[英]FFmpeg: How to convert horizontal video 16:9 to vertical video 9:16, with blurred background on top and bottom sides
[英]FFmpeg: convert any video to square 1:1 video with blurred side bars
與此主題非常相似:
FFmpeg:如何將具有黑色邊的垂直視頻轉換為具有模糊背景邊的視頻 16:9
我正在嘗試為自己制作一個 bat 文件,以自動化我的 Instagram 視頻創作。
這個想法是我制作可變分辨率和可變縱橫比的視頻。 我不想花時間在每個視頻上,只是為了讓它適合。
所以這是我對那個 bat 文件的目標:
到目前為止,我設法獲得了僅適用於垂直或水平視頻但不能同時適用的結果。 或者以裁剪的原始視頻結束,這是我不想要的:我根據需要對我的主題進行構圖,並且我不想預先考慮 FFmpeg 編碼可以做的額外裁剪。
到目前為止,這是我的腳本:
echo off
:again
ffmpeg.exe -i "%~1" ^
-c:v libx264 -crf 23 -filter_complex "[0:v]scale=600*2:600*2,boxblur=luma_radius=min(h\,w)/20:luma_power=1:chroma_radius=min(cw\,ch)/20:chroma_power=1[bg];[0:v]scale=600:-1[ov];[bg][ov]overlay=(W-w)/2:(H-h)/2,crop=w=600:h=600" -profile:v baseline -level 3.0 -pix_fmt yuv420p -preset faster -tune fastdecode ^
-c:a aac -ac 2 -b:a 128k ^
-movflags faststart ^
"%~p1%~n1_Instagramized.mp4" -y
if NOT ["%errorlevel%"]==["0"] pause
shift
if "%~1" == "" goto:eof
goto:again
編輯:
感謝@Gyan,我得到了解決方案。 我也添加了我的輸入:
由於我可能經常重復使用該 bat 文件並且可能想要更改 output 分辨率,因此將分辨率硬編碼在六個不同的位置並不方便。
因此,我創建了一個名為SquareSize
的變量,該變量使用%SquareSize%
(而不是硬編碼的分辨率)調用,並使用set SquareSize=XXX
在文件的開頭進行設置。 所以現在我可以在需要時輕松更改,只需打開它並編輯 XXX。
echo off
:again
set SquareSize=600
ffmpeg.exe -i "%~1" ^
-c:v libx264 -crf 23 ^
-filter_complex "[0:v]split=2[blur][vid];[blur]scale=%SquareSize%:%SquareSize%:force_original_aspect_ratio=increase,crop=%SquareSize%:%SquareSize%,boxblur=luma_radius=min(h\,w)/20:luma_power=1:chroma_radius=min(cw\,ch)/20:chroma_power=1[bg];[vid]scale=%SquareSize%:%SquareSize%:force_original_aspect_ratio=decrease[ov];[bg][ov]overlay=(W-w)/2:(H-h)/2" ^
-profile:v baseline -level 3.0 -pix_fmt yuv420p -preset faster -tune fastdecode ^
-c:a aac -ac 2 -b:a 128k ^
-movflags faststart ^
"%~p1%~n1_Instagramized.mp4" -y
if NOT ["%errorlevel%"]==["0"] pause
shift
if "%~1" == "" goto:eof
goto:again
這就是 filter_complex 應該是的,
"[0:v]split=2[blur][vid];[blur]scale=L:L:force_original_aspect_ratio=increase,crop=L:L,boxblur=luma_radius=min(h\,w)/20:luma_power=1:chroma_radius=min(cw\,ch)/20:chroma_power=1[bg];[vid]scale=L:L:force_original_aspect_ratio=decrease[ov];[bg][ov]overlay=(Ww)/2:(Hh)/2"
將L
替換為文字數字或變量,它表示邊的長度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.