LoginSignup
3
0

FFMPEGで動画ファイルをAV1に圧縮するバッチファイル(GPU使用)

Posted at

指定されたフォルダのビデオファイルを自動で処理します。

主な処理:

1.指定されたフォルダに移動。
2.encode_end と no_encodedフォルダがなければ作成。
3.指定されたフォルダとサブフォルダの .mp4、.mkv、.avi、.mov ファイルを探します。
  encode_end と no_encoded フォルダの中のファイルは無視。
4.ファイル名に "av1" が含まれていない、かつサイズが500MB以上のファイルをAV1エンコード。
5.エンコード後、元のファイルは encode_end に移動。
6.新しいファイル名には "_av1" が追加。
7.500MB未満のファイルは no_encoded フォルダに移動。

このスクリプトは、ビデオファイルを自動的に新しいフォーマットに変換し、整理することを目的としています。

AV1エンコードのためにRTX4000系がいるかもしれません?
また、以下を変えるとCPU使用に変えられますが重くてやってられないと思います。

ffmpeg -i "%%f" -c:v av1_nvenc -c:a copy "%%~dpf%%~nf_av1.mkv"

ffmpegで動画ファイルをAV1に変更する。
@echo off
setlocal enabledelayedexpansion

:: Set the directory path
set "folderPath=%~1"

:: Change directory to the specified path
cd /d "%folderPath%"

:: Create directories if they do not exist
if not exist "encode_end" mkdir "encode_end"
if not exist "no_encoded" mkdir "no_encoded"

:: Loop through all video files in the folder and subfolders
for /r "%folderPath%" %%f in (*.mp4 *.mkv *.avi *.mov) do (
    :: Exclude files in encode_end, and no_encoded directories
    echo %%f | findstr /i /v "\\encode_end\\" | findstr /i /v "\\no_encoded\\" > nul
    if !errorlevel! equ 0 (
        :: Check if filename contains "av1"
        echo %%f | findstr /i "av1" > nul
        if !errorlevel! equ 1 (
            :: Get file size
            set "fileSize=%%~zf"
            
            :: Check if file size is 500MB or more
            if !fileSize! geq 524288000 (
                :: Execute FFmpeg command for each file, encode to MKV with AV1 codec and add "_av1" suffix to the file name
                ffmpeg -i "%%f" -c:v av1_nvenc -c:a copy "%%~dpf%%~nf_av1.mkv"
                
                :: Rename the original video file
                ren "%%f" "encode_%%~nxf"
                
                :: Move the renamed file to encode_end directory
                move "%%~dpfencode_%%~nxf" "%folderPath%\encode_end\"
            ) else (
                :: Move files smaller than 500MB to no_encoded directory
                move "%%f" "%folderPath%\no_encoded\"
            )
        )
    )
)

endlocal
cmd /k echo end.

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0