簡體   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