如何在 FFMpeg 中连接两个或多个具有不同帧速率的视频?

Tik*_*ik0 7 video ffmpeg concatenation raspberry-pi3

我有多个(> 100)视频,具有各种恒定帧速率(例如 7 FPS、8 FPS、16 FPS、25 FPS),但编解码器和分辨率相同。我想将它们连接(使用ffmpeg concat)成一个具有可变帧速率(VFR)的视频,以便连接的视频以相应的帧速率播放每个部分。到目前为止,我只能将所有文件连接到一个视频,其常量(CFR)为例如。25 帧/秒。这是一个缺点,即所有 FPS <25 FPS 的部分播放速度都更快。我曾经-vsync 2 -r 25尝试告诉 ffmpeg 使用 VFR,最大 FPS 为 25,但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
Run Code Online (Sandbox Code Playgroud)

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

Tik*_*ik0 0

由于我的问题主要在评论中得到回答,因此我想发布另一个不带中间文件的解决方案。我使用命名管道并将每个片段作为原始视频发送到该管道,并将其转换为帧速率(例如 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
Run Code Online (Sandbox Code Playgroud)