
07-23-2012, 06:00 PM
|
Senior Member
|
|
Join Date: Dec 2011
Posts: 105
|
|
 Re: FLV fixer script
Quote:
Originally Posted by Elgero
I've been playing around with the FlvFixer script for a while. I know that packet 2021, 4181, 8230 and 10607 are keyframes and I have currently hardcoded them as a test.
The code below works fine, it extracts the parts from keyframe 2021 to 4181 and from keyframe 8230 to 10607. The only problem I don't know how to solve is fixing the timestamps. The timestamps of the first part are fixed correctly, but not the second part.
Is there an "easy" fix for that?
Code:
while ($filePos < $fileLen)
{
$flvTag = fread($flvIn, $tagHeaderLen);
$tagPos = 0;
$packetType = ReadByte($flvTag, $tagPos);
$packetSize = ReadInt24($flvTag, $tagPos + 1);
$packetTS = ReadInt24($flvTag, $tagPos + 4);
$packetTS = $packetTS | (ReadByte($flvTag, $tagPos + 7) << 24);
$flvTag = $flvTag . fread($flvIn, $packetSize + $prevTagSize);
$totalTagLen = $tagHeaderLen + $packetSize + $prevTagSize;
if (strlen($flvTag) != $totalTagLen)
{
DebugLog("Broken FLV tag encountered! Aborting further processing.");
break;
}
$PacketCount += 1;
if (($PacketCount >= 2021 and $PacketCount <= 4181) or ($PacketCount >= 8230 and $PacketCount <= 10607))
{
if (($baseTS === false) and (($packetType == AUDIO) or ($packetType == VIDEO)))
$baseTS = $packetTS;
if ($baseTS > 1000)
{
$packetTS -= $baseTS;
WriteFlvTimestamp($flvTag, $tagPos, $packetTS);
}
switch ($packetType)
{
case AUDIO:
if ($packetTS >= $prevAudioTS - TIMECODE_DURATION * 5)
{
$FrameInfo = ReadByte($flvTag, $tagPos + $tagHeaderLen);
$CodecID = ($FrameInfo & 0xF0) >> 4;
if ($CodecID == CODEC_ID_AAC)
{
$AAC_PacketType = ReadByte($flvTag, $tagPos + $tagHeaderLen + 1);
if ($AAC_PacketType == AAC_SEQUENCE_HEADER)
|
Will Avidemux do what you want? http://fixounet.free.fr/avidemux/
|