如何通过 RTP 传输静态 H.264 文件

发布于 2025-01-16 02:04:15 字数 395 浏览 7 评论 0原文

我有一个名为 video.h264 的文件和我的 RTSP 服务器代码。我想根据 PLAY 请求将此文件传输到视频播放器(例如 VLC 或 FFplay)。问题是我不知道应该以什么时间间隔传输 NAL 单元。

如果我知道 video.h264 的 FPS,那么我的逻辑是我应该每秒传输 FPS 访问单元 (AU),因为每个 AU 在解码后都会生成一个视频帧。但是我如何确定 AU 从哪里开始呢? NAL 头结构中可能有一些关于它们的指示?

或者我应该在没有正确计时的情况下在 video.h264 中一次性传输所有 NAL 单元,因为媒体播放器仍然可以通过 RTP 的时间戳保留原始计时> 现场还是通过其他方式?

I have a file named video.h264 and my RTSP server code. I want to transmit this file to a video player (such as VLC or FFplay) upon the PLAY request. The problem is that I don't know at what time intervals I should transmit NAL units.

If I know the FPS of video.h264, then my logic is that I should transmit FPS Access Units (AU) per second, given that each AU results in one video frame after decoding. But then how do I determine where AUs start? Probably there is some indication of them in the NAL header structure?

Or should I just transmit all the NAL units at once in video.h264 one-by-one without proper timing, since a media player can nonetheless retain the original timing through RTP's timestamp field or by some other means?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金橙橙 2025-01-23 02:04:15

因此,我立即传输了整个 video.h264 文件,它对我有用。此外,这使我能够快速测试我的代码。

对于任何想知道如何计算 video.h264 的 RTP 时间戳的人,方法如下:每当遇到新的访问单元 (AU) 时,您就将时间戳增加 90 kHz / FPS。要测试 AU,最简单的方法是检查每个 NAL 单元的类型以获取访问单元定界符 (AUD),其值必须为 0x09。但是,并非所有有效的 H.264 文件都有 AUD。要获取包含 AUD 的 H.264 文件,您可以使用 FFmpeg:(

$ ffmpeg -i http://docs.evostream.com/sample_content/assets/bun33s.mp4 \
    -vcodec h264 -x264opts aud=1 video.h264

使用 --enable-libx264 --enable-gpl 编译。)

So I just transmitted the whole video.h264 file at once and it worked for me. Additionally, this allowed me to test my code in a quick way.

For anyone wondering how to compute RTP timestamps for video.h264, here's how: whenever you encounter a new Access Unit (AU), you increment your timestamp by 90 kHz / FPS. To test for an AU, the simplest way is to check a type of each NAL unit for Access Unit Delimiter (AUD), which must be of value 0x09. However, not all valid H.264 files have AUDs. To obtain an H.264 file with AUDs, you can employ FFmpeg:

$ ffmpeg -i http://docs.evostream.com/sample_content/assets/bun33s.mp4 \
    -vcodec h264 -x264opts aud=1 video.h264

(Compiled with --enable-libx264 --enable-gpl.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文