本文介绍了如何F4F文件转换为MP4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们知道F4F是Adobe分散的MP4文件格式的 HTTP动态流的。所谓的工具的 F4F包装的可以转换的F4V文件的几个F4F文件和一个清单文件(F4M)。
We know F4F is Adobe's fragmented MP4 file format for HTTP Dynamic Streaming. A tool called F4F Packager could convert an F4V file to several F4F files and a manifest file(F4M).
我的问题是,如何在这样的F4F文件转换回一个F4V或MP4文件?
My question is, how to convert such F4F files back to an F4V or MP4 file?
推荐答案
我们终于找到了一个简单的方法来合并和放大器;转换的 .f4f文件 - > FLV的文件,其中仅MDAT框是有用的。这里是一个PHP的code:
We finally found a simple method to merge & convert .f4f files -> .flv file, in which only 'mdat' box is usefull. Here is a the php code:
<?php
function ReadInt24($str, $pos)
{
return intval(bin2hex(substr($str, $pos, 3)), 16);
}
function ReadInt32($str, $pos)
{
return unpack("N", substr($str, $pos, 4))[1];
}
echo "\nKSV Adobe HDS Downloader\n\n";
$flvHeader = hex2bin("464c5601050000000900000000");
$firstVideoPacket = true;
$prevTagSize = 4;
$fragCount = 0;
isset($argv[1]) ? $baseFilename = $argv[1] : $baseFilename = "";
$baseFilename ? $outputFile = "$baseFilename.flv" : $outputFile = "Joined.flv";
while (true)
{
if (file_exists("$baseFilename" . $fragCount + 1 . ".f4f"))
$fragCount++;
else
break;
}
echo "Found $fragCount fragments\n";
$flv = fopen("$outputFile", "wb");
fwrite($flv, $flvHeader, 13);
for ($i = 1; $i <= $fragCount; $i++)
{
$frag = file_get_contents("$baseFilename$i.f4f");
preg_match('/(.{4})mdat[\x08\x09\x12]/i', $frag, $mdat, PREG_OFFSET_CAPTURE);
$fragLen = ReadInt32($mdat[1][0], 0) - 8;
$frag = substr($frag, $mdat[1][1] + 8, $fragLen);
$pos = 0;
while ($pos < $fragLen)
{
$packetType = $frag[$pos];
$packetSize = ReadInt24($frag, $pos + 1);
$packetTS = ReadInt24($frag, $pos + 4);
$totalTagLen = 11 + $packetSize + $prevTagSize;
if (($packetType == "\x08" && $packetSize > 4) or ($packetType == "\x09" && $packetSize > 40) or ($packetType == "\x09" && $firstVideoPacket))
{
if ($packetType == "\x09" && $firstVideoPacket)
$firstVideoPacket = false;
fwrite($flv, substr($frag, $pos, $totalTagLen), $totalTagLen);
}
$pos += $totalTagLen;
}
}
fclose($flv);
echo "Finished\n";
?>
这篇关于如何F4F文件转换为MP4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!