简体   繁体   English

如何同步网格中的 4 个视频以同时播放同一帧?

[英]How do I sync 4 videos in a grid to play the same frame at the same time?

  • 4 of us have recorded ourselves playing a game and want to create a 4 x 4 video grid我们中的 4 个人录制了自己玩游戏的视频,并希望创建一个 4 x 4 视频网格
  • The game has cutscenes at the beginning followed by each person having their unique part for the rest of the video游戏一开始有过场动画,然后每个人都有自己独特的部分,用于视频的 rest
  • I am looking to synchronize the grid such that it starts at the same place in the cutscene for everyone我希望同步网格,使其在每个人的过场动画中都从同一位置开始
  • Kindly take a look at what is happening currently.请看看目前发生的事情。 The cutscene is off by a few seconds for everyone每个人的过场动画都关闭了几秒钟
  • Imagine a time offset a,b,c,d such that when I add this offet to each video, the entire video grid will be in sync想象一个时间偏移量 a,b,c,d 这样当我将这个偏移量添加到每个视频时,整个视频网格将同步
  • How to find this a,b,c,d and more importantly how to add it in filter_complex如何找到这个 a,b,c,d 更重要的是如何将它添加到 filter_complex

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而不是startstart_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.

相关问题 ffmpeg-如何同时捕获和旋转视频? - ffmpeg - How do I capture AND rotate a video at the same time? 如何从电影中提取第一帧并同时在其上叠加水印? - How can I extract the first frame from a movie AND overlay a watermark on it at the same time? 如何使用 RTSP Url 同时使用 FFPLAY 播放多个流 - How to Play Multiple Streams with FFPLAY at the Same Time using RTSP Url 如何尝试查找播放相同歌曲但压缩格式不同的音频文件? - How do I proceed in an attempt to find audio files which play the same song but are in different compressed formats? 如何从 UIImagePickerController 将 iOS 视频编码为 .mp4 以便 Android 设备可以播放它们? - How do I encode iOS videos as .mp4 from UIImagePickerController so that Android devices can play them? 剪切视频并将它们与hstack同时堆叠在ffmpeg中 - Cut videos and stack them with hstack in ffmpeg at the same time FFMPEG同时开始播放2个视频,但隐藏一个视频直到另一个视频结束 - FFMPEG Start 2 videos at the same time but hide one until the other is finished 如何逐帧复制文件以获得完全相同的文件? (FFmpeg) - how can I copy file frame by frame to get exactly the same file? (FFmpeg) 如何在多个视频的开头批量插入相同的剪辑场景? - How to batch insert same clip scene at the beginning of multiple videos? FFmpeg如何拼接视频和output相同的文件前缀 - How does FFmpeg concat videos and output same file prefix
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM