動画や音声、画像ファイルを調べるのに ffmpeg で表示される以上のことを調べるときに使う ffprobe の使い方。ログのフォーマット指定ができるので json、xml、iniからパースすれば正規表現で無理に取る必要はない。
ffprobe では-vf、-af、-filter_complexなどが使えないので lavfi デバイスで読み込み、そこからフィルタを使う。よって映像は rawvideo、音声は pcm_f32le になり元データとは異なるのに注意。デコーダの指定もできないので一部のピクセルフォーマット、具体的には VP9 の YUVA420 をデコードできない。
VP9(libvpx-vp9)のエンコード設定について | アルファチャンネル付き動画を読み込む
ffmpeg 5.0からcsv出力が直った。
ffprobe: add missing separator when printing side data in compact output · FFmpeg/FFmpeg@131dbb9
ffmpeg 5.1から出力指定の-oが追加され、無指定は今までと同じ標準出力、-oでファイル出力できるようになった。ファイル形式は拡張子から判断しないので-ofで指定する。
ffprobe: add -o option · FFmpeg/FFmpeg@ff07492
基本コマンド
オプションを何も付けなければ ffmpeg と同じ表示になる。
ffprobe -i input
コンテナストリームの情報を表示する。これが基本の出力内容になりこれから必要なものだけを出力したり、パケット単位で出力したりもできる。
ffprobe -i input -show_streams
ffmpeg などで表示される configure オプションやライブラリのバージョンは-hide_bannerで非表示にできる。
ffprobe -hide_banner -i input -show_streams
ffprobe の内容だけが必要なら-v errorを付ける。
ffprobe -v error -i input -show_streams
JSON に出力する。
ffprobe -v error -i input -show_streams -of json > output.json
CSV に出力する。目視なら CSV 出力が読みやすい。
ffprobe -v error -i input -show_streams -of csv > output.csv
解像度を表示する。カンマ区切りで複数指定できる。
ffprobe -v error -i input -select_streams v:0 -show_entries stream=width,height
フレームレート、映像の開始時間、映像の時間を表示する。
ffprobe -v error -i input -select_streams v:0 -show_entries stream=r_frame_rate,start_time,duration
pts_time,pict_typeだけを表示する。
ffprobe -v error -i input -select_streams v:0 -show_frames -show_entries frame=pts_time,pict_type -of csv=p=0
Iフレームの時間だけ表示する。
ffprobe -v error -i input -select_streams v:0 -show_frames -show_entries frame=pts_time,pict_type -of csv=print_section=0 | awk -F',' '/I/ {print $1}'
Iフレームのフレーム番号(0開始)だけ表示する。
ffprobe -v error -i input -select_streams v:0 -show_entries frame=pict_type -of flat | grep -e \\\"I\\\" - |sed -e "s/[^0-9]//g"
キーフレームの時間だけ表示する。
ffprobe -v error -i input -select_streams v:0 -show_entries packet=pts_time,flags -of csv=print_section=0 | awk -F',' '/K/ {print $1}'
Extracting I frames time stamps : ffmpeg
How to get time stamp of closest keyframe before a given timestamp with FFmpeg? – Super User
パケットのKのフレーム番号(0開始)だけ表示する。IDRフレームでないIフレームも含まれる。
ffprobe -v error -i input -select_streams v:0 -show_entries packet=flags -of flat | grep -e K - | sed -e "s/[^0-9]//g"
IDRなキーフレーム番号(0開始)だけ表示する。
ffprobe -v error -i input -select_streams v:0 -show_frames -show_entries frame=key_frame -of flat | grep key_frame=1 - | awk -F '.' '{print $3}'
再生順に表示されるピクチャータイプをテキストに出力する。
ffprobe -v error -i input -show_frames -show_entries frame=pict_type -of csv=print_section=0 > input-pict_type.txt
FFmpegの使用方法より。
- I:Iフレーム (Intra coded frame)
- P:Pフレーム (Predicted frame)
- B:Bフレーム (Bidirectional predicted picture)
- S:(switch frame)
- SI:(switching I frame)
- SP:(switching P frame)
- BI:(special intra frame)
Video compression picture types – Wikipedia
x264 – Get frame type for specific frame using ffmpeg – Stack Overflow
nb_read_packets だけを表示する。1スタートの総パケット数なのでそのままの意味になる。
ffprobe -v error -i input -select_streams v:0 -show_entries stream=nb_read_packets -count_packets -of csv=p=0
メタデータを元としたnb_framesだけを表示する。1スタートの総フレーム数なのでそのままの意味になる。処理が速い。
ffprobe -v error -i input -select_streams v:0 -show_entries stream=nb_frames -of csv=p=0
デコードしたすべてのフレーム数nb_read_framesも表示する。
ffprobe -v error -i input -select_streams v:0 -show_entries stream=nb_frames,nb_read_frames -count_frames -of default=noprint_wrappers=1:nokey=0
ffprobe – FFMPEG nb_frames vs nb_read_frames – Stack Overflow
-skip_frame nokeyを使ってキーフレームの時間だけ表示する。
ffprobe -v error -i input -select_streams v:0 -skip_frame nokey -show_entries frame=pts_time -of csv=print_section=0
-tで指定して特定時間時点のフレーム数を取得する。
ffmpeg -t 10 -i input -nostats -c:v copy -f null - 2>&1 | grep -Po "frame= *\K[0-9]*?(?= )"
video – How to get frame number given a timestamp using ffmpeg – Stack Overflow
字幕コーデックを表示する。
ffprobe -v error -i input -select_streams s -show_entries stream=index,disposition=forced,stream_tags=language,codec_name -of csv=nk=1:p=0
再生時に強制表示しているのを調べるにはDISPOSITION:default=1を確認する。
ffprobe -v error -i input -select_streams s -show_entries stream
Print subtitles type with ffprobe : ffmpeg
フォーマット(コンテナ)の時間。-sexagesimalをつければ読みやすくなる。
ffprobe -v error -i input -show_entries format=duration -of default=noprint_wrappers=1:nokey=1
ビデオストリームの時間だけを表示する。
ffprobe -v error -i input -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1
ffmpeg – Difference between duration from mvhd box and ffprobe for mp4 file – Stack Overflow
映像のtimebaseを表示する。
ffprobe -v error -i input -select_streams v:0 -show_entries stream=time_base -of csv=print_section=0
デコードできるフレーム数、時間を調べるにはログの最後の行(frame=34047 fps=3280 q=-0.0 Lsize=N/A time=00:23:40.05 bitrate=N/A speed= 137x)を見る。
ffmpeg -i input -f null -
パケット毎のpts_time,dts_time,size,flags(フレームタイプ, K_ がキーフレーム)を開始から10秒間 log.txt に出力する。
ffprobe -v error -i input -select_streams v:0 -show_entries packet=pts_time,dts_time,size,flags -read_intervals "%+10" > log.txt
トラック別の音声のチャンネルレイアウトと言語を調べる。
ffprobe -v error -i input -select_streams a -show_entries stream=channel_layout:stream_tags=language -of json > log.json
pts_timeとsignalstats
フィルタから YMIN を開始から1秒間 YMIN.txt に出力する。
ffprobe -v error -f lavfi -i movie=input.mp4,signalstats -show_entries packet=pts_time -show_entries packet_tags=lavfi.signalstats.YMIN -read_intervals "%1" > YMIN.txt
ffprobe -v error -f lavfi -i movie=input.mp4,signalstats -show_entries packet=pts_time -show_entries packet_tags=lavfi.signalstats.YMIN -read_intervals "%1" -of csv > YMIN.csv
YUV のデータを数値で表示する signalstats
複数のpacket_tags=lavfi.XXXをつなげるにはカンマ,でつなげる。
ffprobe -v error -f lavfi -i movie=input.mp4,signalstats -show_entries packet=pts_time -show_entries packet_tags=lavfi.signalstats.YMIN,lavfi.signalstats.YMAX -read_intervals "%1" > YMIN-YMAX.txt
ffprobe -v error -f lavfi -i movie=input.mp4,signalstats -show_entries packet=pts_time -show_entries packet_tags=lavfi.signalstats.YMIN,lavfi.signalstats.YMAX -read_intervals "%1" -of csv > YMIN-YMAX.csv
packet_tagsの数値をフィルタするにはmetadata、ametadat
フィルタを使う。
ffprobe -v error -f lavfi -i movie=input.mp4,scdet,metadata=select:key=lavfi.scd.score:value=10:function=greater -select_streams v:0 -show_entries packet=pts_time -show_entries packet_tags=lavfi.scd.score -of csv > output.csv
すべてのメタデータを一度に出力するには-show_entries frame=pkt_pts_time:frame_tagsをつける。
ffprobe -v error -f lavfi -i movie=input.mp4,signalstats -select_streams v:0 -show_entries frame=pkt_pts_time:frame_tags -read_intervals "%1" > signalstats.txt
メタデータをコンソールに表示する metadata, ametadata
lavfi デバイスで読み込む方法は movie, amovie 入力の設定内容を参照。
packet_tagsで使えるフィルタは meta | ニコラボで検索。
16進数 ASCII のテキスト(show_data.txt)にリダイレクトする。コンソールにそのまま表示するとデータ量が多くおそらく固まるので必ずリダイレクトさせる。
ffprobe -v error -i img.png -show_packets -show_data > show_data.txt
チャプターをXML形式で出力する。
ffprobe -i input -show_chapters -of xml > chapters.xml
複数ファイルの処理に便利な右クリックメニューの「送る」に登録する。エクスプローラで「shell:sendto」を開いてバットファイルを置く。
for %%f in (%*) do (
echo %%f
ffprobe -v error -f lavfi -i movie=%%~xnf,scdet,metadata=select:key=lavfi.scd.score:value=10:function=greater -select_streams v:0 -show_entries packet=pts_time -show_entries packet_tags=lavfi.scd.score -of csv > %%~xnf.csv
)
レジストリを書き換えて右クリックのメニューに登録する。
windows – FFmpeg converting by a context menu entry – Super User
kachurovskiy/VideoContextMenu: Common ffmpeg actions in Windows Explorer context menu
ffmpegから標準入力する。適宜コピーするストリームを指定する。
ffmpeg -ss 10 -i input -t 10 -c copy -an -sn -dn -f nut - | ffprobe -f lavfi -i movie=pipe\\:0,idet -show_entries packet_tags=lavfi.idet.multiple.current_frame -of json > foo.json
HDRに関わるCLL、MDCVのメタデータを出力する。
ffprobe -v error -i input -show_frames -show_entries frame=side_data_list -read_intervals %+#1 -of json
公式ドキュメント : ffprobe Documentation
公式のWiki : FFprobeTips – FFmpeg
Continue reading “ffprobe の使い方”