From f746d0aea2fa631a8ffc30dc39831b0de1616121 Mon Sep 17 00:00:00 2001 From: KazooTTT Date: Mon, 14 Oct 2024 22:49:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0ffmpeg=E6=89=B9?= =?UTF-8?q?=E5=A4=84=E7=90=86=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/软件/06 我自己常用的ffmpeg批处理.md | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/content/post/软件/06 我自己常用的ffmpeg批处理.md diff --git a/src/content/post/软件/06 我自己常用的ffmpeg批处理.md b/src/content/post/软件/06 我自己常用的ffmpeg批处理.md new file mode 100644 index 0000000..968e5f6 --- /dev/null +++ b/src/content/post/软件/06 我自己常用的ffmpeg批处理.md @@ -0,0 +1,86 @@ +--- +title: 我自己常用的ffmpeg批处理 +date: 2024-10-14 +author: KazooTTT +type: Post +status: Published +tags: [视频处理, ffmpeg] +finished: false +published: true +category: 软件 +slug: my-own-commonly-used-ffmpeg-batching +description: +--- + +## 720x1080批量转1920x1080(两边黑屏) + +手机直播的时候录播机录出来的分辨率是720x1080,使用ffmpeg转成横屏的1920x1080。这样xml转ass弹幕的时候,就不需要另外处理了,看起来很更舒服。 + +macos的写法: + +```bash +input_folder="" # 要转化的录播的文件夹路径 +output_folder="" # 要输出的文件夹路径 + +# Create the output folder if it does not exist +mkdir -p "$output_folder" + +for f in "$input_folder"/*.flv; do + ffmpeg -i "$f" -vf "scale=720:1080,pad=1920:1080:(ow-iw)/2:(oh-ih)/2" -c:a copy "$output_folder/$(basename "${f%.*}.mp4")" +done +``` + +windows的写法: + +```powershell +$input_folder = "Z:\\rec\\48743-hanser\\20240731-又来画画了!" # 要转化的录播的文件夹路径 +$output_folder = "Z:\\rec\\48743-hanser\\20240731-又来画画了!" # 要输出的文件夹路径 + +# Create the output folder if it does not exist +If (-Not (Test-Path $output_folder)) { + New-Item -ItemType Directory -Path $output_folder | Out-Null +} + +Get-ChildItem -Path $input_folder -Filter *.flv | ForEach-Object { + $input_file = $_.FullName + $output_file = Join-Path $output_folder ($_.BaseName + ".mp4") + $ffmpeg_args = @("-i", $input_file, "-vf", "scale=720:1080,pad=1920:1080:(ow-iw)/2:(oh-ih)/2", "-c:a", "copy", $output_file) + & ffmpeg $ffmpeg_args +} +``` + +效果 + +![image.png](https://pictures.kazoottt.top/2024/10/20241014-20241014224347.png) + +## 弹幕压制 + +### windows版(使用cuda) + +```bash +@echo off +set input_folder=YourInputFolderPath +set output_folder=YourOutputFolderPath + +for %%a in ("%input_folder%\\*.flv") do ( + ffmpeg -hwaccel cuda -c:v h264_cuvid -i "%%a" -vf subtitles="%%~na.ass" -c:v h264_nvenc -b:v 6000k -c:a copy "%output_folder%\\%%~na_压制.mp4" -y +) +``` + +### macOS版 + +```bash +#!/bin/bash + +input_folder="/path/to/input" # Replace with your input folder path +output_folder="/path/to/output" # Replace with your output folder path + +mkdir -p "$output_folder" # Create the output folder if it doesn't exist + +for f in "$input_folder"/*.mp4; do + subtitle_file="${f%.*}.ass" # Assumes subtitle file name is same as video file name but with .ass extension + output_file="$output_folder/$(basename "${f%.*}_压制.mp4")" # Output file name with _ass suffix + + ffmpeg -i "$f" -vf "ass=$subtitle_file" "$output_file" +done +```