0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

FFmpegコマンド集

Last updated at Posted at 2024-11-02

使えそうなFFmpegコマンドをここに乗せておく。適当に書いただけで動かないやつもあるかもしれない。教えて。
いちいち説明とかしないから自分で見て考えよう。

ヒント

色は0x+16進数で表現される。例: 0xFFFFFF

ヘルプ

ffmpeg -h

適用したい部分2箇所にクロマキーを適用、背景に重ねる

ffmpeg -i GB.mp4 -i back.png -filter_complex "[0:v]scale=1280x720,chromakey=color=0x00FF00:similarity=0.3:enable='between(t,0,4)+between(t,9,12.5)':[chroma];[1:v]scale=1280x720[back];[back][chroma]overlay[out];" -map [out] -map 0:a -c:a copy -pix_fmt yuv420p out.mp4 

黒背景の動画を半透明の連番画像にする。透過?Unmult的な。色を変えればベースカラーも変わる。

ffmpeg -i sample.mp4 -vf "colorkey=black:0.01:1" folder/%00d.png

動画補完。精度はあまり期待できない

ffmpeg -i sample.mp4 -vf "minterpolate=fps=60" -pix_fmt yuv420p -c:a copy out.mp4

二倍速にする。

ffmpeg -i out.mp4 -filter_complex "[0:v]setpts=PTS*0.5[video];[0:a]atempo=2.0[audio];" -map [video] -map [audio] -f matroska -c:v h264_nvenc - | ffplay -i -

音量を三倍にする

ffmpeg -i sample.mp4 -af "volume=3" -c:v copy out.mp4 

動画の中心に文字を書き込む

ffmpeg -i sample.mp4 -filter_complex "[0:v]drawtext=fontsize=56:fontcolor=black:text='FFMPEG':text_align=C:x=(w-text_w)/2:y=(h-text_h)/2:" -pix_fmt yuv420p out.mp4 

画像連番から動画、音声結合も

ffmpeg -r 60 -i %00d.png -i v.wav -pix_fmt yuv420p -map 0:v -map 1:a out.mp4

動画カット、再エンコードなし

ffmpeg -i input.mp4 -ss 0.2 -t 3.1 -c:v copy -c:a copy output1.mp4

静止画切り出し

ffmpeg -i input.mp4 -ss 3 -vframes 1 output.png

ズームイン、ビート(?) いじれば単純にズームインするものにもできる

ffmpeg -i sample.mp4 -filter_complex "[0:v]zoompan=z='1+pow((1-mod(time*2,1)),5)/2':d=1:x=iw/2-(iw/zoom/2)+sin(time*20)*10:y=ih/2-(ih/zoom/2)+sin(time*20)*10[out]" -map [out] -map [0:a] -pix_fmt yuv420p -c:a copy out.mp4

真っ白な画像を生成

ffmpeg -f lavfi -r 60 -i color=white:1280x720:d=1 -ss 0 -vframes 1 out.png
ffmpeg -i color.mp4 -i alpha.mp4 -filter_complex "[0:v]scale=1280x720[col][1:v]scale=1280x720[alp[col][alp]alphamerge" out.mp4

音声波形を作る

ffmpeg -i out.mp3 -i untitled.png -filter_complex " [0:0]showfreqs=size=960x540:mode=1[wave];[1:0]colorize=saturation=1:lightness=0:mix=0,scale=960x540[back];[back][wave]overlay=format=auto:x=(W-w)/2:y=(H-h)/2,format=yuv420p[outv];" -map "[outv]" -map 0:a:0 -b:v 1M -pix_fmt yuv420p "waves.mp4"
ffplay waves.mp4

なんかあったし置いとく 音声波形をNCSリング風にするやつにしたかったものっぽい?

ffmpeg -i out.mp3 -i untitled.png -filter_complex " [0:0]showwaves=size=960x270:mode=2:split_channels=0:colors=000000:rate=25[wave];[wave]geq='lum=sqrt(X*X+Y*Y):lum=atan2(Y,X)'[wave2];[1:0]colorize=saturation=1:lightness=1:mix=0,scale=960x540[back];[back][wave2]overlay=format=auto:x=(W-w)/2:y=(H-h)/2,format=yuv420p[outv];" -map "[outv]" -map 0:a:0 -pix_fmt yuv420p "waves.mp4"

