Commit 30bcd6a9 authored by Joseph Wecker's avatar Joseph Wecker Committed by Michael Niedermayer

flv: Ammon's changes migrated from 0.6.0 - I believe for the android broadcaster.

parent b5d4c0e2
...@@ -98,6 +98,8 @@ enum { ...@@ -98,6 +98,8 @@ enum {
FLV_CODECID_VP6A = 5, FLV_CODECID_VP6A = 5,
FLV_CODECID_SCREEN2 = 6, FLV_CODECID_SCREEN2 = 6,
FLV_CODECID_H264 = 7, FLV_CODECID_H264 = 7,
FLV_CODECID_REALH263= 8,
FLV_CODECID_MPEG4 = 9,
}; };
enum { enum {
......
...@@ -91,6 +91,7 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_co ...@@ -91,6 +91,7 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_co
AVCodecContext *vcodec = vstream->codec; AVCodecContext *vcodec = vstream->codec;
switch(flv_codecid) { switch(flv_codecid) {
case FLV_CODECID_H263 : vcodec->codec_id = CODEC_ID_FLV1 ; break; 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_SCREEN: vcodec->codec_id = CODEC_ID_FLASHSV; break;
case FLV_CODECID_SCREEN2: vcodec->codec_id = CODEC_ID_FLASHSV2; break; case FLV_CODECID_SCREEN2: vcodec->codec_id = CODEC_ID_FLASHSV2; break;
case FLV_CODECID_VP6 : vcodec->codec_id = CODEC_ID_VP6F ; 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 ...@@ -106,6 +107,9 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_co
case FLV_CODECID_H264: case FLV_CODECID_H264:
vcodec->codec_id = CODEC_ID_H264; vcodec->codec_id = CODEC_ID_H264;
return 3; // not 4, reading packet type will consume one byte return 3; // not 4, reading packet type will consume one byte
case FLV_CODECID_MPEG4:
vcodec->codec_id = CODEC_ID_MPEG4;
return 3;
default: default:
av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flv_codecid); av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flv_codecid);
vcodec->codec_tag = flv_codecid; vcodec->codec_tag = flv_codecid;
...@@ -467,10 +471,11 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -467,10 +471,11 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
} }
if (st->codec->codec_id == CODEC_ID_AAC || 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); int type = avio_r8(s->pb);
size--; 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 int32_t cts = (avio_rb24(s->pb)+0xff800000)^0xff800000; // sign extension
pts = dts + cts; pts = dts + cts;
if (cts < 0) { // dts are wrong if (cts < 0) { // dts are wrong
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
static const AVCodecTag flv_video_codec_ids[] = { static const AVCodecTag flv_video_codec_ids[] = {
{CODEC_ID_FLV1, FLV_CODECID_H263 }, {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_FLASHSV, FLV_CODECID_SCREEN},
{CODEC_ID_FLASHSV2, FLV_CODECID_SCREEN2}, {CODEC_ID_FLASHSV2, FLV_CODECID_SCREEN2},
{CODEC_ID_VP6F, FLV_CODECID_VP6 }, {CODEC_ID_VP6F, FLV_CODECID_VP6 },
...@@ -300,7 +302,7 @@ static int flv_write_header(AVFormatContext *s) ...@@ -300,7 +302,7 @@ static int flv_write_header(AVFormatContext *s)
for (i = 0; i < s->nb_streams; i++) { for (i = 0; i < s->nb_streams; i++) {
AVCodecContext *enc = s->streams[i]->codec; 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; int64_t pos;
avio_w8(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO ? avio_w8(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO ?
FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO); FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO);
...@@ -342,7 +344,7 @@ static int flv_write_trailer(AVFormatContext *s) ...@@ -342,7 +344,7 @@ static int flv_write_trailer(AVFormatContext *s)
for (i = 0; i < s->nb_streams; i++) { for (i = 0; i < s->nb_streams; i++) {
AVCodecContext *enc = s->streams[i]->codec; AVCodecContext *enc = s->streams[i]->codec;
if (enc->codec_type == AVMEDIA_TYPE_VIDEO && 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); put_avc_eos_tag(pb, flv->last_video_ts);
} }
} }
...@@ -374,7 +376,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -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 || if(enc->codec_id == CODEC_ID_VP6 || enc->codec_id == CODEC_ID_VP6F ||
enc->codec_id == CODEC_ID_AAC) enc->codec_id == CODEC_ID_AAC)
flags_size= 2; 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; flags_size= 5;
else else
flags_size= 1; flags_size= 1;
...@@ -398,7 +400,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -398,7 +400,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
avio_w8(pb, FLV_TAG_TYPE_AUDIO); 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 */ /* check if extradata looks like mp4 formated */
if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) { if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
if (ff_avc_parse_nal_units_buf(pkt->data, &data, &size) < 0) 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) ...@@ -428,7 +430,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
avio_w8(pb, enc->extradata_size ? enc->extradata[0] : 0); avio_w8(pb, enc->extradata_size ? enc->extradata[0] : 0);
else if (enc->codec_id == CODEC_ID_AAC) else if (enc->codec_id == CODEC_ID_AAC)
avio_w8(pb,1); // AAC raw 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_w8(pb,1); // AVC NALU
avio_wb24(pb,pkt->pts - pkt->dts); avio_wb24(pb,pkt->pts - pkt->dts);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment