[FFmpeg-devel] [PATCH] Correctly Set File Size + Frame Count during Audio SWF Encoding

Jason Lambert jason
Thu Apr 15 14:01:23 CEST 2010


Problem Description:
When converting any Audio to SWF, the File Size is always hard-coded
as 104857600, and Frame Count is always hard coded to 6000. The
incorrect frame count can cause problems when ffmpeg generated swfs
are used inside a flash application and the _totalframes method is
used.

Example command line:
ffmpeg -i 157346.mp3 -ar 44100 -ab 96k -ac 1 -y 157346.swf

When inspecting the generated swf using the swfdump tool
(swftools.org), the following is shown:

==== Error: Real Filesize (1495887) doesn't match header Filesize
(104857600) ====
[HEADER]        File version: 4
[HEADER]        File size: 104857600
[HEADER]        Frame rate: 10.000000
[HEADER]        Frame count: 6000
[HEADER]        Movie width: 320.00
[HEADER]        Movie height: 200.00
[02d]         6 SOUNDSTREAMHEAD2
[013]       317 SOUNDSTREAMBLOCK
[001]         0 SHOWFRAME 1 (00:00:00,000)
[013]       318 SOUNDSTREAMBLOCK
[001]         0 SHOWFRAME 2 (00:00:00,100)
.........
[013]       318 SOUNDSTREAMBLOCK
[001]         0 SHOWFRAME 4595 (00:07:39,382)
[013]       317 SOUNDSTREAMBLOCK
[001]         0 SHOWFRAME 4596 (00:07:39,482)
[000]         0 END

As you can see, the last frame is 4596, and the file size specified in
the header does not match the real file size (swfdump gives a warning
about this).

File size should indicate 1495887 bytes:
$ ls -al 157346.swf
-rw-r--r-- 1 boomkat default 1495887 Apr 14 11:25 157346.swf
$



Problem Solution:
Correctly set the File Size in the SWF header section to the real
number of bytes written, and correctly set the number of frames
included in the SWF.

Details of the SWF file format header information can be confirmed on
page 25 of the SWF File Format Specification document from Adobe,
available here: http://www.adobe.com/devnet/swf/

After my patch is applied, using ffmpeg with the same command line
options as above and then inspecting the generated swf with swfdump
shows:

[HEADER]        File version: 4
[HEADER]        File size: 1495887
[HEADER]        Frame rate: 10.000000
[HEADER]        Frame count: 4596
[HEADER]        Movie width: 320.00
[HEADER]        Movie height: 200.00
[02d]         6 SOUNDSTREAMHEAD2
[013]       317 SOUNDSTREAMBLOCK
[001]         0 SHOWFRAME 1 (00:00:00,000)
[013]       318 SOUNDSTREAMBLOCK
[001]         0 SHOWFRAME 2 (00:00:00,100)
.........
[013]       318 SOUNDSTREAMBLOCK
[001]         0 SHOWFRAME 4595 (00:07:39,382)
[013]       317 SOUNDSTREAMBLOCK
[001]         0 SHOWFRAME 4596 (00:07:39,482)
[000]         0 END

Note that the Frame Count is correct, and the file size is correctly
reflects the total number of bytes in the file:
$ ls -al 157346.swf
-rw-r--r-- 1 boomkat default 1495887 Apr 15 06:58 157346.swf
$



Please find patch (generated using 'svn diff') attached for the
resolution of these issues.

Regards,

Jason
http://www.rumblehq.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: swf_header_info.patch
Type: application/octet-stream
Size: 1760 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100415/8d53885e/attachment.obj>



More information about the ffmpeg-devel mailing list