video - FFmpeg:如何将带有黑框的水平非全高清视频渲染为 1920x1080 的视频,背景模糊

标签 video ffmpeg background blur

示例视频:
enter image description here
期望的结果:
enter image description here

最佳答案

完整的命令可能如下:

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 )。

样本输出:
enter image description here

过滤器链:
  • 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/

    相关文章:

    php - 我如何知道 exec 函数中的命令错误?

    python - Tkinter:模糊透明背景帧

    html - 图片标签中的背景位置

    video - FFmpeg 可能带有 -pre 标志的错误

    FFMPEG 仅在 4k 视频并保持纵横比时降级

    video - DirectShow、Media Foundation、DXVA,什么?

    ffmpeg - 如何从视频文件中提取编码的传输流帧?

    java - 在 java web 应用程序 (struts2) 中使用 quartz 调度程序时,我应该在哪里配置作业?

    xcode - Ipad MPMovieplayerController 视频加载但播放时自动暂停

    c# - 移动实时视频编码