最佳答案
完整的命令可能如下:
ffmpeg -y -i in.jpg -filter_complex "scale=1920:1080,setsar=1:1,crop=1584:896:172:92,split[crp0][crp1];[crp0]scale=1920:1080,setsar=1:1,gblur=sigma=30[blur];[blur][crp1]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" out.jpg
该命令应用您发布的图像(名为 in.jpg
)。样本输出:
过滤器链:
scale=1920:1080,setsar=1:1
- 将输入调整为 1920x1080(setsar
用于固定纵横比)。 crop=1584:896:172:92
- 裁剪黑框内的部分。 split[crp0][crp1]
- 将裁剪后的输出拆分为两个相同的流(两个相同的图像)。 [crp0]scale=1920:1080,setsar=1:1,gblur=sigma=30[blur]
- 将裁剪后的图像调整为 1920x1080 并模糊调整后的图像。将模糊图像存储在临时变量
[blur]
中. [blur][crp1]overlay= ...
- 叠加 [crp1]
在模糊的图像上。 它对视频文件的工作方式相同。
例子:
ffmpeg -y -i in.mp4 -filter_complex "scale=1920:1080,setsar=1:1,crop=1584:896:172:92,split[crp0][crp1];[crp0]scale=1920:1080,setsar=1:1,gblur=sigma=30[blur];[blur][crp1]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -vcodec libx264 -pix_fmt yuv420p -acodec copy out.mp4
寻找
crop
参数使用 cropdetect
筛选:cropdetect的描述筛选:
Auto-detect the crop size.
It calculates the necessary cropping parameters and prints the recommended parameters via the logging system.
The detected dimensions correspond to the non-black area of the input video.
使用
cropdetect
this post 中描述了 Linux 的结果。 .我想在 Windows 10 中使用它,发现 this example ,
但它不工作......
以下代码正在运行(使用 ffmpeg 版本 4.4.1-full_build-www.gyan.dev):
ffmpeg -hide_banner -i in.jpg -vf scale=1920:1080,setsar=1:1,cropdetect=skip=0 -t 1 -f null - 2>&1 | findstr /R /C:"crop=" > log.txt
for /F "tokens=14* delims= " %%i in (log.txt) do set crop=%%i
echo %crop%
使用 %crop%
使用 FFmpeg 命令:ffmpeg -y -i in.jpg -filter_complex "scale=1920:1080,setsar=1:1,%crop%,split[crp0][crp1];[crp0]scale=1920:1080,setsar=1:1,gblur=sigma=30[blur];[blur][crp1]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" out.jpg
不写入
log.txt
的批处理文件:@echo off
setlocal EnableExtensions EnableDelayedExpansion
set count=1
for /F "tokens=2* delims==" %%F in ('"ffmpeg -hide_banner -i in.jpg -vf scale=1920:1080,setsar=1:1,cropdetect=skip=0 -t 1 -f null - 2>&1"') do (
set var!count!=%%F
set /a count=!count!+1
)
echo %var1%
ffmpeg -y -i in.jpg -filter_complex "scale=1920:1080,setsar=1:1,crop=%var1%,split[crp0][crp1];[crp0]scale=1920:1080,setsar=1:1,gblur=sigma=30[blur];[blur][crp1]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" out.jpg
endlocal
关于video - FFmpeg:如何将带有黑框的水平非全高清视频渲染为 1920x1080 的视频,背景模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71514514/