ffmpegを使いこなしたい



サイズ変更

ffmpeg -v error -y -i input -vf scale=1280:720 cow_720p.mp4


-y

上書きON。

 -vf scale

横:縦. -1, -2にすると自動で変更.
-1の場合,いいように勝手に丸めてくれる ,奇数だとダメ.
-2の場合,偶数になるように丸めてくれる
また,アスペクト比を維持しながら,特定の枠内に収めたい場合は引数を以下のようにする.

w:h:force_original_aspect_ratio=decrease


余白を作り動画のアスペクト比を変更

ffmpeg -v error -y -i input -vf "scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2" out

このコマンドでは,中央に貼り付けてる.
黒い余白ができる.














動画をつなげる (Merging, Stitching)

ステップ1:リスト作る

list.txt
file 'input1.mp4'
file 'input2.mp4'
file 'input3.mp4'

ただし,ファイルのコーデック,fpsが同一でなければならない.

ステップ2:連結する

ffmpeg -y -v error -f concat -i list.txt output.mp4


エラー

Unsafe file name 'input.MP4'
list.txt: Operation not permitted

-safe 0
をつける.

ffmpeg -y -v error -safe 0 -f concat -i list.txt output.mp4






動画をトリミングする

開始時刻と終了時刻を指定する

ffmepg -y -v error -i input -ss 00:02:22.000 -to 320.0 output

-ss

開始時刻。
タイムコード形式(hh:mm:ss.sss) か、秒数形式で指定。

-to

終了時間。
タイムコード形式(hh:mm:ss.sss) か、秒数形式で指定。

開始時刻とトリミング時間を指定する

ffmepg -y -v error -i input -ss 00:02:22.000 -t 5 output

-ss

開始時刻。
タイムコード形式(hh:mm:ss.sss) か、秒数形式で指定。

-t

トリミング秒数。


動画をクロップする

https://ffmpeg.org/ffmpeg-filters.html#toc-crop

位置サイズを数値指定する

Crop area with size 100x100 at position (12,34).
crop=100:100:12:34
Using named options, the example above becomes:
crop=w=100:h=100:x=12:y=34

x, yのデフォは中央
w, hのみで中央クロップ

crop=100:100





動画を回転する

ffmpeg Documentation

時計回り90度回転

ffmepg -y -v error -i input -vf transpose=1 output


反時計回り90度回転

ffmepg -y -v error -i input -vf transpose=2 output


動画を反転する

左右反転

ffmepg -y -v error -i input -vf vflip output


上下反転

ffmepg -y -v error -i input -vf hflip output