色調補正して、FFplayにパイプ ファイルをいちいち作成する必要もないときによさそう
matroska(mkv)はほとんどの種類の動画のコンテナになれるから採用

ffmpeg -i sample.mp4 -vf "colorize=hue=90:saturation=0.3:lightness=0.3:mix=1" -f matroska - | ffplay -i -

フェードイン

ffmpeg -i input.mp4 -vf "fade=type=in:duration=2,afade=type=in:duration=2" out.mp4

ブラー

ffmpeg -i input -vf "avgblur=sizeX=3:sizeY=3" output.mp4

NVenc(ハードウェアアクセラレーション)でフルHDの動画をレンダリングするとき、よさげなコマンド

ffmpeg -i video.mp4 -c:v h264_nvenc -bf 3 -refs 4 -b:v 7M -vf scale=1920x1080 out.mp4

フォルダ内にある全メディアファイルを変換するバッチスクリプト
書き方のキモさはご愛敬。batchが悪い。俺は悪くない。
何があっても保証はできない。自分でしっかりテストしてから実行しよう。
バッチの何もかも分からない人用に、remはコメント。バッチ内に日本語が入るとしばしば不都合が起きる。

スクリプト
@echo off
setlocal enabledelayedexpansion
rem Convert/compress all the videos and musics inside of the folder. 


rem specifies folder name that compressed files will be stored.
set "output_folder=compressed"
mkdir %output_folder%
rem if it is set to 0, it will delete the old file, set it to 1 if you don't wish to.
rem when it detects an error it will not delete the old file even if it was set to 0.
rem it's probably the best idea to manually delete the old data in case something happens.
set DeleteOldFile=0

rem _fmt are the types of files that will be converted/compressed.
rem _output specifies the extension(format) of the output file.

rem Video formats.
set V_fmt=.mp4 .avi .mov .webm .mkv
set V_output=mp4
rem Audio formats.
set A_fmt=.mp3 .m4a .wav .wma .aac .ogg .opus
set A_output=mp3
rem Non-transparent image formats. you shouldn't contain transparent images like png since it will lose its transparency.
rem Also, since PNG is a lossless conversion, you probably don't need to compress.
set J_fmt=.jpg .jpeg .jfif .bmp 
set J_output=jpg


rem this is where you specify your ffmpeg argument. I recommend you to leave it unless you know what you're doing.
rem One tip I should tell you, when -y is specified, it will overwrite without asking you... which probably never happens
set "V_args= -loglevel quiet -y -pix_fmt yuv420p -f %V_output%"
set "A_args= -loglevel quiet -y -f %A_output%"
set "J_args= -loglevel quiet -y -f %J_output%"


set "dir=%cd%"
for %%f in (%dir%\*) do (
    set "extension=%%~xf"
    set "input=%%f"
    set "name=%%~nf"
    set "option=0"

    rem if /I "!extension!"==".mp4"
    if not "!option!"=="3" (

    for %%V in (%V_fmt%) do (
        if /I "!extension!"=="%%V" (
            set "option=V"
        )
    )
    for %%A in (%A_fmt%) do (
        if /I "!extension!"=="%%A" (
            set "option=A"
        )
    )
    for %%J in (%J_fmt%) do (
        if /I "!extension!"=="%%J" (
            set "option=J"
        )
    )
    )
    set error=0
    if "!option!"=="V" (
        rem converting videos, you can ofc customize your ffmpeg arguments
    ffmpeg -i "!input!" %V_args% "%dir%/%output_folder%/!name!.%P_output%" || set error=1
    ) else if "!option!"=="A" (
    rem converting to audio, you can ofc customize your ffmpeg arguments
    ffmpeg -i "!input!" %A_args% "%dir%/%output_folder%/!name!.%A_output%" || set error=1
   ) else if "!option!"=="J" (
    rem converting to images, you can ofc customize your ffmpeg arguments
    ffmpeg -i "!input!" %J_args% "%dir%/%output_folder%/!name!.%J_output%" || set error=1
   )
   if not !option!==0 (
       if %DeleteOldFile%==0 (
           if !error!==0 ( 
               del "!input!"
           )
       )
   )
)
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?