[FFmpeg-user] How to get audio and video duration in a media file?
Wesley Wen
delbin.wen at gmail.com
Tue Apr 14 13:32:41 CEST 2015
Hi,
We want to check source file to make sure audio duration match video
duration within 1 second. So, the first thing we want to know is audio
duration and video duration individually, and I tried ffprobe cmd below.
ffprobe -show_streams /tmp/video.ts
ffprobe version git-2015-04-14-2051b40 Copyright (c) 2007-2015 the FFmpeg
developers
built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM
3.6.0svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD --enable-shared
--enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables
--enable-avresample --cc=clang --host-cflags= --host-ldflags=
--enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid
--enable-libfaac --enable-ffplay --enable-libfdk-aac --enable-libx265
--enable-nonfree --enable-vda
libavutil 54. 22.101 / 54. 22.101
libavcodec 56. 34.100 / 56. 34.100
libavformat 56. 30.100 / 56. 30.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 14.100 / 5. 14.100
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mpegts, from '/tmp/video.ts':
Duration: 00:00:49.68, start: 0.207867, bitrate: 31307 kb/s
Program 16
Stream #0:0[0xff]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002),
yuv420p(tv), 1440x1080 [SAR 4:3 DAR 16:9], 30000 kb/s, 29.97 fps, 29.97
tbr, 90k tbn, 59.94 tbc
Stream #0:1[0x100]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, s16p, 384 kb/s
[STREAM]
index=0
codec_name=mpeg2video
codec_long_name=MPEG-2 video
profile=Main
codec_type=video
codec_time_base=1001/60000
codec_tag_string=[2][0][0][0]
codec_tag=0x0002
width=1440
height=1080
coded_width=0
coded_height=0
has_b_frames=1
sample_aspect_ratio=4:3
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=6
color_range=tv
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=left
timecode=00:00:00:00
refs=1
id=0xff
r_frame_rate=30000/1001
avg_frame_rate=30000/1001
time_base=1/90000
start_pts=26634
start_time=0.295933
duration_ts=N/A
duration=N/A
bit_rate=30000000
max_bit_rate=30000000
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
[/STREAM]
[STREAM]
index=1
codec_name=mp2
codec_long_name=MP2 (MPEG audio layer 2)
profile=unknown
codec_type=audio
codec_time_base=1/48000
codec_tag_string=[3][0][0][0]
codec_tag=0x0003
sample_fmt=s16p
sample_rate=48000
channels=2
channel_layout=stereo
bits_per_sample=0
id=0x100
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/90000
start_pts=18708
start_time=0.207867
duration_ts=4471200
duration=49.680000
bit_rate=384000
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
[/STREAM]
I can only see duration, 49.68, in audio stream info but not video stream
info. Is it expected? I tried -count_packets and -count_frames but still
can't get video duration. How can I get video duration?
Later, I tried to exact audio (-c:a copy) and video (-c:v copy) separately
into two files, say video_a.ts and video_v.ts, and ran ffprobe again. This
time I can see duration fields of both files have values, but they are not
identical to 49.68; is it also expected? Here are the output of ffprobe cmd
against those two files.
ffprobe -show_streams /tmp/video_v.ts
ffprobe version git-2015-04-14-2051b40 Copyright (c) 2007-2015 the FFmpeg
developers
built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM
3.6.0svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD --enable-shared
--enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables
--enable-avresample --cc=clang --host-cflags= --host-ldflags=
--enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid
--enable-libfaac --enable-ffplay --enable-libfdk-aac --enable-libx265
--enable-nonfree --enable-vda
libavutil 54. 22.101 / 54. 22.101
libavcodec 56. 34.100 / 56. 34.100
libavformat 56. 30.100 / 56. 30.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 14.100 / 5. 14.100
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mpegts, from '/tmp/video_v.ts':
Duration: 00:00:49.62, start: 1.500100, bitrate: 32415 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002),
yuv420p(tv), 1440x1080 [SAR 4:3 DAR 16:9], 30000 kb/s, 29.97 fps, 29.97
tbr, 90k tbn, 59.94 tbc
[STREAM]
index=0
codec_name=mpeg2video
codec_long_name=MPEG-2 video
profile=Main
codec_type=video
codec_time_base=1001/60000
codec_tag_string=[2][0][0][0]
codec_tag=0x0002
width=1440
height=1080
coded_width=0
coded_height=0
has_b_frames=1
sample_aspect_ratio=4:3
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=6
color_range=tv
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=left
timecode=00:00:00:00
refs=1
id=0x100
r_frame_rate=30000/1001
avg_frame_rate=30000/1001
time_base=1/90000
start_pts=135009
start_time=1.500100
duration_ts=4465461
duration=49.616233
bit_rate=30000000
max_bit_rate=30000000
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
[/STREAM]
ffprobe -show_streams /tmp/video_a.ts
ffprobe version git-2015-04-14-2051b40 Copyright (c) 2007-2015 the FFmpeg
developers
built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM
3.6.0svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD --enable-shared
--enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables
--enable-avresample --cc=clang --host-cflags= --host-ldflags=
--enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid
--enable-libfaac --enable-ffplay --enable-libfdk-aac --enable-libx265
--enable-nonfree --enable-vda
libavutil 54. 22.101 / 54. 22.101
libavcodec 56. 34.100 / 56. 34.100
libavformat 56. 30.100 / 56. 30.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 14.100 / 5. 14.100
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mpegts, from '/tmp/video_a.ts':
Duration: 00:00:49.66, start: 1.400000, bitrate: 430 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, s16p, 384 kb/s
[STREAM]
index=0
codec_name=mp2
codec_long_name=MP2 (MPEG audio layer 2)
profile=unknown
codec_type=audio
codec_time_base=1/48000
codec_tag_string=[3][0][0][0]
codec_tag=0x0003
sample_fmt=s16p
sample_rate=48000
channels=2
channel_layout=stereo
bits_per_sample=0
id=0x100
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/90000
start_pts=126000
start_time=1.400000
duration_ts=4469040
duration=49.656000
bit_rate=384000
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
[/STREAM]
Thanks,
Wesley
More information about the ffmpeg-user
mailing list