[FFmpeg-user] Audio Desynchronization When Utilizing Segmentation

Gabriel Balaich roderrooder at gmail.com
Tue Apr 17 00:18:23 EEST 2018


I was able to mostly solve this issue by utilizing the reset_timestamps
segment option and encoding .ts instead of .mp4. No matter
what I did I could not get this option to work when encoding .mp4 for some
reason:

ffmpeg -y -thread_queue_size 9999 -indexmem 9999 -guess_layout_max 0 -f
dshow -video_size 3440x1440 -rtbufsize 2147.48M ^
-framerate 200 -pixel_format nv12 -i video="Video (00 Pro Capture HDMI
4K+)":audio="SPDIF/ADAT (1+2) (RME Fireface UC)" ^
-map 0:0,0:1 -map 2:1 -c:v h264_nvenc -r 100 -rc-lookahead 200 -forced-idr
1 -strict_gop 1 -sc_threshold 0 -flags +cgop ^
-force_key_frames expr:gte(t,n_forced*2) -preset: llhp -pix_fmt nv12 -b:v
250M -minrate 250M -maxrate 250M -bufsize 250M ^
-c:a aac -ar 44100 -b:a 384k -ac 2 -af "atrim=0.035, asetpts=PTS-STARTPTS,
aresample=async=250" -vsync 1 -ss 00:00:01.096 ^
-max_muxing_queue_size 9999 -f segment -segment_time 600 -segment_wrap 9
-reset_timestamps 1 ^
C:\Users\djcim\Videos\PC\PC\PC%02d.ts

However it isn't perfect, the audio still moves around a tiny bit but it's
anchored to the original position. Basically things can be off
by around 12-16 millisecond after the first segment but not exponentially.
I've also found that after I apply this option when I try to
concat segments back together the audio will drift. Strange behavior and
opposite of what happens when you omit
-reset_timestamps, the audio drifts segment to segment, but lines up
perfectly after concat. I am able to alleviate the drift after
concat by using  aresample=async=xxxx but then I can here the audio
stretching an squeezing at times:

ffmpeg -f concat -safe 0 -i "C:\Users\djcim\Google
Drive\Notepad++\FFMPEG\Concatenate.txt" -c:v copy -c:a aac -ar 44100 ^
-b:a 384k -af "aresample=async=250" C:\Users\djcim\Videos\AllCOutputs.ts

Wish there was a more elegant solution but I haven't found anything else
that works. But at least now my audio doesn't
exponentially drift segment to segment. If anyone has any extra advice
surrounding this issue it would be much appreciated.


More information about the ffmpeg-user mailing list