我正在浏览 ffmpeg 的文档,但很难找到解决方法。
有没有办法为视频中的特定范围添加模糊效果。
示例:1 分钟的视频。我想模糊 30-35 秒。
这可能吗?如果可以的话,命令是什么样的?
我不知道是否可以仅使用单个
ffmpeg
命令来完成此操作,但是使用 bash 函数您可以使用 function 来完成此操作:
function blurPartOfVideo {
if [ $# -ne 3 ]; then
echo "Usage: blurPartOfVideo <videoName> <blurStartSeconds> <blurEndSeconds>"
return 1
fi
videoName=$1
blurStartSeconds=$2
blurEndSeconds=$3
blurValue=5 # the greater value the stronger blur is
videoExtension="${videoName##*.}" # Get video extension from the filename
videoNamePartBeforeBlur="$(basename "$videoName" ."$videoExtension")_until$blurStartSeconds.$videoExtension"
videoNamePartToBlur="$(basename "$videoName" ."$videoExtension")_$blurStartSeconds-$blurEndSeconds.$videoExtension"
videoNamePartAfterBlur="$(basename "$videoName" ."$videoExtension")_from$blurEndSeconds.$videoExtension"
videoNamePartiallyBlurred="$(basename "$videoName" ."$videoExtension")_blurred.$videoExtension"
echo "Trying to add blurring=$blurValue to video $videoName in time range: $blurStartSeconds - $blurEndSeconds, result video: $videoNamePartiallyBlurred"
echo "Splitting video: $videoName -> $videoNamePartBeforeBlur, $videoNamePartToBlur, $videoNamePartAfterBlur"
ffmpeg -loglevel error -i "$videoName" -t "$blurStartSeconds" "$videoNamePartBeforeBlur"
ffmpeg -loglevel error -i "$videoName" -ss "$blurStartSeconds" -t "$(($blurEndSeconds - $blurStartSeconds))" "$videoNamePartToBlur"
ffmpeg -loglevel error -i "$videoName" -ss "$blurEndSeconds" "$videoNamePartAfterBlur"
videoNamePartToBlur_blurred="$(basename $videoNamePartToBlur)_blurred.$videoExtension"
echo "Adding blur to video: $videoNamePartToBlur, blurValue=$blurValue, creating file: $videoNamePartToBlur_blurred"
ffmpeg -loglevel error -i "$videoNamePartToBlur" -vf "boxblur=$blurValue" "$videoNamePartToBlur_blurred"
echo "Merging files: $videoNamePartBeforeBlur + $videoNamePartToBlur_blurred + $videoNamePartAfterBlur = $videoNamePartiallyBlurred"
ffmpeg -loglevel error -i $videoNamePartBeforeBlur -i $videoNamePartToBlur_blurred -i $videoNamePartAfterBlur \
-filter_complex "[0:v] [0:a] [1:v] [1:a] [2:v] [2:a] concat=n=3:v=1:a=1 [v] [a]" \
-map "[v]" -map "[a]" $videoNamePartiallyBlurred
echo "Video partially blurred: $videoNamePartiallyBlurred in time range: $blurStartSeconds - $blurEndSeconds [seconds]"
# removing remporaly files:
# rm $videoNamePartBeforeBlur $videoNamePartToBlur_blurred $videoNamePartAfterBlur $videoNamePartToBlur_blurred
}
用途:
blurPartOfVideo fileToBlur.MOV 10 15
注意:有更多合并文件的方法,其中一些对于特定文件扩展名更有效。