FFmpeg 损坏的连接输出

问题描述

编辑/更新:当前的解决方案是在所有文件上运行此代码 ffmpeg -i up.mp4 -vf scale=1920:1080 -crf 22 reUP.mp4 分辨率,但每秒匹配帧数。

enter image description here

我以前可以打开CMD,输入CD C:\Users\...,然后输入ffmpeg -f concat -safe 0 -i xmylist.txt -crf 22 -c copy x1.mp4

xmylist

录音来自同一部手机,一些来自前置摄像头,一些来自后置摄像头。我了解这可能会导致不同的问题?但直到最近它都运行良好。

现在输出被这个日志损坏了:

enter image description here

单个视频文件播放得很好,大多数连接输出也是如此,但有些部分变成这样并冻结:

enter image description here

解决方法

您正在连接两个分辨率不同的视频文件。

  • front.mp4 为 1920x1080
  • rear.mp4 为 1280x720

重现问题并不难(您可以将代码放在 .bat 文件中):

rem Create tmplist.txt
echo file 'front.mp4' > tmplist.txt
echo file 'rear.mp4' >> tmplist.txt

rem Create video with resolution 192x108 for example (instead of 1920x1080)
ffmpeg -y -f lavfi -i testsrc=size=192x108:rate=25 -f lavfi -i sine=frequency=300 -acodec aac -ar 22050 -vcodec libx265 -crf 17 -pix_fmt yuv420p -t 3 front.mp4

rem Create video with resolution 128x72 for example (instead of 1280x720)
ffmpeg -y -f lavfi -i testsrc=size=128x72:rate=25 -f lavfi -i sine=frequency=400 -acodec aac -ar 22050 -vcodec libx265 -crf 17 -pix_fmt yuv420p -t 3 rear.mp4

rem Concatenate:
ffmpeg -y -f concat -safe 0 -i tmplist.txt -c copy tmp.mp4

结果(3 秒后):
enter image description here


解决方案:将所有连接的输入视频转换为相同的分辨率。

注意:

  • 至少有些视频必须重新编码。

我认为最好的解决方案是将较低的分辨率转换为较高的分辨率,然后应用concat

ffmpeg -y -i rear.mp4 -vf scale=192:108,setsar=1 -vcodec libx265 -crf 22 -pix_fmt yuv420p resized_rear.mp4

ffmpeg -y -f concat -safe 0 -i tmplist.txt -c copy tmp2.mp4

不太推荐的解决方案:

有一个解决方案,但它重新编码所有视频(降低质量)。
不知道有没有使用文本文件的解决方案。

连接两个文件的示例 - 第二个视频已调整大小:

ffmpeg -y -i front.mp4 -i rear.mp4 -filter_complex "[1:v]scale=192:108,setsar=1[v1];[0:v][0:a][v1][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" -vcodec libx265 -crf 22 -pix_fmt yuv420p tmp_resized.mp4