Error when reading sound in avi files

4 views (last 30 days)
Hello, i whould like to make an aplication that add volume to a film.
In my code i have used a bucle in order to match the audio with the frames. But i found a problem that when reading audio from a film it has a lot of samples that are at 0 value, thoose samples introduce me a lot of distorsion in the audio. When i read a video in mp4 it doesent give me that distorsion because the sound doesen`t have void samples. I whould appreciate if you could healp me. I attach my code in order to explain better
In that picture i have read a mp4 video file that doesen't introduce distorsion.
Same experiment but reading a film.
Same experiment but with other film.
I suppose that this distorison is due the compression of the audiofile but i thought that the dsp.AudioReaderFile function could uncompress that sound.
Those films with distorison are correctly heared in a videoplayer like VLC.

Answers (1)

Walter Roberson
Walter Roberson on 14 Feb 2021
MATLAB use the model that audio is attached to the frame, and that each frame has the same amount of audio. If the source does not have the same amount of audio as the first frame, then MATLAB zero fills.
For fixed-framerate video this is an more acceptable model, as lack of audio in such a case can be tied directly to silence for a fixed period.
But for variable-framerate video, the assumption of the same amount of audio for each frame when the frames are not spaced equally presents obvious problems.
I do not know how one might get around this problem.
I wonder, though... perhaps if you fetched the timestamp for each frame as you read it, then the difference in timestamps would give you information on how much audio should have been expected, and then maybe you can chop the buffer if it should have been short?
  5 Comments
Hermenegildo Bello García
The idea that was interlaced was not correct.
i am investigating that effect, in that audio its like the sound is oversampled, but with no lowpass filter done.
When you oversample you have to increase the vector of the signal adding 0 and then use a lowpass in order to rise thoose 0 to its place, doing that you dont modify the spectrum.
In my case i found that when you reproduce the sound with a sampling frequency equal 3*fs you obtain the same sound as in the film but 3 times shorter, we dont hear that sifhting(produced due the reason that the sound doesnt have the low pass ) becaouse its outside of the hearing range.
Spectrum of the sound:
The next thing to discover is the way to increase the legnth of a sound with the same message, without adding noise, this might be possible becouse VLC does.
Hermenegildo Bello García
Finally i got the sollution of the problem
We have the origial signal x with length N. This signal is oversampled and has 2 0 between useful values.
If we take only the useful values we obtain y with length N/3. I have done this with the function in picture(1)
Now we have the origian sound, as the film needs N samples to be weel reproduced we have to increase the length of y.
The way to increase that length is doing ifft(fft(y,N)) doing that we obtain N samples of the signal y and the same espectral distribution.
Now we can match the samples again with the frames.
picture 1:

Sign in to comment.

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!