[Ffmpeg-devel] [PATCH] flv muxer metadata

Allan Hsu allan
Thu Dec 7 05:00:58 CET 2006


Attached is a patch for the FLV muxer to supply more complete metadata
in the onMetaData header.

	-Allan
-- 
Allan Hsu <allan at counterpop dot net>
1E64 E20F 34D9 CBA7 1300 1457 AC37 CBBB 0E92 C779
-------------- next part --------------
Index: libavformat/flvenc.c
===================================================================
--- libavformat/flvenc.c	(revision 7231)
+++ libavformat/flvenc.c	(working copy)
@@ -99,11 +99,16 @@
     put_be64(pb, av_dbl2int(d));
 }
 
+static void put_amf_bool(ByteIOContext *pb, int b) {
+    put_byte(pb, AMF_DATA_TYPE_BOOL);
+    put_byte(pb, (b ? AMF_BOOL_TRUE : AMF_BOOL_FALSE));
+}
+
 static int flv_write_header(AVFormatContext *s)
 {
     ByteIOContext *pb = &s->pb;
     FLVContext *flv = s->priv_data;
-    int i, width, height, samplerate;
+    int i, width, height, samplerate, samplesize, channels, audiocodecid;
     double framerate = 0.0;
     int metadata_size_pos, data_size;
 
@@ -130,6 +135,25 @@
         } else {
             flv->hasAudio=1;
             samplerate = enc->sample_rate;
+            samplesize = enc->bits_per_sample;
+            channels = enc->channels;
+
+            switch(enc->codec_id) {
+                case    CODEC_ID_PCM_S8:
+                case CODEC_ID_PCM_S16BE:
+                    audiocodecid = FLV_CODECID_PCM_BE >> FLV_AUDIO_CODECID_OFFSET; break;
+                case CODEC_ID_ADPCM_SWF:
+                    audiocodecid = FLV_CODECID_ADPCM  >> FLV_AUDIO_CODECID_OFFSET; break;
+                case       CODEC_ID_MP3:
+                    audiocodecid = FLV_CODECID_MP3    >> FLV_AUDIO_CODECID_OFFSET;
+                    samplesize = 16;
+                    break;
+                case CODEC_ID_PCM_S16LE:
+                    audiocodecid = FLV_CODECID_PCM_LE >> FLV_AUDIO_CODECID_OFFSET; break;
+                default:
+                    //unsupported format, but the get_audio_flags check below will catch it.
+                    break;
+            }
         }
         av_set_pts_info(s->streams[i], 24, 1, 1000); /* 24 bit pts in ms */
         if(enc->codec_tag == 5){
@@ -159,7 +183,7 @@
 
     /* mixed array (hash) with size and string/type/data tuples */
     put_byte(pb, AMF_DATA_TYPE_MIXEDARRAY);
-    put_be32(pb, 4*flv->hasVideo + flv->hasAudio + 2); // +2 for duration and file size
+    put_be32(pb, 5*flv->hasVideo + 4*flv->hasAudio + 2); // +2 for duration and file size
 
     put_amf_string(pb, "duration");
     flv->duration_offset= url_ftell(pb);
@@ -177,11 +201,23 @@
 
         put_amf_string(pb, "framerate");
         put_amf_double(pb, framerate);
+
+        put_amf_string(pb, "videocodecid");
+        put_amf_double(pb, FLV_CODECID_H263);
     }
 
     if(flv->hasAudio){
         put_amf_string(pb, "audiosamplerate");
         put_amf_double(pb, samplerate);
+
+        put_amf_string(pb, "audiosamplesize");
+        put_amf_double(pb, samplesize);
+
+        put_amf_string(pb, "stereo");
+        put_amf_bool(pb, (channels == 2));
+
+        put_amf_string(pb, "audiocodecid");
+        put_amf_double(pb, audiocodecid);
     }
 
     put_amf_string(pb, "filesize");
Index: libavformat/flv.h
===================================================================
--- libavformat/flv.h	(revision 7231)
+++ libavformat/flv.h	(working copy)
@@ -91,6 +91,11 @@
     FLV_FRAME_DISP_INTER = 3 << FLV_VIDEO_FRAMETYPE_OFFSET,
 };
 
+enum {
+    AMF_BOOL_FALSE  = 0x00,
+    AMF_BOOL_TRUE   = 0x01
+};
+
 typedef enum {
     AMF_DATA_TYPE_NUMBER      = 0x00,
     AMF_DATA_TYPE_BOOL        = 0x01,



More information about the ffmpeg-devel mailing list