[FFmpeg-devel] [PATCH] libavfromat/flvenc.c: Preserve the 'amf0' data stream written by Adobe Flash Media Servers while doing a data stream copy
Benedict Endemann
bendemann at make.tv
Thu Mar 7 16:18:47 CET 2013
From: Benedict Endemann <bendemann at make.tv>
---
libavformat/flvenc.c | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 502da0f..625076a 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -225,7 +225,8 @@ static int flv_write_header(AVFormatContext *s)
return AVERROR_INVALIDDATA;
break;
case AVMEDIA_TYPE_DATA:
- if (enc->codec_id != AV_CODEC_ID_TEXT) {
+ // 'amf0' is the codec_tag used by the Adobe Flash Media Server for the 'amf0' data packets
+ if (enc->codec_id != AV_CODEC_ID_TEXT && enc->codec_tag != MKTAG('a','m','f','0')) {
av_log(s, AV_LOG_ERROR, "Data codec '%s' for stream %d is not compatible with FLV\n",
avcodec_get_name(enc->codec_id), i);
return AVERROR_INVALIDDATA;
@@ -527,18 +528,23 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
if (enc->codec_type == AVMEDIA_TYPE_DATA) {
int data_size;
int metadata_size_pos = avio_tell(pb);
- avio_w8(pb, AMF_DATA_TYPE_STRING);
- put_amf_string(pb, "onTextData");
- avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY);
- avio_wb32(pb, 2);
- put_amf_string(pb, "type");
- avio_w8(pb, AMF_DATA_TYPE_STRING);
- put_amf_string(pb, "Text");
- put_amf_string(pb, "text");
- avio_w8(pb, AMF_DATA_TYPE_STRING);
- put_amf_string(pb, pkt->data);
- put_amf_string(pb, "");
- avio_w8(pb, AMF_END_OF_OBJECT);
+ if (enc->codec_id == AV_CODEC_ID_TEXT) {
+ avio_w8(pb, AMF_DATA_TYPE_STRING);
+ put_amf_string(pb, "onTextData");
+ avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY);
+ avio_wb32(pb, 2);
+ put_amf_string(pb, "type");
+ avio_w8(pb, AMF_DATA_TYPE_STRING);
+ put_amf_string(pb, "Text");
+ put_amf_string(pb, "text");
+ avio_w8(pb, AMF_DATA_TYPE_STRING);
+ put_amf_string(pb, pkt->data);
+ put_amf_string(pb, "");
+ avio_w8(pb, AMF_END_OF_OBJECT);
+ }
+ if (enc->codec_tag == MKTAG('a','m','f','0')) {
+ avio_write(pb, pkt->data, pkt->size);
+ }
/* write total size of tag */
data_size = avio_tell(pb) - metadata_size_pos;
avio_seek(pb, metadata_size_pos - 10, SEEK_SET);
--
1.7.10.4
More information about the ffmpeg-devel
mailing list