Mercurial > libavformat.hg
changeset 1247:2f118b3e65c6 libavformat
parse mpeg frame to get pict type and closed gop flag
author | bcoudurier |
---|---|
date | Wed, 09 Aug 2006 10:48:32 +0000 |
parents | ca6fc8c8c9dc |
children | b3e31b65ba02 |
files | gxfenc.c |
diffstat | 1 files changed, 19 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/gxfenc.c Tue Aug 08 22:16:34 2006 +0000 +++ b/gxfenc.c Wed Aug 09 10:48:32 2006 +0000 @@ -40,6 +40,7 @@ int bframes; int p_per_gop; int b_per_gop; + int closed_gop; } GXFStreamContext; typedef struct GXFContext { @@ -178,9 +179,9 @@ ctx->b_per_gop = 9; /* ensure value won't take more than one char */ } size = snprintf(buffer, 1024, "Ver 1\nBr %.6f\nIpg 1\nPpi %d\nBpiop %d\n" - "Pix 0\nCf %d\nCg 1\nSl 7\nnl16 %d\nVi 1\nf1 1\n", + "Pix 0\nCf %d\nCg %d\nSl 7\nnl16 %d\nVi 1\nf1 1\n", (float)ctx->codec->bit_rate, ctx->p_per_gop, ctx->b_per_gop, - ctx->codec->pix_fmt == PIX_FMT_YUV422P ? 2 : 1, + ctx->codec->pix_fmt == PIX_FMT_YUV422P ? 2 : 1, ctx->closed_gop, ctx->codec->height / 16); put_byte(pb, 0x4F); put_byte(pb, size + 1); @@ -417,7 +418,7 @@ put_le32(pb, 2); else put_le32(pb, 1); /* default to 420 */ - put_le32(pb, 1); /* closed = 1, open = 0, unknown = 255 */ + put_le32(pb, stream->closed_gop); /* closed = 1, open = 0, unknown = 255 */ put_le32(pb, 3); /* top = 1, bottom = 2, frame = 3, unknown = 0 */ put_le32(pb, 1); /* I picture per GOP */ put_le32(pb, stream->p_per_gop); @@ -682,6 +683,18 @@ return 0; } +static int gxf_parse_mpeg_frame(GXFStreamContext *sc, const uint8_t *buf, int size) +{ + uint32_t c=-1; + int i; + for(i=0; i<size-4 && c!=0x100; i++){ + c = (c<<8) + buf[i]; + if(c == 0x1B8) /* GOP start code */ + sc->closed_gop= (buf[i+4]>>6)&1; + } + return (buf[i+1]>>3)&7; +} + static int gxf_write_media_preamble(ByteIOContext *pb, GXFContext *ctx, AVPacket *pkt, int size) { GXFStreamContext *sc = &ctx->streams[pkt->stream_index]; @@ -693,10 +706,11 @@ put_be16(pb, 0); put_be16(pb, size / 2); } else if (sc->codec->codec_id == CODEC_ID_MPEG2VIDEO) { - if (pkt->flags & PKT_FLAG_KEY) { + int frame_type = gxf_parse_mpeg_frame(sc, pkt->data, pkt->size); + if (frame_type == FF_I_TYPE) { put_byte(pb, 0x0d); sc->iframes++; - } else if (pkt->pts != pkt->dts) { + } else if (frame_type == FF_B_TYPE) { put_byte(pb, 0x0f); sc->bframes++; } else {