現時点で扱っている動画形式は、iPhoneから録画したMOVファイルと、ビデオカメラから録画したMTS(AVCHD)ファイルの主に2形式になる。
これらのファイルをffmpegを使って、mp4形式になるべく劣化しないように変換を試行錯誤したときの結果を残しておく。(ほとんどがネットにあった設定を試しただけ)
MOVからmp4変換
22MBから9.5MBまで削減して、ほとんど劣化なし(自分の視聴環境で)。しかも変換も早く優秀だった。
ffmpeg -i input.mov -vcodec libx264 -preset veryfast -crf 25 -tune zerolatency,film -movflags +faststart output.mp4
MTS(AVCHD)からmp4変換
MTSだと上記設定だと劣化が目立った。以下だとほぼ劣化は体感しなかった。MOVも以下のパラメータで変換しても画質は良かったが、少し時間がかかる。
22MBから6.8MBまで圧縮された。
ffmpeg -i input.mts -vcodec libx264 -ar 48000 -ab 128k -r 30000/1001 -vsync 1 -deinterlace -f mp4 -bufsize 20000k -maxrate 25000k output.mp4
動画ファイルから情報取得する方法
ffmpegと同じディレクトリに同梱されているffprobe.exeを使う。
-hide_banner
と-show_format
を追加すると、FORMATタグ内に拾いやすい情報が出力される。
> ffprobe input.mts -v quiet -hide_banner -show_format
[FORMAT]
filename=test.MTS
nb_streams=3
nb_programs=1
format_name=mpegts
format_long_name=MPEG-TS (MPEG-2 Transport Stream)
start_time=1.033367
duration=8.512000
size=18087936
bit_rate=16999939
probe_score=50
[/FORMAT]
JSON形式もある
> ffprobe input.mts -v quiet -hide_banner -show_streams -print_format json
{
"streams": [
{
"index": 0,
"codec_name": "h264",
"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
"profile": "High",
"codec_type": "video",
"codec_time_base": "1001/60000",
"codec_tag_string": "HDMV",
"codec_tag": "0x564d4448",
"width": 1920,
"height": 1080,
"coded_width": 1920,
"coded_height": 1080,
"has_b_frames": 1,
:
}
]
}
ちなみにMTSファイルの場合、ファイル内には作成日付が存在しないので、ファイルそのものの作成日付や更新日付を不正確ではあるが、頼るしかない。
> ffprobe input.mts -v quiet -hide_banner -show_format
[FORMAT]
filename=input.mts
nb_streams=3
nb_programs=1
format_name=mpegts
format_long_name=MPEG-TS (MPEG-2 Transport Stream)
start_time=1.033367
duration=8.512000
size=18087936
bit_rate=16999939
probe_score=50
[/FORMAT]
MOV(QuickTime)はタグが存在していた。
> ffprobe input.mov -v quiet -hide_banner -show_format
[FORMAT]
filename=input.mov
nb_streams=4
nb_programs=0
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=0.000000
duration=13.241667
size=22795543
bit_rate=13772008
probe_score=100
TAG:major_brand=qt
TAG:minor_version=0
TAG:compatible_brands=qt
TAG:creation_time=2016-07-25T03:00:34.000000Z
TAG:com.apple.quicktime.location.ISO6709=+xx.xxxx+xxx.xxxx+xx.xxx/
TAG:com.apple.quicktime.make=Apple
TAG:com.apple.quicktime.model=iPhone 5s
TAG:com.apple.quicktime.software=9.3.2
TAG:com.apple.quicktime.creationdate=2016-07-25T12:00:34+0900
[/FORMAT]
MOVのほうが、色々とプログラム的には扱いやすいことがわかった。