2

I was using ffmpeg to transfer the format of audio files, like from .wav to mp3. The transfer seemed fine and the audio sounds as expected. However when I check its waveform, I found that after the transfer,

  1. A small portion of silent (and with some very tiny noise) is at the beginning of the output audio. The length is about 1 ms ~ 0.001 sec.

  2. As the silent part is appended, the end of the audio is altered - the length of the output audio is longer than the input file. (my input is exactly 10 sec, now the output is around 10.1 sec.

Need the transfer precise because need to do further analysis frame by frame, and this situation could not go well. I used the following command to transfer a file.

ffmpeg -I ..\wav_1K_32bit_24576kbps_384000Hz_stereo.wav -vn -ar 12000 -ac 2 -ab 320000 -f MP3 MP3_12000Hz_32kbps_stereo_VBROff.MP3

Please refer to the screen crop of waveform view.

Beginning of audio, input (U) & output (L)

End of audio, input (U) & output (L)

Thank you!

LouisCJT
  • 41
  • 3
  • See https://stackoverflow.com/questions/42410479/ffmpeg-wrong-audio-file-after-conversion-in-aac/42415886#42415886 – Gyan May 04 '18 at 09:55

1 Answers1

0

This is one approach ... issue this to pre-process your input file prior to your ffmpeg call

sox $input_audio $output_audio  trim 0.001  00:00:09.999

to snip off the leading 0.001 second from your input file so its length becomes 9.999 seconds

Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
  • This will get rid of the actual beginning 0.1s of the audio data. The extra time is decoder delay, not an audio artifact. – Gyan May 04 '18 at 12:31
  • yes however if original ffmpeg adds time this should result in the needed 10 seconds - no ? – Scott Stensland May 04 '18 at 12:35
  • Please read my answer in my comment link. Your solution is lossy and creates a new problem while making the durations match. – Gyan May 04 '18 at 12:47
  • Yes, as described by Gyan, this actually skips the first frames of input. This might make more problems because we need to shift the output instead of cutting off the input. If this is used there still will be several frames silent in output because the decoder delay is still there, although this might make output as nearer 10 secs. Anyway I also thank comments from Scott. – LouisCJT May 21 '18 at 09:12