我怎么能知道任何H264文件的时间? [英] How can i know the duration of any h264 file?

查看:306
本文介绍了我怎么能知道任何H264文件的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,其中只有H264帧那里NAL单元的形式。
所以,现在有没有什么方法,所以我可以指望该文件的时间?

I have one file in which only h264 frames are there in form of NAL unit. So now is there any method so i can count the duration of that file?

我不知道有多少帧文件的存在。
我只有文件的大小。

I dont know how many frames are there in file. I have only file size.

PS:所有我想要做的是C语言和Linux平台

PS: All i want to do is in C language and on Linux platform.

推荐答案

您的问题是毫无意义的,这就是投票为什么有人下来你。

Your question is meaningless, that's why someone down vote you.

容器文件

首先,有没有这样的事情 H264文件。可以有一个容器文件(MP4,AVI,MKV),它保存H264 EN codeD的视频。该容器格式通常还保持着数据告诉你所包含的视频时长。所以,你必须分析该文件,检查格式的文档,看看那里的持续时间被保存,然后解压缩。

First, there is no such a thing as H264 file. There can be a container file (MP4, AVI, MKV) that holds the H264 encoded video. That container format usually also holds the data telling you the contained video duration. So you have to parse that file, check the format documentation to see where the duration is saved, and then extract it.

最简单的方法是使用FFMPEG像奥古斯托建议。

Easiest way is to use FFMPEG like Augusto suggested.

NAL字节流

如果你的文件只NAL单元在NAL字节流保存此起彼伏,像有是没有办法,你可以得到的视频时长!由于H264恩$ C $光盘画面未持有定时信息。

If your file is only NAL units saved one after another, like in a NAL byte stream, there IS NO WAY that you can get the video duration! Since H264 encoded picture doesn't hold timing information.

如果是这样的话,你仍然可以做一个近似,如果你知道视频FPS ......你需要计算文件中的所有帧不包括:

If that is the case, you still can make an approximation if you know the video FPS... You need to count all frames in the file excluding:


  • 序列参数集

  • 图像参数集

  • 结束中流

  • 结束序列

  • 筛选数据

  • 接入单元分隔符

然后做数学题: NUMBER_OF_FRAMES / FPS = DUR​​ATION_IN_SECONDS

RTP流

如果你是错误的,有RTP包头每个NAL单元的上方,你可以很容易地通过检查每个RTP报头的RTP时间把视频的持续时间。在什么RTP头字节的意思是,你可以找到在这里: HTTP://www.networksorcery .COM / ENP /协议/ rtp.htm 。你想从每一个 TIMESTAMP 部分(4字节整数)。在code应该这样做:

If you are wrong and there is RTP header on top of each NAL unit, you can easily get the video duration by checking the RTP time of each RTP header. What the bytes in RTP Header mean, you can find out here: http://www.networksorcery.com/enp/protocol/rtp.htm. You want to get the TIMESTAMP part (4 bytes integer) from each one. The code should do this:

int last_timestamp = GetNextTimestamp();
double duration_in_ms = 0;

while(true)
{
    int next = GetNextTimestamp();
    duration_in_ms += (next - last_timestamp)/90000.0;
    last_timestamp = next;
}

这篇关于我怎么能知道任何H264文件的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