繁体   English   中英

如何使用avconv / ffmpeg获取H264文件的持续时间/比特率

[英]How to get the duration/bitrate of a H264 file with avconv/ffmpeg

执行avprobe test.h264输出

Input #0, h264, from 'test.h264':
  Duration: N/A, bitrate: N/A
    Stream #0.0: Video: h264 (High), yuv420p, 720x480, 25 fps, 25 tbn, 50 tbc

执行file test.h264输出

test.h264: JVT NAL sequence, H.264 video @ L 30

请注意,文件没有损坏或损坏,我可以在VLC上播放它没有任何问题。

有没有办法从原始的H264文件中获取持续时间和比特率? 我在某处读到如果我首先解码文件可能是可能的,但我不确定如何做到这一点。

编辑#1

我是用一个名为picamera的Python库创建H264文件的picamera

编辑#2

运行avconv -i test.h264 -f null -时的控制台输出avconv -i test.h264 -f null -

avconv version 11.7-6:11.7-1~deb8u1+rpi1, Copyright (c) 2000-2016 the Libav developers
  built on Jun 17 2016 02:13:49 with gcc 4.9.2 (Raspbian 4.9.2-10)
[h264 @ 0x1bcc200] Estimating duration from bitrate, this may be inaccurate
Input #0, h264, from 'test.h264':
  Duration: N/A, bitrate: N/A
    Stream #0.0: Video: h264 (High), yuv420p, 720x480, 25 fps, 25 tbn
 Output #0, null, to 'pipe:':
  Metadata:
    encoder         : Lavf56.1.0
    Stream #0.0: Video: rawvideo, yuv420p, 720x480, q=2-31, 200 kb/s, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.1.0 rawvideo
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> rawvideo (native))
Press ctrl-c to stop encoding
frame=  208 fps= 68 q=0.0 Lsize=       0kB time=10000000000.00 bitrate=   0.0kbits/s
video:13kB audio:0kB other streams:0kB global headers:0kB muxing overhead: unknown

您可以将其复制到容器然后检查

ffmpeg -i test.h264 -c copy test.mp4

ffprobe test.mp4

您还可以计算H264中的帧并按帧速率进行分频

ffprobe test.h264 -count_frames -show_entries stream=nb_read_frames,avg_frame_rate,r_frame_rate

持续时间= nb_read_frames / avg_frame_rate

持续时间为N / A的原因是annexb(原始)H.264文件通常没有存储在文件中的时间戳或帧速率信息。 帧速率可以选择存储在PPS的VUI中,但是这个文件显然没有,所以它只知道是framecount(通过解析整个文件),而不是与时间戳相关的任何东西。

一种方法是使用ffmpeg解码文件以获取持续时间:

ffmpeg -framerate 24 -i input.h264 -f null -

然后在控制台输出的倒数第二行中查看time=持续时间。 例如,5秒输入:

frame=  125 fps=0.0 q=-0.0 Lsize=N/A time=00:00:05.00 bitrate=N/A speed= 189x

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM