小编Jac*_*ord的帖子

流式RTP/RTSP:同步/时间戳问题

我在通过RTSP传输H.264视频时遇到了一些麻烦.目标是将摄像机图像直播到RTSP客户端(理想情况下是最终的浏览器插件).到目前为止,这个问题一直很顺利,除了一个问题:视频会在启动时滞后,每隔几秒就会断断续续,并且延迟时间约为4秒.这是不好的.

我们的设置是使用x264(w/zerolatency和ultrafast)进行编码,并使用ffmpeg 0.6.5的libavformat打包到RTSP/RTP中.为了测试,我在连接到RTSP服务器时接收带有gst-launch的GStreamer管道的流.但是,当我只使用RTP从另一个GStreamer实例直接流式传输时,我已经能够重现相同的问题.

发送机:

gst-launch videotestsrc ! x264enc tune=zerolatency ! rtph264pay ! udpsink host=10.89.6.3
Run Code Online (Sandbox Code Playgroud)

收货机:

gst-launch udpsrc ! application/x-rtp,payload=96 ! rtph264depay ! decodebin ! xvimagesink
Run Code Online (Sandbox Code Playgroud)

您也可以在同一台计算机上运行这两者,只需将主机更改为127.0.0.1即可.在接收端,您应该注意到口吃和通常效果不佳的视频,以及控制台上的重复警告:

WARNING: from element /GstPipeline:pipeline0/GstXvImageSink:xvimagesink0: A lot of buffers are being dropped.
Additional debug info:
gstbasesink.c(2875): gst_base_sink_is_too_late (): /GstPipeline:pipeline0/GstXvImageSink:xvimagesink0:
There may be a timestamping problem, or this computer is too slow.
Run Code Online (Sandbox Code Playgroud)

我在互联网上看到的一个常见建议的"修复"是sync=false与xvimagesink 一起使用:

gst-launch udpsrc ! application/x-rtp,payload=96 ! rtph264depay ! decodebin ! xvimagesink sync=false
Run Code Online (Sandbox Code Playgroud)

即使使用我们的相机软件进行测试,视频也会以接近零的延迟播放.这对于测试非常有用,但对于部署并不是很有用,因为它不适用于Totem,VLC或其浏览器插件嵌入.

我想尝试从源头解决问题; 我怀疑x264或者RTP有效载荷在H.264流上缺少某种时间戳信息.有什么办法来修改 GST管道,这样我就不会需要使用 …

video streaming rtp gstreamer h.264

13
推荐指数
2
解决办法
2万
查看次数

使用libavformat通过RTP传输H.264

过去一周我一直在尝试通过RTP实现H.264流,使用x264作为编码器,使用libavformat来打包和发送流.问题是,据我所知,它无法正常工作.

现在我只是编码随机数据(x264_picture_alloc)并从libx264中提取NAL帧.这很简单:

x264_picture_t pic_out;
x264_nal_t* nals;
int num_nals;
int frame_size = x264_encoder_encode(this->encoder, &nals, &num_nals, this->pic_in, &pic_out);

if (frame_size <= 0)
{
    return frame_size;
}

// push NALs into the queue
for (int i = 0; i < num_nals; i++)
{
    // create a NAL storage unit
    NAL nal;
    nal.size = nals[i].i_payload;
    nal.payload = new uint8_t[nal.size];
    memcpy(nal.payload, nals[i].p_payload, nal.size);

    // push the storage into the NAL queue
    {
        // lock and push the NAL to the queue
        boost::mutex::scoped_lock lock(this->nal_lock);
        this->nal_queue.push(nal);
    } …
Run Code Online (Sandbox Code Playgroud)

c++ rtp h.264 libx264 libavformat

10
推荐指数
1
解决办法
1万
查看次数

无法将libavformat/ffmpeg与x264和RTP同步

我一直在研究一些流媒体软件,它使用H.264通过网络从各种摄像机和流中获取实时信息.为了实现这一点,我直接使用x264编码器(带有"zerolatency"预设)并提供NAL,因为它们可用于libavformat以打包到RTP(最终是RTSP).理想情况下,此应用程序应尽可能实时.在大多数情况下,这一直运作良好.

然而不幸的是,存在某种同步问题:客户端上的任何视频回放似乎都显示了一些平滑帧,然后是短暂停顿,然后是更多帧; 重复.此外,似乎有大约4秒的延迟.我尝试过的每一个视频播放器都会出现这种情况:Totem,VLC和基本的gstreamer管道.

我把它煮成了一个小小的测试用例:

#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <x264.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>

#define WIDTH       640
#define HEIGHT      480
#define FPS         30
#define BITRATE     400000
#define RTP_ADDRESS "127.0.0.1"
#define RTP_PORT    49990

struct AVFormatContext* avctx;
struct x264_t* encoder;
struct SwsContext* imgctx;

uint8_t test = 0x80;


void create_sample_picture(x264_picture_t* picture)
{
    // create a frame to store in
    x264_picture_alloc(picture, X264_CSP_I420, WIDTH, HEIGHT);

    // fake image generation
    // disregard how wrong this is; just writing a quick test
    int strides = …
Run Code Online (Sandbox Code Playgroud)

c ffmpeg rtp x264 libavformat

8
推荐指数
1
解决办法
5264
查看次数

标签 统计

rtp ×3

h.264 ×2

libavformat ×2

c ×1

c++ ×1

ffmpeg ×1

gstreamer ×1

libx264 ×1

streaming ×1

video ×1

x264 ×1