[Ffmpeg-cvslog] r5779 - in trunk: libavformat/flvenc.c tests/ffmpeg.regression.ref tests/libav.regression.ref tests/rotozoom.regression.ref

michael subversion
Mon Jul 17 23:51:21 CEST 2006


Author: michael
Date: Mon Jul 17 23:51:21 2006
New Revision: 5779

Modified:
   trunk/libavformat/flvenc.c
   trunk/tests/ffmpeg.regression.ref
   trunk/tests/libav.regression.ref
   trunk/tests/rotozoom.regression.ref

Log:
add header info to flv format based on a patch by (Philipp Klaus >ffmpegdevel ad pylonsoft mot ch )


Modified: trunk/libavformat/flvenc.c
==============================================================================
--- trunk/libavformat/flvenc.c	(original)
+++ trunk/libavformat/flvenc.c	Mon Jul 17 23:51:21 2006
@@ -79,11 +79,34 @@
     return flags;
 }
 
+#define AMF_DOUBLE  0
+#define AMF_BOOLEAN 1
+#define AMF_STRING  2
+#define AMF_OBJECT  3
+#define AMF_MIXED_ARRAY 8
+#define AMF_ARRAY  10
+#define AMF_DATE   11
+
+static void put_amf_string(ByteIOContext *pb, const char *str)
+{
+    size_t len = strlen(str);
+    put_be16(pb, len);
+    put_buffer(pb, str, len);
+}
+
+static void put_amf_double(ByteIOContext *pb, double d)
+{
+    put_byte(pb, AMF_DOUBLE);
+    put_be64(pb, av_dbl2int(d));
+}
+
 static int flv_write_header(AVFormatContext *s)
 {
     ByteIOContext *pb = &s->pb;
     FLVContext *flv = s->priv_data;
-    int i;
+    int i, width, height, samplerate;
+    double framerate = 0.0;
+    int metadata_size_pos, data_size;
 
     flv->hasAudio = 0;
     flv->hasVideo = 0;
@@ -96,6 +119,19 @@
 
     for(i=0; i<s->nb_streams; i++){
         AVCodecContext *enc = s->streams[i]->codec;
+        if (enc->codec_type == CODEC_TYPE_VIDEO) {
+            width = enc->width;
+            height = enc->height;
+            if (s->streams[i]->r_frame_rate.den && s->streams[i]->r_frame_rate.num) {
+                framerate = av_q2d(s->streams[i]->r_frame_rate);
+            } else {
+                framerate = 1/av_q2d(s->streams[i]->codec->time_base);
+            }
+            flv->hasVideo=1;
+        } else {
+            flv->hasAudio=1;
+            samplerate = enc->sample_rate;
+        }
         av_set_pts_info(s->streams[i], 24, 1, 1000); /* 24 bit pts in ms */
         if(enc->codec_tag == 5){
             put_byte(pb,8); // message type
@@ -109,6 +145,62 @@
             return -1;
     }
 
+    /* write meta_tag */
+    put_byte(pb, 18);         // tag type META
+    metadata_size_pos= url_ftell(pb);
+    put_be24(pb, 0);          // size of data part (sum of all parts below)
+    put_be24(pb, 0);          // time stamp
+    put_be32(pb, 0);          // reserved
+
+    /* now data of data_size size */
+
+    /* first event name as a string */
+    put_byte(pb, AMF_STRING); // 1 byte
+    put_amf_string(pb, "onMetaData"); // 12 bytes
+
+    /* mixed array (hash) with size and string/type/data tuples */
+    put_byte(pb, AMF_MIXED_ARRAY);
+    put_be32(pb, 4*flv->hasVideo + flv->hasAudio + (!!s->file_size) + (s->duration != AV_NOPTS_VALUE && s->duration));
+
+    if (s->duration != AV_NOPTS_VALUE && s->duration) {
+        put_amf_string(pb, "duration");
+        put_amf_double(pb, s->duration / (double)AV_TIME_BASE);
+    }
+
+    if(flv->hasVideo){
+        put_amf_string(pb, "width");
+        put_amf_double(pb, width);
+
+        put_amf_string(pb, "height");
+        put_amf_double(pb, height);
+
+        put_amf_string(pb, "videodatarate");
+        put_amf_double(pb, s->bit_rate / 1024.0);
+
+        put_amf_string(pb, "framerate");
+        put_amf_double(pb, framerate);
+    }
+
+    if(flv->hasAudio){
+        put_amf_string(pb, "audiosamplerate");
+        put_amf_double(pb, samplerate);
+    }
+
+    if(s->file_size){
+        put_amf_string(pb, "filesize");
+        put_amf_double(pb, s->file_size);
+    }
+
+    put_amf_string(pb, "");
+    put_byte(pb, 9); // end marker 1 byte
+
+    /* write total size of tag */
+    data_size= url_ftell(pb) - metadata_size_pos - 10;
+    url_fseek(pb, metadata_size_pos, SEEK_SET);
+    put_be24(pb, data_size);
+    url_fseek(pb, data_size + 10 - 3, SEEK_CUR);
+    put_be32(pb, data_size + 11);
+
     return 0;
 }
 
@@ -143,7 +235,6 @@
         put_byte(pb, 9);
         flags = 2; // choose h263
         flags |= pkt->flags & PKT_FLAG_KEY ? 0x10 : 0x20; // add keyframe indicator
-        flv->hasVideo = 1;
     } else {
         assert(enc->codec_type == CODEC_TYPE_AUDIO);
         flags = get_audio_flags(enc);
@@ -151,9 +242,6 @@
         assert(size);
 
         put_byte(pb, 8);
-
-        // We got audio! Make sure we set this to the global flags on closure
-        flv->hasAudio = 1;
     }
 
     put_be24(pb,size+1); // include flags

