diff --git a/libavformat/flv.h b/libavformat/flv.h index d0731c80a3..bca17fc643 100644 --- a/libavformat/flv.h +++ b/libavformat/flv.h @@ -98,6 +98,8 @@ enum { FLV_CODECID_VP6A = 5, FLV_CODECID_SCREEN2 = 6, FLV_CODECID_H264 = 7, + FLV_CODECID_REALH263= 8, + FLV_CODECID_MPEG4 = 9, }; enum { diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index d3e3d77fce..e861941cf0 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -91,6 +91,7 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_co AVCodecContext *vcodec = vstream->codec; switch(flv_codecid) { case FLV_CODECID_H263 : vcodec->codec_id = CODEC_ID_FLV1 ; break; + case FLV_CODECID_REALH263: vcodec->codec_id = CODEC_ID_H263 ; break; // Really mean it this time case FLV_CODECID_SCREEN: vcodec->codec_id = CODEC_ID_FLASHSV; break; case FLV_CODECID_SCREEN2: vcodec->codec_id = CODEC_ID_FLASHSV2; break; case FLV_CODECID_VP6 : vcodec->codec_id = CODEC_ID_VP6F ; @@ -106,6 +107,9 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_co case FLV_CODECID_H264: vcodec->codec_id = CODEC_ID_H264; return 3; // not 4, reading packet type will consume one byte + case FLV_CODECID_MPEG4: + vcodec->codec_id = CODEC_ID_MPEG4; + return 3; default: av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flv_codecid); vcodec->codec_tag = flv_codecid; @@ -467,10 +471,11 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) } if (st->codec->codec_id == CODEC_ID_AAC || - st->codec->codec_id == CODEC_ID_H264) { + st->codec->codec_id == CODEC_ID_H264 || + st->codec->codec_id == CODEC_ID_MPEG4) { int type = avio_r8(s->pb); size--; - if (st->codec->codec_id == CODEC_ID_H264) { + if (st->codec->codec_id == CODEC_ID_H264 || st->codec->codec_id == CODEC_ID_MPEG4) { int32_t cts = (avio_rb24(s->pb)+0xff800000)^0xff800000; // sign extension pts = dts + cts; if (cts < 0) { // dts are wrong diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index 5bf9809358..d790a12288 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -33,6 +33,8 @@ static const AVCodecTag flv_video_codec_ids[] = { {CODEC_ID_FLV1, FLV_CODECID_H263 }, + {CODEC_ID_H263, FLV_CODECID_REALH263}, + {CODEC_ID_MPEG4, FLV_CODECID_MPEG4 }, {CODEC_ID_FLASHSV, FLV_CODECID_SCREEN}, {CODEC_ID_FLASHSV2, FLV_CODECID_SCREEN2}, {CODEC_ID_VP6F, FLV_CODECID_VP6 }, @@ -300,7 +302,7 @@ static int flv_write_header(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVCodecContext *enc = s->streams[i]->codec; - if (enc->codec_id == CODEC_ID_AAC || enc->codec_id == CODEC_ID_H264) { + if (enc->codec_id == CODEC_ID_AAC || enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) { int64_t pos; avio_w8(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO ? FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO); @@ -342,7 +344,7 @@ static int flv_write_trailer(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVCodecContext *enc = s->streams[i]->codec; if (enc->codec_type == AVMEDIA_TYPE_VIDEO && - enc->codec_id == CODEC_ID_H264) { + (enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4)) { put_avc_eos_tag(pb, flv->last_video_ts); } } @@ -374,7 +376,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) if(enc->codec_id == CODEC_ID_VP6 || enc->codec_id == CODEC_ID_VP6F || enc->codec_id == CODEC_ID_AAC) flags_size= 2; - else if(enc->codec_id == CODEC_ID_H264) + else if(enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) flags_size= 5; else flags_size= 1; @@ -398,7 +400,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) avio_w8(pb, FLV_TAG_TYPE_AUDIO); } - if (enc->codec_id == CODEC_ID_H264) { + if (enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) { /* check if extradata looks like mp4 formated */ if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) { if (ff_avc_parse_nal_units_buf(pkt->data, &data, &size) < 0) @@ -428,7 +430,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) avio_w8(pb, enc->extradata_size ? enc->extradata[0] : 0); else if (enc->codec_id == CODEC_ID_AAC) avio_w8(pb,1); // AAC raw - else if (enc->codec_id == CODEC_ID_H264) { + else if (enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) { avio_w8(pb,1); // AVC NALU avio_wb24(pb,pkt->pts - pkt->dts); }