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

标签 ffmpeg

我有一个工作流程,它基本上采用原始视频文件,裁剪掉不相关的帧部分,然后使用 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

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

最佳答案

因此,尽管我不得不承认我不能 100% 确定哪个更改解决了它,但我设法让这个工作正常进行。下面的代码 pastelet 包含原始的“三遍”方法以及较新的“两遍”方法。

# 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检测 channel 的临时文件在这两种情况下并不相同——理论上,通过相同两个过滤器的相同输入文件应该是相同的- 但 vidstabdetect 过滤器输出不同的像素格式:

从三遍(crop 和 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”和“yuv420p”之间的详细区别——但这就是输出文件不同的原因......

关于ffmpeg:组合/排序 vidstab 和裁剪过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38598047/

相关文章:

ffmpeg - 使用 FFmpeg 从大电影创建缩略图需要太长时间

bash - 使用 FFMPEG 递归扫描和识别视频文件

ffmpeg - 使用 ffmpeg 将 webm 转换为 mp4

html - 将视频从 flv 转换为 mp4 音频不播放

python - 将视频帧传送到 OpenCV 图像,然后传送到 FFmpeg

python - 不和谐机器人在哪里可以找到 ffmpeg buildpack heroku

启动 FFmpegFrameGrabber 中的 java.lang.UnsatisfiedLinkError : org. bytedeco.javacpp.avutil

ffmpeg - 使用ffmpeg垂直或水平堆叠(马赛克)几个视频?

python - 可以用 python 捕获 ffmpeg 错误吗?

ffmpeg:是否可以替换可变帧率视频中的帧?