Modified: trunk/tests/ffmpeg.regression.ref
==============================================================================
--- trunk/tests/ffmpeg.regression.ref	(original)
+++ trunk/tests/ffmpeg.regression.ref	Mon Jul 17 23:51:21 2006
@@ -125,8 +125,8 @@
 1453500 ./data/a-asv2.avi
 0b310840a6d3970595983491687669df *./data/out.yuv
 stddev: 18.82 PSNR:22.63 bytes:7602176
-de42cb5a15bfa8e70cf60edda0b32355 *./data/a-flv.flv
-657991 ./data/a-flv.flv
+2e1647c88d1b7e56d91058484db602da *./data/a-flv.flv
+658104 ./data/a-flv.flv
 4d9c04e7017dc68da7891048c46c1c37 *./data/out.yuv
 stddev:  8.08 PSNR:29.97 bytes:7602176
 a7ef4746f27be309138c188e327d3ebe *./data/a-ffv1.avi

Modified: trunk/tests/libav.regression.ref
==============================================================================
--- trunk/tests/libav.regression.ref	(original)
+++ trunk/tests/libav.regression.ref	Mon Jul 17 23:51:21 2006
@@ -19,8 +19,8 @@
 0026c4e2528ff8f71b79ef53d38cc04d *./data/b-libav.ffm
  389120 ./data/b-libav.ffm
 ./data/b-libav.ffm CRC=0x688bd1eb
-794934a02582f8dfc85d1856514cf37c *./data/b-libav.flv
- 339325 ./data/b-libav.flv
+eb8ff480628c444be572045ef7208528 *./data/b-libav.flv
+339438 ./data/b-libav.flv
 ./data/b-libav.flv CRC=0x7b9076f8
 63e05396e2d52135c4025ce14eb090a9 *./data/b-libav.mov
 369893 ./data/b-libav.mov

Modified: trunk/tests/rotozoom.regression.ref
==============================================================================
--- trunk/tests/rotozoom.regression.ref	(original)
+++ trunk/tests/rotozoom.regression.ref	Mon Jul 17 23:51:21 2006
@@ -125,8 +125,8 @@
 788036 ./data/a-asv2.avi
 74a78015b64b2cf8cb9da2e44f508a69 *./data/out.yuv
 stddev: 10.28 PSNR:27.88 bytes:7602176
-d847c144e7b72027531047ea4c441cbf *./data/a-flv.flv
-131771 ./data/a-flv.flv
+ae1a6e011fa1ae015cb16a925de4bcfa *./data/a-flv.flv
+131884 ./data/a-flv.flv
 e61cd1e7c5a292d396ae90f4d2fb3db7 *./data/out.yuv
 stddev:  5.33 PSNR:33.57 bytes:7602176
 d0831a8339491fd680b650f05262e5d9 *./data/a-ffv1.avi




More information about the ffmpeg-cvslog mailing list