[FFmpeg-devel] FLV tag has invalid field when using VP6

Andrew Brampton andrew
Sat Jul 21 13:50:13 CEST 2007

I think I have found a minor bug when writing out FLV files with the VP6 
codec. Each FLV tag contains a previous length field which should be the 
size of the previous tag + the tag's header (which is 11 bytes).

Now I've been writing a tool to parse FLV files and add meta data (its 
called flvtool++). However when parsing a file generated with the latest SVN 
release of ffmpeg my tool detects that the Video tags have an incorrect 
previous length. Here is some output from my app, showing the tag's length, 
and the previous length.

272 AudioTag time:0 length:209 prev:220 Stero 16bit 44khz MP3
496 VideoTag time:0 length:19008 prev:19018 type:K codec:On2 VP6
19519 AudioTag time:26 length:210 prev:221 Stero 16bit 44khz MP3
19744 VideoTag time:33 length:923 prev:933 type:I codec:On2 VP6
20682 AudioTag time:52 length:210 prev:221 Stero 16bit 44khz MP3
20907 VideoTag time:67 length:690 prev:700 type:I codec:On2 VP6

The prev field should be length + 11, but with the VideoTags its length + 
10. This does not happen if I use a different codec within FLV.

Now I think I've tracked this bug down to line 313 of libavformat\flvenc.c 
where the previous tag size is written:
312: put_buffer(pb, pkt->data, size);
313: put_be32(pb,size+1+11); // previous tag size
314: flv->duration = pkt->pts + pkt->duration;

If we look further up at lines 301-304 where the length of the tag is 
written, we see its +2 when using VP6:
301:    if ((enc->codec_id == CODEC_ID_VP6) || (enc->codec_id == 
302:        put_be24(pb,size+2); // include the extra byte needed for VP6 in 
flv and flags
303:    else
304:        put_be24(pb,size+1); // include flags

So I think the fix would be to change line 313 to add 2 when using VP6. I 
could code a patch to do this, but I wanted to check here first since I am 
not familiar with the ffmpeg code, and I didn't want to write something 

Thanks for any feedback,

More information about the ffmpeg-devel mailing list