[1/2] flvenc: Write the right metadata entry count

Message ID 1316614480-10136-1-git-send-email-martin@martin.st
State Committed
Commit cad0c375d957830dbe517313c9e3335f1a863846
Headers show

Commit Message

Martin Storsjö Sept. 21, 2011, 2:14 p.m.
---
 libavformat/flvenc.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

Comments

Alex Converse Sept. 21, 2011, 2:57 p.m. | #1
On Wed, Sep 21, 2011 at 7:14 AM, Martin Storsjö <martin@martin.st> wrote:
>
> ---
>  libavformat/flvenc.c |   13 ++++++++++---
>  1 files changed, 10 insertions(+), 3 deletions(-)
>

Based on my understanding that size is just a size hint.
Martin Storsjö Sept. 21, 2011, 4:05 p.m. | #2
On Wed, 21 Sep 2011, Alex Converse wrote:

> On Wed, Sep 21, 2011 at 7:14 AM, Martin Storsjö <martin@martin.st> wrote:
>>
>> ---
>>  libavformat/flvenc.c |   13 ++++++++++---
>>  1 files changed, 10 insertions(+), 3 deletions(-)
>>
>
> Based on my understanding that size is just a size hint.

Yes, I don't know of any flv demuxer that can't handle what we output now. 
But if we write something other than 0, we might as well write the right 
value IMO.

// Martin
Luca Barbato Oct. 12, 2011, 12:09 p.m. | #3
On 9/21/11 6:05 PM, Martin Storsjö wrote:
> On Wed, 21 Sep 2011, Alex Converse wrote:
>
>> On Wed, Sep 21, 2011 at 7:14 AM, Martin Storsjö <martin@martin.st> wrote:
>>>
>>> ---
>>>  libavformat/flvenc.c |   13 ++++++++++---
>>>  1 files changed, 10 insertions(+), 3 deletions(-)
>>>
>>
>> Based on my understanding that size is just a size hint.
>
> Yes, I don't know of any flv demuxer that can't handle what we output
> now. But if we write something other than 0, we might as well write the
> right value IMO.
>

It shouldn't hurt. Feel free to push once you are happy with the test.

lu
Martin Storsjö Oct. 12, 2011, 12:29 p.m. | #4
On Wed, 12 Oct 2011, Luca Barbato wrote:

> On 9/21/11 6:05 PM, Martin Storsjö wrote:
>> On Wed, 21 Sep 2011, Alex Converse wrote:
>> 
>>> On Wed, Sep 21, 2011 at 7:14 AM, Martin Storsjö <martin@martin.st> wrote:
>>>> 
>>>> ---
>>>>  libavformat/flvenc.c |   13 ++++++++++---
>>>>  1 files changed, 10 insertions(+), 3 deletions(-)
>>>> 
>>> 
>>> Based on my understanding that size is just a size hint.
>> 
>> Yes, I don't know of any flv demuxer that can't handle what we output
>> now. But if we write something other than 0, we might as well write the
>> right value IMO.
>> 
>
> It shouldn't hurt. Feel free to push once you are happy with the test.

Applied.

// Martin

Patch

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index f3017d7..23d19cd 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -177,9 +177,9 @@  static int flv_write_header(AVFormatContext *s)
     AVIOContext *pb = s->pb;
     FLVContext *flv = s->priv_data;
     AVCodecContext *audio_enc = NULL, *video_enc = NULL;
-    int i;
+    int i, metadata_count = 0;
     double framerate = 0.0;
-    int64_t metadata_size_pos, data_size;
+    int64_t metadata_size_pos, data_size, metadata_count_pos;
     AVDictionaryEntry *tag = NULL;
 
     for(i=0; i<s->nb_streams; i++){
@@ -237,7 +237,9 @@  static int flv_write_header(AVFormatContext *s)
 
     /* mixed array (hash) with size and string/type/data tuples */
     avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY);
-    avio_wb32(pb, 5*!!video_enc + 5*!!audio_enc + 2); // +2 for duration and file size
+    metadata_count_pos = avio_tell(pb);
+    metadata_count = 5*!!video_enc + 5*!!audio_enc + 2; // +2 for duration and file size
+    avio_wb32(pb, metadata_count);
 
     put_amf_string(pb, "duration");
     flv->duration_offset= avio_tell(pb);
@@ -281,6 +283,7 @@  static int flv_write_header(AVFormatContext *s)
         put_amf_string(pb, tag->key);
         avio_w8(pb, AMF_DATA_TYPE_STRING);
         put_amf_string(pb, tag->value);
+        metadata_count++;
     }
 
     put_amf_string(pb, "filesize");
@@ -292,6 +295,10 @@  static int flv_write_header(AVFormatContext *s)
 
     /* write total size of tag */
     data_size= avio_tell(pb) - metadata_size_pos - 10;
+
+    avio_seek(pb, metadata_count_pos, SEEK_SET);
+    avio_wb32(pb, metadata_count);
+
     avio_seek(pb, metadata_size_pos, SEEK_SET);
     avio_wb24(pb, data_size);
     avio_skip(pb, data_size + 10 - 3);