使用FFprobe与MP4Box检索视频的持续时间

时间:2017-11-14 07:44:53

标签: video video-streaming ffprobe mp4box

我正在使用FFprobe和MP4Box来检索视频流信息。我意识到返回的值存在显着差异。

以下命令用于FFprobe:

$ ffprobe -v error -select_streams v:0 -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 1510579366733_9.ts
3.23334

但是,使用MP4Box检索同一文件的持续时间会返回不同的值。使用以下命令:

$ MP4Box -info 1510579366733_9.ts 2>&1 | grep Duration | awk '{print $2}'
2.826

所有我的.ts文件都有~3秒的视频片段,所以这应该只返回秒数(而不是几分钟或几小时);现在不关心这个。

这两个值中哪一个更准确?

此外,我还意识到使用MP4Box -info并不总是检索ts文件的持续时间信息,而FFprobe到目前为止我的所有.ts文件都运行良好。

示例:

$ MP4Box -info 1510579366733_10.ts
Import probing results for 1510579366733_10.ts:
File has 2 tracks
    Track 257 type: Audio (MP4A) - Program 1
    Track 258 type: Video (H264) - Program 1


$ MP4Box -info 1510579366733_9.ts
Import probing results for 1510579366733_9.ts:
File has 2 tracks
Duration: 2.826 s
    Track 257 type: Audio (MP4A) - Program 1
    Track 258 type: Video (H264) - Program 1

仅供参考1510579366733_9.ts的ffprobe(完整)视频信息如下:

ffprobe version N-86980-g62b7553 Copyright (c) 2007-2017 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: --prefix=/home/adminuser/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/adminuser/ffmpeg_build/include --extra-ldflags=-L/home/adminuser/ffmpeg_build/lib --bindir=/home/adminuser/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      55. 73.100 / 55. 73.100
  libavcodec     57.102.100 / 57.102.100
  libavformat    57. 76.100 / 57. 76.100
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 98.100 /  6. 98.100
  libswscale      4.  7.102 /  4.  7.102
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
Input #0, mpegts, from '1510579366733_9.ts':
  Duration: 00:00:03.23, start: 0.000000, bitrate: 447 kb/s
  Program 1 
    Stream #0:0[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 137 kb/s
    Stream #0:1[0x102]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 426x240 [SAR 160:213 DAR 4:3], 30 fps, 30 tbr, 90k tbn, 60 tbc

1510579366733_10.ts

ffprobe version N-86980-g62b7553 Copyright (c) 2007-2017 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: --prefix=/home/adminuser/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/adminuser/ffmpeg_build/include --extra-ldflags=-L/home/adminuser/ffmpeg_build/lib --bindir=/home/adminuser/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      55. 73.100 / 55. 73.100
  libavcodec     57.102.100 / 57.102.100
  libavformat    57. 76.100 / 57. 76.100
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 98.100 /  6. 98.100
  libswscale      4.  7.102 /  4.  7.102
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
Input #0, mpegts, from '1510579366733_10.ts':
  Duration: 00:00:01.10, start: 0.000000, bitrate: 429 kb/s
  Program 1 
    Stream #0:0[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 131 kb/s
    Stream #0:1[0x102]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 426x240 [SAR 160:213 DAR 4:3], 30 fps, 30 tbr, 90k tbn, 60 tbc

编辑以回复Mulvya's comment: 将ffprobe与stream=duration一起使用如下: -

$ ffprobe -v error -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 1510579366733_9.ts
3.178667
3.166667
3.178667
3.166667

$ ffprobe -v error -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 1510579366733_10.ts
1.066667
1.033333
1.066667
1.033333

0 个答案:

没有答案