Kapalı

FFMPEG: How to avoid audio/video desync in output of crossfaded clips when input is variable frame rate video

Hi! I'm doing screen recordings of gameplay (Dota2) using my NVIDIA graphics card GeForce experience hardware recording (NVEC Encoder). This creates a variable frame rate output video. My NVIDIA settings are 60 fps 15000 kbps. I have paid a guy to make a program that generates scripts that given start/stop timepoints can extract clips from the video and merge them with crossfade. See example code below. The script works for many input recordings but fails often: The audio and video are desynchronized (usually audio delay) in many of the clips, ca 0.5 seconds. I think it fails more when frame rate dropped more during recording. He does not know how to fix the problem, and I wonder if anyone could point out if anything could be fixed in the script (example below)?

Processing speed is quite important (now making a 10 min 'highlight' video takes ca 7-10 min). Solutions increasing that amount very much more is not of too big interest, unfortunately. His approach has been to work separately with audio and video and merge in the end. He already has a program to make ffmpeg code for working with different scenarios (also adding overlays, adding music, intro/outro) so it would be preferable with some easy fixes to his code and not dramatic redesigning of the logic. But if nothing else can fix the problem, a redesign in logic is ok. Using other tools than ffmpeg is also ok, but should be automatable (scripts/cli) and not increase processing times too much.

Running the program "mediainfo" on the input video shows that framerate dropped quite low for this input video:

Frame rate mode: Variable

Frame rate : 60.000 FPS

Minimum frame rate: 3.059 FPS

Maximum frame rate: 63.739 FPS

Full report here: [login to view URL]

The input video can be downloaded from dropbox here (6 GB):

[login to view URL]

Here the example of a script when asked to extract two clips from input video at 9:57 (41 sec length) and 15:45 (28 sec length) and crossfade merge them with a 0.5 crossfade time. There might be some code-remnants from options that are not used in this example (overlays, music, intro/outro). Using the input video above, this creates audio/video desync.

6 commands excecuted in sequence:

[login to view URL] -loglevel warning -ss 00:09:57 -i [login to view URL] -t 00:00:41 -filter_complex "[0:a]afade=t=out:st=40.5:d=0.5[a1]" -map "[a1]" -y [login to view URL]

[login to view URL] -loglevel warning -i [login to view URL] -ss 00:09:57 -t 00:00:41 -an -vcodec copy -f mpegts -avoid_negative_ts make_zero -y [login to view URL]

[login to view URL] -loglevel warning -ss 00:15:45 -i [login to view URL] -t 00:00:28 -filter_complex "[0:a]afade=t=in:st=0:d=0.5[a1]" -map "[a1]" -y [login to view URL]

[login to view URL] -loglevel warning -i [login to view URL] -ss 00:15:45 -t 00:00:28 -an -vcodec copy -f mpegts -avoid_negative_ts make_zero -y [login to view URL]

[login to view URL] -loglevel warning -i [login to view URL] -i [login to view URL] -y -filter_complex "[0:a]adelay=0|0[a0];[1:a]adelay=40500|40500[a1];[a0][a1]amix=inputs=2:dropout_transition=68.5,atrim=duration=68.5[outa0];[outa0]loudnorm[outa]" -map "[outa]" -ar 48000 -acodec aac -strict -2 [login to view URL]

[login to view URL] -loglevel warning -i [login to view URL] -i [login to view URL] -y -i [login to view URL] -filter_complex "[0:v]trim=start=0.5,setpts=PTS-STARTPTS[0c];[1:v]trim=start=0.5,setpts=PTS-STARTPTS[1c];[0:v]trim=40.5:41,setpts=PTS-STARTPTS[fo];[1:v]trim=0:0.5[fi];[fi]format=pix_fmts=yuva420p,fade=t=in:st=0:d=0.5:alpha=1[z];[fo]format=pix_fmts=yuva420p,fade=t=out:st=0:d=0.5:alpha=1[x];[z]fifo[w];[x]fifo[q];[q][w]overlay[r];[0c][r][1c]concat=n=3[outv]" -map "[outv]" -map 2:a -shortest -acodec copy -vcodec libx264 -preset ultrafast -b 15000k -aspect 1920:1080 [login to view URL]

P.S.

I already asked for help at an ffmpeg chat room. One guy said he knew what the problem was, but didnt know how to fix it(?):

[login to view URL]

Beceriler: Kod yazma, Graphics Programming, Programlama, Video Düzenleme

Daha fazlasını gör: access form output based user input, audio translation english spanish clips, ffmpeg convert mp3 audio wav, shotcut audio video sync, how to fix audio video sync, ffmpeg change movie audio mp3, using ffmpeg php convert audio, output query access input text, ffmpeg play stream audio, ffmpeg mms stream audio, multiple audio program output software, usb audio arduino output, ffmpeg play mms audio stream, ffmpeg android ndk audio video sync, vlc audio desync, how much is it to hire someone to edit on 4k video, how much does it cost to hire an editor for a video, how much to hire a pro animation company for a music video, how to audio mastering, balancing audio levels for multiple clips

İşveren Hakkında:
( 1 değerlendirme ) Oslo, Norway

Proje NO: #18397088

Bu iş için 3 freelancer ortalamada $187 teklif veriyor

tamas421

I would not use stream copy neither. And perhaps converting the video to a constant frame rate one (with -crf 0, -r 60) before anything else would be helpful to solve the problem. But it is just after a quick lo Daha Fazla

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(25 Değerlendirme)
4.1
xiqian88

Hello Sir. I am a software architecture and web developer with a Bachelor of Science in Information Technology from Tsinghua University and 7 years of software development experience. I am experienced in web developme Daha Fazla

$155 USD in 3 gün içinde
(2 Değerlendirme)
4.2
TakaAlex

Hello I don't know why you don't use the Video Editor like UleadVideStudio Thanks .......................................................

$377 USD in 3 gün içinde
(0 Değerlendirme)
0.0