ffmpeg:组合/排序vidstab和crop过滤器



我有一个工作流程,它基本上是获取一个原始视频文件,裁剪掉帧中不相关的部分,然后使用vidstab过滤器执行两次去握手过滤器。目前,我将这作为三个不同的命令运行:一个命令执行裁剪,第二个命令执行vidstab"检测"过程,第三个命令执行vidstab"转换"过程。

我的工作脚本:

# do the crop first and strip the audio
nice -20 ffmpeg -hide_banner -ss $SEEK -i $INFILE -t $DURATION -preset veryfast -crf 12 -vf crop=0.60*in_w:in_h/9*8:0.22*in_w:0 -an -y $TEMP
# now run the vidstab detection pass
nice -20 ffmpeg -hide_banner -i $TEMP -vf vidstabdetect=stepsize=6:shakiness=10:accuracy=15:result=${INFILE}.trf -f null - 
# now the vidstab transform, with unsharp and writing the overlay text
nice -20 ffmpeg -hide_banner -i $TEMP -preset veryfast -crf 22 -vf 
" 
vidstabtransform=input=${INFILE}.trf:zoom=2:smoothing=60, 
unsharp=5:5:0.8:3:3:0.4, 
drawtext=fontfile=/Windows/Fonts/arialbd.ttf:text=$DIVE:enable='between(t,0,65)':fontcolor=black:fontsize=72:x=w*0.01:y=h*0.01,  
null"
  -y $OUTFILE

我似乎不知道如何将前两次滤波器通过组合成一个单链,这(至少在理论上)将是一个更快的编码时间,而且至少维护起来更简单,可以消除编码器的通过。我尝试做的是第二个代码块,它只是构建了一个过滤器链,将初始裁剪与vidstab检测过滤器相结合。

# this is a combined filter for the crop and the vidstab detect
nice -20 ffmpeg -hide_banner -ss $SEEK -i $INFILE -t $DURATION -preset veryfast -crf 12 -vf 
" 
crop=0.60*in_w:in_h/9*8:0.22*in_w:0,
vidstabdetect=stepsize=6:shakiness=10:accuracy=15:result=${INFILE}.trf,
null " 
-an -r 30 -y $TEMP

# now run the transcoding and the vidstab transform
nice -20 ffmpeg -hide_banner -i $TEMP -preset veryfast -crf 22 -vf 
" 
vidstabtransform=input=${INFILE}.trf:zoom=2:smoothing=60, 
unsharp=5:5:0.8:3:3:0.4, 
drawtext=fontfile=/Windows/Fonts/arialbd.ttf:text=$DIVE:enable='between(t,0,65)':fontcolor=black:fontsize=72:x=w*0.01:y=h*0.01,  
null"
  -y $OUTFILE

然而,当我运行这个(并且它运行)时,最终输出的视频肯定没有得到有效的稳定。日志显示,检测转换过程都已处理,只是输出不正确。

所以,我成功地实现了这一点,尽管我不得不承认,我不能100%确定是哪一个更改解决了它。下面的代码粘贴包含了原始的"三次通过"方法和更新的"两次通过"方法。

# begin the "three pass" method -- crop, then detect, then transform
# do the crop first and strip the audio
nice -20 ffmpeg -hide_banner -ss $SEEK -i $INFILE -t $DURATION -an -y -vf 
crop=0.60*in_w:in_h/9*8:0.22*in_w:0 $TEMP
# now run the vidstab detection pass
nice -20 ffmpeg -hide_banner -i $TEMP -vf 
vidstabdetect=stepsize=6:shakiness=10:accuracy=15:result=${TEMP}.trf -f null - 
# now run the transcoding and the vidstab transform
nice -20 ffmpeg -hide_banner -i $TEMP -y -vf 
" 
vidstabtransform=input=${TEMP}.trf:zoom=2:smoothing=60, 
unsharp=5:5:0.8:3:3:0.4, 
null " 
$OUTFILE

# begin the "two pass" method -- crop and detect together, then transform
# do the crop first and strip the audio
nice -20 ffmpeg -hide_banner -ss $SEEK -i $INFILE -t $DURATION -an -y -vf 
crop=0.60*in_w:in_h/9*8:0.22*in_w:0,vidstabdetect=stepsize=6:shakiness=10:accuracy=15:result=${TEMP2}.trf $TEMP2

# now the vidstab transform
nice -20 ffmpeg -hide_banner -i $TEMP2 -y -vf 
" 
vidstabtransform=input=${TEMP2}.trf:zoom=2:smoothing=60, 
unsharp=5:5:0.8:3:3:0.4, 
null " 
$TWOPASS

顺便说一句,我花了很多时间试图弄清楚为什么在这两种情况下,来自crop和vidstab检测过程的临时文件不相同-理论上,通过相同两个过滤器的相同输入文件应该是相同的-但vidstabdetect过滤器输出不同的像素格式:

从三个通道(作物和视频稳定检测的单独通道)

Output #0, mp4, to 'temp-GOPR3285.MP4':
    Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuvj420p(pc), 1152x960 [SAR 1:1 DAR 6:5], q=-1--1, 47.95 fps, 48k tbn, 47.95 tbc (default)

来自组合作物/检测输出:

Output #0, mp4, to 'temp2-GOPR3285.MP4':
    Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1152x960 [SAR 1:1 DAR 6:5], q=-1--1, 47.95 fps, 48k tbn, 47.95 tbc (default)

我还没有深入了解"yuvj420p"one_answers"yuv420p"之间的详细区别,但这就是输出文件不相同的原因。。。

最新更新