Conversion from MP4 to WAV results in desync with FFmpeg, but not when using VLC

1

Converstion to .wav from .mp4 video causes a desynchronization when the conversion is done with FFmpeg, but not when with VLC. I've been trying to figure this out for days now and any help is greatly appreaciated :)

I start with a video recorded with OBS in .flv. I then use a batch file with FFmpeg:

"for %%a in ("*.flv") do ffmpeg -i %%a -vcodec copy -acodec copy %%~na.mp4
pause"

which gives me the .mp4 file.

I then use VLC GUI method to convert the audio in the .mp4 into .wav so I can better edit it in Audacity. I tried using a batch file with FFmpeg instead of VLC's GUI to make it more streamlined. However, whenever I do the conversion using a batch file and FFmpeg and then put the FFmpeg converted .wav file on the timeline in Adobe Premiere along with the .mp4 video, the audio of the .wav, that is converted with FFmpeg is offset with the .mp4 video's audio track, but when the same to .wav conversion is done with VLC's GUI the resulting .wav and the original .mp4 audio tracks are in sync.

The batch files I have tried with different options, but still resulting in the .mp4 and .wav file audio tracks not matching are as follows:

"for %%a in ("*.mp4") do ffmpeg -i %%a -vn %%~na.wav pause"    


"for %%a in ("*.flv") do ffmpeg -i %%a -acodec pcm_s16le %%~na.wav pause"    


"for %%a in ("*.mp4") do ffmpeg -i %%a -ab 1536k -ac 2 -ar 48000 -acodec pcm_s16le %%~na.wav -loglevel verbose -report -stats  pause"  


"for %%a in ("*.flv") do ffmpeg -i %%a -vcodec copy -acodec copy %%~na.mp4 %%~na.aac -loglevel verbose -report pause"

I've also tried to use the options:

-vn -copyts -ss 0 -y -avoid_negative_ts 1 -async 1 ...etc.

all to no avail.

Since VLC can handle the same conversion then it must mean that I am not just using the correct syntax : /

EDIT: The console output for

"for %%a in ("*.mp4") do ffmpeg -i %%a -vn %%~na.wav -loglevel verbose -report pause":

Y:\Dxtory\Cataclysm Dark Days Ahead\Test Batch File>for %a in ("*.mp4") do ffmpe
g -i %a -vn %~na.wav

Y:\Dxtory\Cataclysm Dark Days Ahead\Test Batch File>ffmpeg -i CataclysmDDAWCam0M
icOff2nd.mp4 -vn CataclysmDDAWCam0MicOff2nd.wav
ffmpeg version N-62162-gec8789a Copyright (c) 2000-2014 the FFmpeg developers
  built on Apr  4 2014 22:08:30 with gcc 4.8.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
ack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable
-zlib
  libavutil      52. 74.100 / 52. 74.100
  libavcodec     55. 57.100 / 55. 57.100
  libavformat    55. 36.101 / 55. 36.101
  libavdevice    55. 11.100 / 55. 11.100
  libavfilter     4.  3.100 /  4.  3.100
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 18.100 /  0. 18.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'CataclysmDDAWCam0MicOff2nd.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.36.101
  Duration: 00:00:17.67, start: 0.000000, bitrate: 99559 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709)
, 1920x1080, 99437 kb/s, 30 fps, 30 tbr, 16k tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 10
9 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Output #0, wav, to 'CataclysmDDAWCam0MicOff2nd.wav':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    ISFT            : Lavf55.36.101
    Stream #0:0(und): Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo
, s16, 1536 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:1 -> #0:0 (aac -> pcm_s16le)
Press [q] to stop, [?] for help
size=    3304kB time=00:00:17.62 bitrate=1536.0kbits/s
video:0kB audio:3304kB subtitle:0kB other streams:0kB global headers:0kB muxing
overhead: 0.002365%

Y:\Dxtory\Cataclysm Dark Days Ahead\Test Batch File>pause
Press any key to continue . . .

EDIT: Added a new shorter test .flv, .mp4 and two .wav files converted with FFmpeg and VLC, console output and log file to Google Drive https://drive.google.com/folderview?id=0B1bpDgYQQ_bMMmhmcDEtcldhSUE&usp=sharing

Ferco

Posted 2014-04-06T11:36:18.220

Reputation: 11

Please provide the console outputs of the commands. It is best to use the command on a single file for illustration, rather than as a batch against multiple inputs. You have to solve it on one file before attempting to run the conversion on several inputs. – Rajib – 2014-04-06T13:28:30.607

I edited the original question to add the console output for one of the above commands and I did run these test batch files on single input files; both the .flv and .mp4 separately. – Ferco – 2014-04-06T15:41:02.427

How is it "offset"? Ahead/behind by what duration? Can you do ffmpeg -i CataclysmDDAWCam0MicOff2nd.wav and provide the console output of that? – Rajib – 2014-04-07T02:28:14.863

The .wav file converted from .mp4 with FFmpeg is behind on the timeline compared to the audio track of that same .mp4 file on the timeline. The outout you requested: Guessed Channel Layout for Input Stream #0.0 : stereo Input #0, wav, from 'CataclysmDDAWCam0MicOff2nd.wav': Metadata: encoder : Lavf55.36.101 Duration: 00:00:17.62, bitrate: 1536 kb/s Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16 , 1536 kb/s At least one output file must be specified – Ferco – 2014-04-07T03:03:47.237

The duration reported is 17.62 seconds. The mp4 was 17.67. The difference is small, but if this should cause an offset, the audio ought to arrive earlier. Could you post the mp4 file somewhere (say dropbox) for testing? – Rajib – 2014-04-07T04:16:44.817

I've uploaded a new shorter .mp4 file with the original .flv it was converted to .mp4 from and also the .wav file generated from that .mp4 with FFmpeg and then from VLC for comparison. Again, the .mp4 to .wav conversion with FFmpeg results in the .wav file's waveform being behind on the timeline as comparted to the .wav file converted with VLC and the .mp4 video's audio track.

I've also included the console output for the FFmppeg conversion and a resulting log file on Google Drive:

https://drive.google.com/folderview?id=0B1bpDgYQQ_bMMmhmcDEtcldhSUE&usp=sharing

– Ferco – 2014-04-07T19:16:30.903

Any suggestions on what else I could try, other than wait for newer versions of FFMPEG to come out, and see if the conversion works then? – Ferco – 2014-04-23T20:54:46.757

No answers