[英]How do I sync 4 videos in a grid to play the same frame at the same time?
I used the ffmpeg command below to generate a 4 x 4 video grid and it seems to work我使用下面的 ffmpeg 命令生成了一个 4 x 4 的视频网格,它似乎可以工作
ffmpeg
-i nano_prologue.mkv -i macko_nimble_guardian.mkv -i nano_nimble_guardian.mkv -i ghost_nimble_guardian_subtle_arrow_1.mp4
-filter_complex "
nullsrc=size=1920x1080 [base];
[0:v] setpts=PTS-STARTPTS, scale=960x540 [upperleft];
[1:v] setpts=PTS-STARTPTS, scale=960x540 [upperright];
[2:v] setpts=PTS-STARTPTS, scale=960x540 [lowerleft];
[3:v] setpts=PTS-STARTPTS, scale=960x540 [lowerright];
[base][upperleft] overlay=shortest=1 [tmp1];
[tmp1][upperright] overlay=shortest=1:x=960 [tmp2];
[tmp2][lowerleft] overlay=shortest=1:y=540 [tmp3];
[tmp3][lowerright] overlay=shortest=1:x=960:y=540
"
-c:v libx264 output.mkv
My problem though is that since each of us starts recording at slightly different times, the cutscenes are out of sync但我的问题是,由于我们每个人开始录制的时间略有不同,因此过场动画不同步
As per the screenshot below, you can see that each video has the same scene starting at a slightly different time.根据下面的屏幕截图,您可以看到每个视频都有相同的场景,开始时间略有不同。
Is there a way to find where the same frame will start on all videos and then sync each video to start from that frame or 20 seconds before that frame?有没有办法找到同一帧在所有视频上的开始位置,然后同步每个视频从该帧开始或该帧前 20 秒开始?
UPDATE 1更新 1
i have figured out the offset for each video in millisecond precision using the following technique我已经使用以下技术计算出每个视频的毫秒精度偏移量
take a screenshot of the first video at a particular point in the cutscene and save image as png and run the script below for the remaining 3 videos to find out where this screenshot appears in each video
ffmpeg -i "video2.mp4" -r 1 -loop 1 -i screenshot.png -an -filter_complex "blend=difference:shortest=1,blackframe=90:32" -f null -
Use the command above to search for the offset in every video for that cutscene使用上面的命令在每个视频中搜索该过场动画的偏移量
It gave me this它给了我这个
VIDEO 3 OFFSET视频 3 偏移量
[Parsed_blackframe_1 @ 0x600003af00b0] frame:3144 pblack:92 pts:804861 t:52.399805 type:P last_keyframe:3120
[Parsed_blackframe_1 @ 0x600003af00b0] frame:3145 pblack:96 pts:805117 t:52.416471 type:P last_keyframe:3120
VIDEO 2 OFFSET视频 2 偏移量
[Parsed_blackframe_1 @ 0x6000014dc0b0] frame:3629 pblack:91 pts:60483 t:60.483000 type:P last_keyframe:3500
VIDEO 4 OFFSET视频 4 偏移量
[Parsed_blackframe_1 @ 0x600002f84160] frame:2885 pblack:93 pts:48083 t:48.083000 type:P last_keyframe:2880
[Parsed_blackframe_1 @ 0x600002f84160] frame:2886 pblack:96 pts:48100 t:48.100000 type:P last_keyframe:2880
Now how do I use filter_complex to say start each video at either the frame above or the timestamp above?.现在我如何使用 filter_complex 来表示在上面的帧或上面的时间戳开始每个视频? I would like to include say 10 seconds before the above frame in each video so that it starts from the beginning
我想在每个视频的上述帧之前加入 10 秒,以便它从头开始
UPDATE 2更新 2
This command currently gives me a 100% synced video, how do I make it start 15 seconds before the specified frame numbers and how to make it use the audio track from video 2 instead?这个命令目前给我一个 100% 同步的视频,我如何让它在指定的帧数之前 15 秒开始,以及如何让它使用视频 2 的音轨?
ffmpeg
-i v_nimble_guardian.mkv -i macko_nimble_guardian.mkv -i ghost_nimble_guardian_subtle_arrow_1.mp4 -i nano_nimble_guardian.mkv
-filter_complex "
nullsrc=size=1920x1080 [base];
[0:v] trim=start_pts=49117,setpts=PTS-STARTPTS, scale=960x540 [upperleft];
[1:v] trim=start_pts=50483,setpts=PTS-STARTPTS, scale=960x540 [upperright];
[2:v] trim=start_pts=795117,setpts=PTS-STARTPTS, scale=960x540 [lowerleft];
[3:v] trim=start_pts=38100,setpts=PTS-STARTPTS, scale=960x540 [lowerright];
[base][upperleft] overlay=shortest=1 [tmp1];
[tmp1][upperright] overlay=shortest=1:x=960 [tmp2];
[tmp2][lowerleft] overlay=shortest=1:y=540 [tmp3];
[tmp3][lowerright] overlay=shortest=1:x=960:y=540
"
-c:v libx264 output.mkv
By "how do I make it start 15 seconds before the specified frame numbers" you simply want all those four videos to start 15 seconds back, compared to your current timings?通过“我如何让它在指定的帧数之前 15 秒开始”,您只是希望所有这四个视频都比您当前的时间提前 15 秒开始? Any reason why you would use
start_pts
instead of start
or start_frame
?您为什么要使用
start_pts
而不是start
或start_frame
的任何原因? Those two seem more convenient.这两个看起来更方便。 If i got it right, if the offset for cutscene image in the third video starts at
t:52.416471
, and you want this video track start ten seconds before, just use trim=start=42.416471
in your filters.如果我做对了,如果第三个视频中过场动画图像的偏移量从
t:52.416471
开始,并且您希望该视频轨道在十秒前开始,只需在过滤器中使用trim=start=42.416471
。 If all steams have the same pixel format, you can remove nullsrc, and replace the overlay parts with [upperleft][upperright][lowerleft][lowerright]xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0[out_v]
.如果所有流的像素格式都一样,可以去掉nullsrc,将覆盖部分替换为
[upperleft][upperright][lowerleft][lowerright]xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0[out_v]
. End your filter chain with named output (out_v in example above), then map it like -map '[out_v]'
.以名为 output(上面示例中的 out_v)结束您的过滤器链,然后 map 就像
-map '[out_v]'
一样。 If you want to use second audio stream, you can map it with -map 1:a, but something tells me you would want to manipulate its timing, too, and add another line to your filtering: [1:a]atrim=<your options to match the video>[out_a]
, then -map '[out_a]'
.如果你想使用第二个音频 stream,你可以用 -map 1:a map 它,但有些东西告诉我你也想操纵它的时间,并在你的过滤中添加另一行:
[1:a]atrim=<your options to match the video>[out_a]
,然后-map '[out_a]'
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.