LoginSignup
46
37

More than 5 years have passed since last update.

ffmpeg 動画や音声の時間を取得する

Last updated at Posted at 2015-06-24

ffprobeを使う

もっとも簡単な方法は、下記のようにすることです。

ffprobe hoge.mp4

表示される結果に、下記のような情報が入っています。

Duration: 00:00:10.12

Copyrightとか、不要な情報を表示させたくない場合、-hide_bannerオプションを使うとよいでしょう。それでもファイルのinput情報等は表示されてしまいますが。

ffprobe -hide_banner hoge.mp4

-show_entries オプションを使う

下記のように使います。

ffprobe hoge.mp4  -hide_banner -show_entries format=duration

結果

・・・いろいろな情報が表示される・・・
[FORMAT]
duration=10.1245
[/FORMAT]

こんなふうに[FORMAT]タグに囲まれて表示されます。
また、こちらのほうがより細かい時間(小数点第3位以下)を取得することができます。
これなら出力結果をちょっと整形すれば、簡単に取得できそうです。

また、下記のようにすると、-show_entriesで取得できる他の情報を表示できます。

ffprobe hoge.mp4 -hide_banner -show_entries format

結果

[FORMAT]
filename=.\hoge.mp4
nb_streams=1
nb_programs=0
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=0.000000
duration=10.1245
size=7979232
bit_rate=1201329
probe_score=100
TAG:major_brand=isom
TAG:minor_version=512
TAG:compatible_brands=isomiso2avc1mp41
TAG:encoder=Lavf55.0.100
[/FORMAT]
46
37
2

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
46
37