H264到PES打包

时间:2014-10-24 12:10:45

标签: c++ ffmpeg h.264 mpeg2-ts

我有Ti DaVinci h264编码器,我想将其输出帧打包到PES。该流采用附件B格式。 我接过了ffmpeg的pes标题作者并做了类似的事情:

void MediaPacket::writePesHeader(std::vector< uint8_t >& buffer)
{
    int header_len, flags, len, val;
    uint8_t *q = buffer.data();

    *q++ = 0x00;
    *q++ = 0x00;
    *q++ = 0x01;
    *q++ = 0xe0;

    header_len = 0;
    flags      = 0;
    if (pts != UNKNOWN) {
        header_len += 5;
        flags      |= 0x80;
    }
    if (dts != UNKNOWN && pts != UNKNOWN && dts != pts) {
        header_len += 5;
        flags      |= 0x40;
    }

    len = 0;
    *q++ = len >> 8;
    *q++ = len;
    val  = 0x80;

    *q++ = val;
    *q++ = flags;
    *q++ = header_len;
    if (pts != UNKNOWN) {
        write_pts(q, flags >> 6, pts);
        q += 5;
    }
    if (dts != UNKNOWN && pts != UNKNOWN && dts != pts) {
        write_pts(q, 1, dts);
        q += 5;
    }
    buffer.resize(q-buffer.data());
}

static void write_pts(uint8_t *q, int fourbits, int64_t pts)
{
    int val;

    val  = fourbits << 4 | (((pts >> 30) & 0x07) << 1) | 1;
    *q++ = val;
    val  = (((pts >> 15) & 0x7fff) << 1) | 1;
    *q++ = val >> 8;
    *q++ = val;
    val  = (((pts) & 0x7fff) << 1) | 1;
    *q++ = val >> 8;
    *q++ = val;
}

没有标题的编码器输出可以很好地使用Totem播放器和avplay播放,但是有一个错误&#34;找不到编解码器参数&#34;当标题出现时。 我做错了什么?

0 个答案:

没有答案