I did a re-encode just lately utilizing ffmpeg and encountered an inaudible however waveform seen audio desynchronization within the course of.
Supply info of MKV file:
Mediainfo reveals a 6ms audio delay relative to the video:
Audio ID : 2 Format : E-AC-3 Format/Data : Enhanced Audio Coding 3 Format settings, Endianness : Massive Codec ID : A_EAC3 Period : 1 h Zero min Bit price mode : Fixed Bit price : 640 kb/s Channel(s) : 6 channels Channel positions : Entrance: L C R, Aspect: L R, LFE Sampling price : 48.Zero kHz Body price : 187.500 FPS (256 SPF) Compression mode : Lossy Delay relative to video : 6 ms Stream measurement : 276 MiB (7%) Language : English Service type : Full Primary Default : Sure Compelled : No
This can be seen by wanting on the pts and on the stream begin time:
ffprobe -of compact -select_streams a:0 -show_frames -show_entries body=pkt_pts,pkt_pts_time,pkt_dts,pkt_dts_time,best_effort_timestamp_time,pkt_duration,nb_samples %sourcemkv% body|pkt_pts=6|pkt_pts_time=0.006000|pkt_dts=6|pkt_dts_time=0.006000|best_effort_timestamp_time=0.006000|pkt_duration=32|nb_samples=1536 body|pkt_pts=38|pkt_pts_time=0.038000|pkt_dts=38|pkt_dts_time=0.038000|best_effort_timestamp_time=0.038000|pkt_duration=32|nb_samples=1536 body|pkt_pts=70|pkt_pts_time=0.070000|pkt_dts=70|pkt_dts_time=0.070000|best_effort_timestamp_time=0.070000|pkt_duration=32|nb_samples=1536
Additionally, the delay is detected by way of following:
ffprobe -show_entries stream=codec_type,period,start_time -of compact %sourcemkv% stream|codec_type=video|start_time=0.000000|period=N/A stream|codec_type=audio|start_time=0.006000|period=N/A stream|codec_type=subtitle|start_time=0.000000|period=3617.638000
Re-encoding course of
For transcoding EAC3 to AAC I used solely these audio parameters – no time stamp manipulation:
-acodec aac -b:a 160ok -ac 2
A technique I obtained the delayed result’s this command to re-encode:
ffmpeg -i %sourcemkv% -vcodec libx264 -profile:v excessive -crf 23 -tune movie -level 4.1 -acodec aac -b:a 160ok -ac 2 re-encoded-with-aac.mkv
Detecting the delay
I detected a delay by inspecting the waveform similar to a video body.
The delay itself just isn’t fairly audible – as I discovered to be of 15.333 ms in period, nevertheless it appears to be there, in response to inspection by way of the next AviSynth+ script in AvsPmod::
FFmpegSource2("re-encoded-with-aac.mkv", vtrack=-1, atrack=-1, cache=True, cachefile="", fpsnum=-1, fpsden=1, threads=-1, timecodes="", seekmode=1, overwrite=False, width=-1, top=-1, resizer="BICUBIC", colorspace="", rffmode=0, adjustdelay=-1, utf8=False, varprefix="") ConvertToMono() # Check if DelayAudio will sync it! #AmplifydB(50.0) #DelayAudio(-0.015333) waveform( window=1, top=0.6)
I utilized the identical script to the unique and in contrast the ensuing waveform graphs for a sure video body: supply mkv graph for body 139 vs AAC re-encoded video’s waveform view of body 139
As will be seen, except a
DelayAudio(-0.015333) is utilized to the re-encoded AAC audio stream – they don’t seem to be in sync.
Fortunately, this delay is fixed all through the video!
Different info of re-encode
Remuxed audio stream has
start_time=0.000000 and first audio body’s pts is
0.000000. It’s a bit unusual that though the reported identified delay of the unique audio relative to the video is of 6ms, the ensuing delay between unique and re-encoded video with aac stream is of
15.333ms. I do not know from the place this will come; possibly it has to do with the size of the output’s audio frames, every having a period of
- Is that this a bug with ffmpeg when transcoding from EAC3 to AAC?
- Did I misuse ffmpeg or anticipate an excessive amount of from it to accurately re-encode this?
- Is there a have to specify some additional ffmpeg parameters with the intention to have issues in
- What could be the perfect resolution to deal with this apart from visible inspection of body’s waveform for figuring out the somewhat arbitrary delays which can happen?
- Does the 6ms delay of the audio stream trigger all these points with the re-encode?
I additionally tried the next:
%sourcemkv%in gMKVExtractGUI – 6ms of EAC3 audio is detected – extract audio stream
- Remux the re-encoded video stream in mkvtoolnix-gui with unique EAC3 audio – specify 6ms delay
End result: ALL IN SYNC with inspection technique described above.
- convert unique audio to 2 channel AAC
- mkvtoolnix-gui: remux re-encoded video stream with 2 channel AAC audio
End result: Delay is current