【问题标题】:How to concatenate two or more videos with different framerates in FFMpeg?如何在 FFMpeg 中连接两个或多个具有不同帧速率的视频?
【发布时间】:2019-09-11 15:17:12
【问题描述】:

我有多个 (> 100) 个视频,这些视频具有各种恒定帧速率(例如 7 FPS、8 FPS、16 FPS、25 FPS)但编解码器和分辨率相同。 我想将它们连接(使用ffmpeg concat)成一个具有可变帧速率(VFR)的视频,以便连接的视频以各自的帧速率播放每个部分。 到目前为止,我只设法将所有文件连接到一个具有常量(CFR)例如的单个视频。 25 帧/秒。 这是缺点,所有 -vsync 2 -r 25 试图告诉 ffmpeg 使用最大 FPS 为 25 的 VFR,但mediainfo 报告了一个 CFR 为 25 FPS 的视频。 如果我只使用-vsync 2(没有-r),我会得到一个VFR 视频输出,但是mediainfo 报告说这是一个最低11.9 FPS 最高12 FPS 的视频(所有视频的平均FPS) . 如何将各种视频连接到单个 VFR 视频?

这是我使用的命令:

ffmpeg -y -vsync 2 -r 25 -f concat -safe 0 -i /tmp/filelist.txt -c:v h264_omx -pix_fmt yuv420p -b:v 524231 -maxrate 524231 -bufsize 1048462 -an /tmp/${DATE}.mp4

我在(Raspbian 6.3.0-18+rpi1+deb9u1上使用ffmpeg version 3.2.12-1~deb9u1+rpt

【问题讨论】:

  • 目前不可能。在我的待办事项中。
  • @Gyan 不好。但是什么是有效的解决方法?将所有视频转换为相同的帧率然后 cancat 吗?
  • 如果您可以将它们重新混合到 MPEG-TS,然后将它们连接起来,那可能会起作用。 ffmpeg -i file.mp4 -c copy file.ts
  • 在我的情况下,我根据所有视频的最小 fps 将所有视频转换为相同的帧速率,这优于最大 fps。并且有些视频不能使用-c copy来避免Non-monotonous DTS in output stream警告导致部分视频卡顿。

标签: video ffmpeg concatenation raspberry-pi3


【解决方案1】:

由于我的问题主要在 cmets 中得到解答,我想发布另一个没有中间文件的解决方案。 我使用命名管道并发送每个 sn-p,它被转换为例如帧速率。 5 FPS,作为该管道的原始视频。 使用exec 保持管道畅通至关重要。 将多个 720p AVI 视频连接到单个 MKV 视频的简单 bash 脚本如下:

#!/bin/bash
send2pipe() {
    # Open the pipe permanently
    exec 7<>outpipe
    # Decode and send every raw frame to the pipe 
    for l in $(ls *avi); do ffmpeg -nostdin -i $l -an -filter:v fps=fps=5 -f rawvideo pipe:1 > outpipe 2> /dev/null ; done &
    # Close the pipe (aka send EOF), which causes the encoding app to terminate
    exec 7>&-
}

# Create the pipe
mkfifo outpipe
# Start sending videos to the pipe in the background
send2pipe &
# Encode the frames in the pipe to a single video
ffmpeg -fflags +genpts -f rawvideo -s:v 1280x720 -r 5 -i outpipe -an -c:v libx264 -preset ultrafast -crf 35 -y output.mkv
# Remove the pipe
rm outpipe

【讨论】:

    【解决方案2】:

    我能够使用“filter_complex”模式做到这一点。简单的 concat 选项提供了输出,但我认为它插入重复帧以弥补以 30fps 运行 12fps 源的延迟。

    .\ffmpeg.exe -i .\12fps_start.mp4 -i .\30fps_end.mp4 -filter_complex "[0:v] [1:v] concat=n=2:v=1 [v]" -map "[v]" -c:v libx264 -r 30 final.mp4
    

    注意:源文件中没有音频流。我正在拼接游戏中时光倒流。

    【讨论】:

    • 你的工作但会重新编码。我认为 OP 试图避免这种情况。
    猜你喜欢
    • 2012-07-16
    • 1970-01-01
    • 2018-03-25
    • 2020-02-19
    • 2019-06-26
    • 1970-01-01
    • 2022-01-08
    • 2019-12-13
    相关资源
    最近更新 更多