アーケードゲームのプレイを録画した際、機器によっては録画した動画の向きが横になっている場合があります。
FFmpegを使えば動画を回転して正しい向きにすることができるのですが、GUIを持たないツールであるため、コマンドラインに慣れていない方にとっては少々扱いづらいアプリケーションです。
そこで今回はHTAを使って簡易的なフロントエンドを用意したいと思います。
FFmpegの準備
まずは動画の回転に使用するFFmpegをダウンロードします。
- 「Download FFmpeg」からWindows向けFFmpegのダウンロードページを開きます。
- 32ビット版と64ビット版に分かれているので、自分の環境に応じたファイル(zip形式)をダウンロードします。「Static」「Shared」「Dev」バージョンがありますが、特にこだわりが無ければ「Static」バージョンで良いでしょう。
- 手順2.でダウンロードしたzipファイルを適当な場所に解凍します。
HTAの準備
FFmpegの準備が終わったら、次はフロントエンドとなるHTAファイルを作成します。
- メモ帳を起動し、下記コードを貼り付けます。
- 「名前を付けて保存」から、ファイルの種類を「すべてのファイル」、文字コードを「UTF-8」、ファイルの拡張子(ファイル名)を「hta」にして適当な場所に保存します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | <!DOCTYPE html> <!-- 動画回転用簡易FFmpegフロントエンド @kinuasa ※要ffmpeg.exe ※https://ffmpeg.org/download.html からダウンロード --> <html> <head> <meta charset= "UTF-8" > <meta http-equiv= "X-UA-Compatible" content= "IE=10" > <title>動画回転用簡易FFmpegフロントエンド</title> <style> * { font-family: "Segoe UI" , Meiryo, "メイリオ" , sans-serif; font-size: 11pt; } table { border-style: none; } tr, td { border-style: none; padding: 5px; } #btnExec { border-top: 1px solid #96d1f8; background: #65a9d7; padding: 15px 30px; color: white; font-size: 16px; /* font-weight: bold; */ text-decoration: none; vertical-align: middle; } #btnExec:hover { border-top-color: #28597a; background: #28597a; color: #ccc; cursor: pointer; } #btnExec:active { border-top-color: #1b435e; background: #1b435e; } </style> <script language= "vbscript" > Option Explicit Private Const FileSuffix = "_output" Private Sub window_OnLoad() 'ウィンドウリサイズ・移動 window.resizeTo 600, 250 window.moveTo 250, 250 End Sub Private Sub btnExec_OnClick() Dim FfmpegFilePath Dim SrcFilePath Dim DestFilePath Dim DestFolderPath Dim Rotate Dim Com Dim iptFfmpegFile Dim iptSrcFile Set iptFfmpegFile = document.getElementById( "iptFfmpegFile" ) Set iptSrcFile = document.getElementById( "iptSrcFile" ) FfmpegFilePath = iptFfmpegFile.Value SrcFilePath = iptSrcFile.Value Rotate = document.getElementById( "selRotate" ).Value With CreateObject( "Scripting.FileSystemObject" ) 'ファイルチェック If (Len(Trim(FfmpegFilePath))) < 1 Then MsgBox "ffmpeg.exeファイルを指定してください。" , vbCritical + vbSystemModal iptFfmpegFile.Focus Exit Sub End If If .FileExists(FfmpegFilePath) = False Then MsgBox "[" & FfmpegFilePath & "]ファイルが見つかりません。" & vbNewLine & _ "処理を中止します。" , vbCritical + vbSystemModal iptFfmpegFile.Focus Exit Sub End If If (Len(Trim(SrcFilePath))) < 1 Then MsgBox "変換元ファイルを指定してください。" , vbCritical + vbSystemModal iptSrcFile.Focus Exit Sub End If If .FileExists(SrcFilePath) = False Then MsgBox "[" & SrcFilePath & "]ファイルが見つかりません。" & vbNewLine & _ "処理を中止します。" , vbCritical + vbSystemModal iptSrcFile.Focus Exit Sub End If '保存先ファイル設定 DestFolderPath = .GetParentFolderName(SrcFilePath) DestFilePath = AddPathSeparator(DestFolderPath) & _ .GetBaseName(SrcFilePath) & FileSuffix & _ "." & .GetExtensionName(SrcFilePath) 'MsgBox DestFolderPath & vbNewLine & DestFilePath '確認用 End With If MsgBox( "[" & DestFilePath & "]にファイルが保存されます。" & vbNewLine & _ "処理を続行しますか?" , vbQuestion + vbYesNo + vbSystemModal) = vbNo Then Exit Sub End If '---------------------------------------------- '※ffmpegに渡すパラメーター、必要に応じて変更 '---------------------------------------------- Com = "" "" & FfmpegFilePath & "" " -y -i " "" & SrcFilePath & "" " -c copy -metadata:s:v:0 rotate=" & Rotate & " " "" & DestFilePath & "" "" '---------------------------------------------- 'MsgBox Com '確認用 CreateObject( "WScript.Shell" ).Run Com, 1, True '変換処理実行 If MsgBox( "変換処理が終了しました。" & vbNewLine & _ "(ファイル:" & DestFilePath & ")" & vbNewLine & _ "ファイルの保存先フォルダを開きますか?" , vbInformation + vbYesNo + vbSystemModal) = vbYes Then CreateObject( "Shell.Application" ).Open DestFolderPath End If End Sub Private Function AddPathSeparator( ByVal Path) Dim ret ret = Path If Right(ret, 1) <> ChrW(92) Then ret = ret & ChrW(92) AddPathSeparator = ret End Function </script> </head> <body> <table> <tr> <td>ffmpeg.exe:</td> <td><input id= "iptFfmpegFile" type= "file" accept= ".exe" size= "40" title= "ffmpeg.exeファイルを選択します。" ></td> </tr> <tr> <td>変換元:</td> <td><input id= "iptSrcFile" type= "file" accept= ".mp4" size= "40" title= "変換元の動画ファイルを選択します。" ></td> </tr> <tr> <td>回転角度:</td> <td> <select id= "selRotate" title= "動画の回転する角度を指定します。" > <option value= "90" >90</option> <option value= "180" >180</option> <option value= "270" selected>270</option> </select> </td> </tr> <tr> <td colspan= "2" ><input id= "btnExec" type= "button" value= "変換実行" title= "動画ファイルの変換を実行します。" ></td> </tr> </table> </body> </html> |
回転処理の実行
HTAファイルの準備が出来たら、いよいよ回転処理の実行です。
- 上記手順で作成したHTAファイルを実行します。
- 「ffmpeg.exe」横にある「参照」ボタンをクリックして、事前に準備しておいた「ffmpeg.exe」ファイルを選択します。
- 「変換元」横にある「参照」ボタンをクリックして、回転したい動画ファイルを選択します。
- 回転角度を指定した後「変換実行」ボタンをクリックします。
- 確認ダイアログが表示されるので、問題が無ければ「はい」ボタンをクリックします。処理後のファイルは元のファイル名に「_output」が付いた形で、元のファイルと同じ場所に保存されます。
- 処理終了後の確認ダイアログで「はい」ボタンをクリックすると、ファイルの保存先フォルダが表示されます。
- 出力されたファイルを再生すると、ちゃんと回転されていることが確認できます。
おわりに
フロントエンドといっても単にffmpeg.exeにパラメーターを渡しているだけなので、大したことはしていません。
正直バッチファイルを用意した方が手っ取り早いのですが、コマンドプロンプトでの操作に慣れていない方向けにUIを用意してみました。
WPFあたりでコードを書いた方が簡潔でユーザーフレンドリーなものになったはずですが、“メモ帳だけでも簡単に作れる”点で、今回はHTAを使うことにしました。
(もはや化石ともいえるHTAですが、一応Windows 10 + Internet Explorer 11環境でも動作します。)
参考Webページ
- FFmpeg
- https://ja.wikipedia.org/wiki/FFmpeg
- ffmpegの使い方
- http://tech.ckme.co.jp/ffmpeg.shtml
- スマホで撮影した映像をffmpegで正しい向きに変換する(+縮小変換)
- http://qiita.com/naga3/items/639da87ad56c67549eee
この記事へのコメントはありません。