動画変換バッチファイル(video file to .mp4)


1. 小ネタ

  • .AVI、.WMV動画形式の想い出の動画ファイルを、利用しやすい.MP4動画形式で残しておきたい時にお使いください。
  • 作成したバッチファイル上に、変換元の動画ファイルをドラッグ&ドロップすることで.MP4ファイルが、変換元動画ファイルと同一フォルダ内に生成されます。

2. 前提条件

3. 動画変換バッチファイル

conv2MP4spacetrim.bat(ファイル名の半角スペース除去に対応したもの:Windowsバッチファイル)
@echo off
cd /d %~dp0
setlocal enabledelayedexpansion

: 引数パラメータの複数ファイル分繰り返し(ドラッグ&ドロップでも動くよ)
for %%f in (%*) do (
    call :DUPCHECK %%f

    : INファイル名、OUTファイル名の出力
    echo ^(IN^) %%~f ^(OUT^) !file!

    "C:\Program Files\VideoLAN\VLC\vlc.exe" -vvv --sout="#transcode{acodec=mp4a,ab=128,channels=2,samplerate=44100,vcodec=h264,deinterlace}:duplicate{dst=std{access=file,mux=mp4,dst=!file!}}" "%%~f" --play-and-exit
    echo end.
)
exit /b

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DUPCHECK
: 既存ファイルとファイル名が重複しない新規ファイル名を決定する
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
for /L %%i in (0,1,10) do (
    if %%i equ 0 (
        set file=%~dpn1.mp4

        : スペース除去
        set "file=!file: =_!"
    ) else (
        set file=%~dpn1 ^(%%i^).mp4

        : スペース除去
        set "file=!file: =_!"
    )

    : 既存ファイルと重複しないファイル名であればループ終了
    if not exist !file! exit /b
)
pause
exit /b
buzzyvox2017065365.bat(buzzyvoxサイトさんの参考にして作成したもの:Windowsバッチファイル)
@echo off
cd /d %~dp0
setlocal enabledelayedexpansion

: 引数パラメータの複数ファイル分繰り返し(ドラッグ&ドロップでも動くよ)
for %%f in (%*) do (
    call :DUPCHECK %%f

    : INファイル名、OUTファイル名の出力
    echo ^(IN^) %%~f ^(OUT^) !file!

:    "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" -vvv "%%~f" --sout-avcodec-strict=-2 --qt-start-minimized --sout=#transcode{acodec=mp4a,ab=128,channels=2,samplerate=44100,vcodec=h264,deinterlace}:standard{access=file,mux=mp4,dst="!file!"} vlc://quit
    "C:\Program Files\VideoLAN\VLC\vlc.exe" -vvv --sout="#transcode{acodec=mp4a,ab=128,channels=2,samplerate=44100,vcodec=h264,deinterlace}:duplicate{dst=std{access=file,mux=mp4,dst=!file!}}" "%%~f" --play-and-exit
    echo end.
)
exit /b

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DUPCHECK
: 既存ファイルとファイル名が重複しない新規ファイル名を決定する
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
for /L %%i in (0,1,10) do (
    if %%i equ 0 (
        set file=%~dpn1.mp4
    ) else (
        set file=%~dpn1 ^(%%i^).mp4
    )

    : 既存ファイルと重複しないファイル名であればループ終了
    if not exist !file! exit /b
)
pause
exit /b
multiconvertMP4.bat(複数動画ファイル一括変換:Windowsバッチファイル)
@echo off
cd /d %~dp0
setlocal enabledelayedexpansion

: 変数宣言
set selfname=%~n0
set ret_success=0
set ret_fail=1

echo Convert video files to MP4.

: 引数チェック
if "%1"=="" (
    call :usage
    pause
    exit /b %ret_success%
)

: 引数ヘルプ
if "%1"=="-h" (
    call :usage
    pause
    exit /b %ret_success%
)


: 引数ファイル数分繰り返し
for %%f in (%*) do (
    : インプットファイル
    set infile=%%f

    : アウトプットファイル
    set outfile=%%f.mp4

    echo In  file !infile!
    echo Out file !outfile!

    : 動画変換
    echo Converting video... please wait.
    "C:\Program Files\VideoLAN\VLC\vlc.exe" -vvv --sout="#transcode{acodec=mp4a,ab=128,channels=2,samplerate=44100,vcodec=h264,deinterlace}:duplicate{dst=std{access=file,mux=mp4,dst=!outfile!}}" "!infile!" --play-and-exit
)
echo Finish Convert.
pause

: 終了
exit /b %ret_success%

: 使い方ラベル
:usage
echo [Usage]
echo Drag and drop multiple video file into this file.  : multiple videofile to MP4 convert.
echo %selfname% videofile1 [videofile2] [...]           : videofile to MP4 convert.
echo %selfname% -h                                      : Show the usage.
echo %selfname%                                         : Show the usage.
exit /b %ret_success%

convertMP4.bat(単一動画ファイル変換:Windowsバッチファイル)
echo off

: 変数宣言
set selfname=%~n0
set ret_success=0
set ret_fail=1

echo Convert video files to MP4.

: 引数チェック
if "%1"=="" (
    call :usage
    pause
    exit /b %ret_success%
)

: 引数ヘルプ
if "%1"=="-h" (
    call :usage
    pause
    exit /b %ret_success%
)

: インプットファイル
@SET infile=%~f1

: アウトプットファイル
@SET outfile=%~dpn1.mp4

: 表示
echo In  file %infile%
echo Out file %outfile%

: 動画変換
echo Converting video... please wait.
"C:\Program Files\VideoLAN\VLC\vlc.exe" -vvv --sout="#transcode{acodec=mp4a,ab=128,channels=2,samplerate=44100,vcodec=h264,deinterlace}:duplicate{dst=std{access=file,mux=mp4,dst=%outfile%}}" "%infile%" --play-and-exit

: 終了
exit /b %ret_success%

: 使い方ラベル
:usage
echo [Usage]
echo Drag and drop the video file into this file.   : videofile to MP4 convert.
echo %selfname% videofile1 [videofile2] [...]       : videofile to MP4 convert.
echo %selfname% -h                                  : Show the usage.
echo %selfname%                                     : Show the usage.
exit /b %ret_success%


4. 参考文献