note 86430 modified in faq by danbrown
| From: | danbrown@php.net | Date: | Sat, 18 Oct 2008 15:44:42 +0000 |
| Subject: | note 86430 modified in faq by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145471@lists.php.net to get a copy of this message | ||
It is sometimes useful to decompressed SWF files, for example if you want to process it usin ffmpeg.
I wrote this function because I didn't want to call en external program (like cws2fws)
<?php
/**
* convert compressed swf to uncompressed. usefull for ffmpeg usage
* @param string $in_swf_file input file to convert
* @param string $out_swf_file converted output file
* @param string $error error message
* @return boolean true or false
* see more info at http://the-labs.com/MacromediaFlash/SWF-Spec/SWFfileformat.html
* and a perl version at http://zefonseca.com/cws2fws/release/cws2fws
*/
function decode_swf($in_swf_file, $out_swf_file, &$error) {
$swf = file_get_contents($in_swf_file); // read entire file
if (!$swf) {
$error = "SWF file not fount - $in_swf_file";
return FAIL;
}
$type = substr($swf, 0, 3); // already in uncompressed format?
if ($type == 'FWS') {
@copy ($in_swf_file, $out_swf_file);
return SUCCESS;
}
if ($type != 'CWS') {
$error = "Wrong file format - $in_swf_file";
return FAIL;
}
$uncomp = gzuncompress (substr($swf, 8)); // unzip everything but the header
if (!$uncomp) {
$error = "File data error - $in_swf_file";
return FAIL;
}
$header = substr($swf, 0, 8);
$header[0] = 'F'; // CWS -> FWS
$status = file_put_contents($out_swf_file , $header . $uncomp);
if (!$status) {
$error = "File write error - $out_swf_file";
return FAIL;
}
return SUCCESS;
}
?>
--was--
It is sometimes useful to decompressed SWF files, for example if you want to process it usin ffmpeg.
I wrote this function because I didn't want to call en external program (like cws2fws)
/**
* convert compressed swf to uncompressed. usefull for ffmpeg usage
* @param string $in_swf_file input file to convert
* @param string $out_swf_file converted output file
* @param string $error error message
* @return boolean true or false
* see more info at http://the-labs.com/MacromediaFlash/SWF-Spec/SWFfileformat.html
* and a perl version at http://zefonseca.com/cws2fws/release/cws2fws
*/
function decode_swf($in_swf_file, $out_swf_file, &$error) {
$swf = file_get_contents($in_swf_file); // read entire file
if (!$swf) {
$error = "SWF file not fount - $in_swf_file";
return FAIL;
}
$type = substr($swf, 0, 3); // already in uncompressed format?
if ($type == 'FWS') {
@copy ($in_swf_file, $out_swf_file);
return SUCCESS;
}
if ($type != 'CWS') {
$error = "Wrong file format - $in_swf_file";
return FAIL;
}
$uncomp = gzuncompress (substr($swf, 8)); // unzip everything but the header
if (!$uncomp) {
$error = "File data error - $in_swf_file";
return FAIL;
}
$header = substr($swf, 0, 8);
$header[0] = 'F'; // CWS -> FWS
$status = file_put_contents($out_swf_file , $header . $uncomp);
if (!$status) {
$error = "File write error - $out_swf_file";
return FAIL;
}
return SUCCESS;
}
http://php.net/manual/en/faq.php