Audio/video stream recording forums (http://stream-recorder.com/forum/index.php)
-   rtmpdump (http://stream-recorder.com/forum/forumdisplay.php?f=54)
-   -  

FLV fixer script

(http://stream-recorder.com/forum/showthread.php?t=12722)

KSV 06-03-2012 10:28 AM

FLV fixer script


 
I have created a new script for repairing the FLV files based on the flv processing code taken from my another script AdobeHDS. it can help you in following scenarios.
  1. it can fix live streams recorded with rtmpdump which are not remuxable with ffmpeg or not properly seekable.
  2. it can extract valid flv data leaving out junk from interrupted downloads which are no longer resumable with rtmpdump. you can resume them after fixing with this script.

You can use script with following switches:
Code:

--help              displays this help
 --debug            show debug output
 --nometa            do not save metadata in repaired file
 --fixwindow [param] timestamp gap between frames to consider as timeshift
 --in        [param] input filename of flv file to be repaired
 --out      [param] output filename for repaired file

Download:
Code:

https://github.com/K-S-V/Scripts

greenythebeast 06-03-2012 03:43 PM

Re: FLV fixer script


 
Wonderful, thanks!

KSV 07-18-2012 01:07 AM

Re: FLV fixer script


 
Changes:
Code:

1. rebase timestamps to zero + other improvements
2. added nometa switch to remove metadata from repaired file

removing metadata from repaired file can be often useful in case of live streams because they normally have wrong duration set in metadata.

Elgero 07-22-2012 02:56 PM

Re: FLV fixer script


 
KSV, would it be difficult to write a script or modify the flvFixer script so it can read several chunks/parts from an Flv video and then save them as a single video in one process?

I have quite a few large Flv videos (some are over 2GB) I need to cut first and then join the cut parts together, but I'm having a lot of problems finding a freeware application that can do it properly.

Some applications crash with large files, because they want to load the entire video in memory. Other applications can cut only 1 part at once, which takes a lot of time and other applications don't support Nellymoser or Speex audio, even though it's raw file editing.

I'd like to edit based on seconds or perhaps milliseconds. I know that every video needs to start on a keyframe, which means it won't always cut exactly on the specified start time, but that's not a problem.


For example:

--parts 39-249,583-937,1292-1819

cut from second 39 to 249
cut from second 583 to 937
cut from second 1292 to 1819

Save the parts as a single Flv video.

greenythebeast 07-22-2012 09:32 PM

Re: FLV fixer script


 
Quote:

Originally Posted by Elgero (Post 49664)
KSV, would it be difficult to write a script or modify the flvFixer script so it can read several chunks/parts from an Flv video and then save them as a single video in one process?

I have quite a few large Flv videos (some are over 2GB) I need to cut first and then join the cut parts together, but I'm having a lot of problems finding a freeware application that can do it properly.

Some applications crash with large files, because they want to load the entire video in memory. Other applications can cut only 1 part at once, which takes a lot of time and other applications don't support Nellymoser or Speex audio, even though it's raw file editing.

I'd like to edit based on seconds or perhaps milliseconds. I know that every video needs to start on a keyframe, which means it won't always cut exactly on the specified start time, but that's not a problem.


For example:

--parts 39-249,583-937,1292-1819

cut from second 39 to 249
cut from second 583 to 937
cut from second 1292 to 1819

Save the parts as a single Flv video.

Pretty sure you can do this with ffmpeg.

Elgero 07-22-2012 11:19 PM

Re: FLV fixer script


 
Quote:

Originally Posted by greenythebeast (Post 49675)
Pretty sure you can do this with ffmpeg.

Thank you. Do you know if ffmpeg can cut multiple parts with one command? The only commands I can find are -ss (start time) and -t (duration) to cut one part. This is what I'm already doing and it takes too long to do this all step by step. Or perhaps I need to write a batch script to do this.

I'm not a PHP programmer, but I'll play around with the FlvFixer script and maybe I can add it myself. I rather have the PHP script, it gives me more control and I can add little things, like "duration" metadata that some video players require to be able to seek.

Elgero 07-23-2012 03:50 PM

Re: FLV fixer script


 
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)


greenythebeast 07-23-2012 06:00 PM

Re: FLV fixer script


 
Quote:

Originally Posted by Elgero (Post 49714)
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/

Elgero 07-23-2012 09:03 PM

Re: FLV fixer script


 
Unfortunately not. AVIDemux is one of those tools that does not support Nellymoser audio, even though it's just raw file editing.

When I load the Flv video it first complains that no audio decoder can be found. When I try to save the video anyway it complains about unsupported audio and that saving the video has failed.

KSV 07-23-2012 11:51 PM

Re: FLV fixer script


 
IMO trying to add editing capabilities (sort of) to this script is out of scope for it's intended purpose though you are free to play around with your copy.

PayNow 07-24-2012 05:43 AM

Re: FLV fixer script


 
KSV do u have any script for fix live stream audio is not sync for video.

Elgero 07-24-2012 08:30 AM

Re: FLV fixer script


 
Quote:

Originally Posted by KSV (Post 49731)
IMO trying to add editing capabilities (sort of) to this script is out of scope for it's intended purpose though you are free to play around with your copy.

I can modify the script to extract the parts I need, that's not the problem, but I don't know how to modify the timestamps. The timestamps of the first part are fixed correctly, but the start time of the second part does not 'connect' to the end time of the first part.

If the first part is one minute long, then the timestamp of the last video frame is 1:00.724, this is correct, but the timestamp of the first video frame of the second part starts with 5:37.141.

I don't know if there's a fairly easy fix for that or if a large part of the script needs to be rewritten, which is not worth it.

KSV 07-24-2012 12:16 PM

Re: FLV fixer script


 
Quote:

Originally Posted by Elgero (Post 49752)
I don't know if there's a fairly easy fix for that or if a large part of the script needs to be rewritten, which is not worth it.

without actually trying to make it do so i can't say for sure but it may be a bit tricky. $baseTS value should be updated with new starting timestamp for correct rebasing.

Bahman 08-07-2012 12:49 PM

Re: FLV fixer script


 
KSV, Can you please add trim option in this script?

KSV 08-08-2012 07:42 AM

Re: FLV fixer script


 
Quote:

Originally Posted by Bahman (Post 50807)
KSV, Can you please add trim option in this script?

trimming what?

Bahman 08-08-2012 10:01 AM

Re: FLV fixer script


 
Trimming Video! For example, I give it a duration or imputing a value that trim from a time to another time! like start and stop of rtmpdump!

Elgero 12-18-2012 02:24 PM

Re: FLV fixer script


 
KSV is there any way you can modify the script to fix the videos from MyFreeCams.com, Naked.com and Cams.com?

These websites deliberately put a random wrong timestamp in the video after 2/10th of a second, so most video players are not able to play the recorded videos properly. VLC can play them, but most other video players play only those first 2/10th of a second.

The only frames with the correct timestamp are the keyframes.


svnpenn2 12-18-2012 06:03 PM

Re: FLV fixer script


 
Quote:

Originally Posted by Elgero
These websites deliberately put a random wrong timestamp in the video after 2/10th of a second, so most video players are not able to play the recorded videos properly. VLC can play them, but most other video players play only those first 2/10th of a second.

Upload sample video, I may have answer.

Elgero 12-18-2012 06:29 PM

Re: FLV fixer script


 
Here's a small sample video.

<sample video deleted>

svnpenn2 12-18-2012 07:41 PM

Re: FLV fixer script


 
I could be wrong but it appears you can fix this by simply remuxing with FFmpeg

Code:

$ ffmpeg -i sample.flv -c copy a.flv
ffmpeg version N-47062-g26c531c Copyright (c) 2000-2012 the FFmpeg developers
  built on Nov 25 2012 12:25:21 with gcc 4.7.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-pthreads --enable-runt
ime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass -
-enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enab
le-libgsm --enable-libmp3lame --enable-libnut --enable-libopenjpeg --enable-libo
pus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheo
ra --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-li
bvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --ena
ble-zlib
  libavutil      52.  9.100 / 52.  9.100
  libavcodec    54. 77.100 / 54. 77.100
  libavformat    54. 37.100 / 54. 37.100
  libavdevice    54.  3.100 / 54.  3.100
  libavfilter    3. 23.102 /  3. 23.102
  libswscale      2.  1.102 /  2.  1.102
  libswresample  0. 17.101 /  0. 17.101
  libpostproc    52.  2.100 / 52.  2.100
[flv @ 000000000032dd60] DTS discontinuity in stream 0: packet 6 with DTS 129, p
acket 7 with DTS 420679
Input #0, flv, from 'sample.flv':
  Duration: 00:08:38.21, start: 0.000000, bitrate: 282 kb/s
    Stream #0:0: Video: flv1, yuv420p, 480x360, 1k tbr, 1k tbn, 1k tbc
    Stream #0:1: Audio: nellymoser, 22050 Hz, mono, flt
Output #0, flv, to 'a.flv':
  Metadata:
    encoder        : Lavf54.37.100
    Stream #0:0: Video: flv1 ([2][0][0][0] / 0x0002), yuv420p, 480x360, q=2-31,
1k tbn, 1k tbc
    Stream #0:1: Audio: nellymoser ([6][0][0][0] / 0x0006), 22050 Hz, mono
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[flv @ 0000000003f102e0] st:0 PTS: 743 DTS: 743 < 421128 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 1757 DTS: 1757 < 422167 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 2784 DTS: 2784 < 423187 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 3803 DTS: 3803 < 424206 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 4791 DTS: 4791 < 425197 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 5806 DTS: 5806 < 426210 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 6828 DTS: 6828 < 427229 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 7862 DTS: 7862 < 428260 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 8883 DTS: 8883 < 429289 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 9902 DTS: 9902 < 430284 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 10896 DTS: 10896 < 431298 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 11914 DTS: 11914 < 432317 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 12936 DTS: 12936 < 433337 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 13928 DTS: 13928 < 434333 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 14962 DTS: 14962 < 435351 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 15985 DTS: 15985 < 436374 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 17002 DTS: 17002 < 437407 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 18030 DTS: 18030 < 438434 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 19045 DTS: 19045 < 439451 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 20064 DTS: 20064 < 440469 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 21054 DTS: 21054 < 441456 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 22122 DTS: 22122 < 442511 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 23114 DTS: 23114 < 443502 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 24165 DTS: 24165 < 444540 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 25149 DTS: 25149 < 445562 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 26145 DTS: 26145 < 446549 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 27165 DTS: 27165 < 447569 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 28186 DTS: 28186 < 448591 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 29233 DTS: 29233 < 449577 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 30194 DTS: 30194 < 450632 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 31256 DTS: 31256 < 451636 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 32244 DTS: 32244 < 452656 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 33271 DTS: 33271 < 453675 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 34283 DTS: 34283 < 454689 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 35275 DTS: 35275 < 455675 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 36297 DTS: 36297 < 456700 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 37315 DTS: 37315 < 457718 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 38349 DTS: 38349 < 458714 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 39343 DTS: 39343 < 459747 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 40360 DTS: 40360 < 460767 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 41387 DTS: 41387 < 461791 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 42411 DTS: 42411 < 462846 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 43430 DTS: 43430 < 463834 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 44445 DTS: 44445 < 464823 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 45436 DTS: 45436 < 465840 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 46473 DTS: 46473 < 466878 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 47490 DTS: 47490 < 467917 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 48521 DTS: 48521 < 468965 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 49536 DTS: 49536 < 469938 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 50527 DTS: 50527 < 470928 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 51548 DTS: 51548 < 471961 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 52641 DTS: 52641 < 473061 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 53664 DTS: 53664 < 474068 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 54655 DTS: 54655 < 475061 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 55672 DTS: 55672 < 476074 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 56700 DTS: 56700 < 477101 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 57717 DTS: 57717 < 478119 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 58769 DTS: 58769 < 479113 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 59735 DTS: 59735 < 480123 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 60733 DTS: 60733 < 481119 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 61780 DTS: 61780 < 482163 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 62765 DTS: 62765 < 483180 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 63795 DTS: 63795 < 484196 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 64840 DTS: 64840 < 485245 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 65806 DTS: 65806 < 486209 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 66819 DTS: 66819 < 487225 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 67812 DTS: 67812 < 488217 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 68844 DTS: 68844 < 489246 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 69863 DTS: 69863 < 490298 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 70920 DTS: 70920 < 491294 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 71908 DTS: 71908 < 492314 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 72900 DTS: 72900 < 493305 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 73922 DTS: 73922 < 494325 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 74943 DTS: 74943 < 495345 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 75971 DTS: 75971 < 496361 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 76960 DTS: 76960 < 497350 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 77982 DTS: 77982 < 498419 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 79002 DTS: 79002 < 499380 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 79992 DTS: 79992 < 500428 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 81046 DTS: 81046 < 501456 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 82062 DTS: 82062 < 502441 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 83052 DTS: 83052 < 503464 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 84097 DTS: 84097 < 504499 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 85116 DTS: 85116 < 505518 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 86133 DTS: 86133 < 506534 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 87157 DTS: 87157 < 507555 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 88144 DTS: 88144 < 508578 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 89134 DTS: 89134 < 509539 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 90145 DTS: 90145 < 510560 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 91189 DTS: 91189 < 511605 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 92210 DTS: 92210 < 512614 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 93222 DTS: 93222 < 513626 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 94221 DTS: 94221 < 514625 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 95233 DTS: 95233 < 515637 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 96288 DTS: 96288 < 516692 invalid, clipping
[flv @ 0000000003f102e0] st:0 PTS: 97282 DTS: 97282 < 517685 invalid, clipping
frame= 1448 fps=0.0 q=-1.0 Lsize=  17887kB time=00:08:38.22 bitrate= 282.8kbits
/s
video:17305kB audio:526kB subtitle:0 global headers:0kB muxing overhead 0.313095
%


Elgero 12-18-2012 09:10 PM

Re: FLV fixer script


 
Quote:

Originally Posted by svnpenn2 (Post 57655)
I could be wrong but it appears you can fix this by simply remuxing with FFmpeg

FFmpeg fixes the video, so it works in every video player, but it doesn't fix the timestamps. It only changes the timestamp of the keyframes, so they match the other frames.

With the sample video I posted above, I need to skip to 7 minutes before it starts to play the video. The first 7 minutes of the video is basically a still image of the first frame.

First image is before fixing, second image is after fixing.



KSV 12-19-2012 07:50 AM

Re: FLV fixer script


 
@Elgero

i have made some specific fixes to correct files with such odd timestamps. try it out and post your feedback.

http://pastebin.com/2CeNeArd

Elgero 12-19-2012 10:31 AM

Re: FLV fixer script


 
KSV, thank you very much. The timestamps are fixed correctly now.

TubeDigger 12-19-2012 08:56 PM

Re: FLV fixer script


 
Yet Another FLV Fixer: C file and compiled binary. Please test and provide your feedback.

Elgero 12-19-2012 09:19 PM

Re: FLV fixer script


 
TubeDigger, that one works fine too.



The only thing I've noticed is that VLC, MPC and WMP play the fixed videos without problems, but for example BSPlayer keeps playing the first 2/10th of a second over and over again (with both FLV Fixers). It must be BSPlayer, but I wonder what the problem might be. BSPlayer has no problems with playing FLV videos that don't have these odd timestamps.

svnpenn2 12-19-2012 09:31 PM

Re: FLV fixer script


 
Quote:

Originally Posted by Elgero
BSPlayer keeps playing the first 2/10th of a second over and over again

As workaround, you can try clipping first second

Code:

ffmpeg -ss 1 a.flv -c copy b.flv

Elgero 12-19-2012 09:45 PM

Re: FLV fixer script


 
Quote:

Originally Posted by svnpenn2 (Post 57711)
As workaround, you can try clipping first second

Code:

ffmpeg -ss 1 a.flv -c copy b.flv

Thank you very much. BSPlayer can now play them as well.

reumb 12-20-2012 07:48 AM

Re: FLV fixer script


 
Quote:

Originally Posted by TubeDigger (Post 57708)
Yet Another FLV Fixer: C file and compiled binary. Please test and provide your feedback.


this is a best windows noob tool seen here (in my opinion)

just draw/drop your flv f4v to yaflvfix.exe

works allmost on every file ------- great1!

TubeDigger 12-20-2012 08:19 AM

Re: FLV fixer script


 
Quote:

Originally Posted by reumb (Post 57745)
works allmost on every file

For further improvements please upload that problematic videos and post links to them here or via PM.

KSV 12-21-2012 07:28 AM

Re: FLV fixer script


 
i have pushed the update to repo with a bit of more fine tuning.

@TubeDigger

Thanx for your contributions.

TubeDigger 01-01-2013 05:53 PM

Re: FLV fixer script


 
Slightly improved Yet Another FLV Fixer: C file and compiled binary.

reumb 01-02-2013 09:03 AM

Re: FLV fixer script


 
Thanks for the update TubeDigger

Best flvfixer ever made for windows noobs/pros (in my opinion)

just drag/drop your flv f4v on yaflvfix.exe

grobatob 01-19-2013 11:44 PM

Re: FLV fixer script


 
Hi, I have a problem that I suppose most people don't have because I have "broken" the file I need fixed myself.

The problem is I have a series of flv files dumped with rtmpdump that I want to merge, which have identical video/audio streams with overlap so they can't simply be connected one after the other. (That is for example file1 goes from 0-1hr file2 goes 45mins to 2 hours, etc) I have linux so I am unable to try most of the merging tools I found with a google search, but avconv and ffdshow both seem to be unable to do it.

The files all have identical video/audio streams and since they overlap I went and found a spot they are the same in a hex editor and simply used dd to trim them then cat to join them together. Once concatenated together the playback is perfect and seamless in the version of mplayer2 I have installed (2.1~git20120828.28228-1) from start to end, however it doesn't show total play time and the OSD time jumps backwards when it hits the join point in the files with the message:

Code:

Decreasing video pts: 4.743000 < 50.986000
Playing the same file in VLC causes a large skip, presumably VLC is skipping ahead to the next point in the file where the pts is greater than the last one it played.

I was hoping these concatenated files could simply be run through ffmpeg with '-codec copy' but when ffmpeg (most recent compiled from their git) gets to the join it gives a series of errors like this:

Code:

[flv @ 0x204cba0] st:0 PTS: 41471 DTS: 41471 < 50991 invalid, clipping
The resulting file has the wrong total time, and when it gets to the join the video skips ahead a fair bit (in mplayer2) then the video ends early while the audio continues to play without any skip and goes its full length. VLC behaves the same as it did before running the file through ffmpeg

So I have been searching around trying to figure out how to fix the timestamps. Presumably they just need to be resequenced so they line up as they should. I looked at the ffmpeg source code where the 'invalid, clipping' message is to see if I could edit it to adjust the timestamps instead of clipping but it is quite a bit over my head.

So that is what brings me here. I have tried both the php script and compiled the latest yaflvfix.c which works fine on linux. The php script gives weird artefacting at the join which other attempts to fix haven't and the same large skip/too short video playback. The yaflvfix program gives seemingly identical results to ffmpeg, but the source code is a lot easier to understand so I think it is the closest I have gotten to fixing this problem.

Now I am trying to work from the yaflvfix source to see if I can edit it to meet my needs, but I was hoping someone could help me as I am completely clueless about all of this. Maybe someone could do it very easily, whereas for me it is very difficult. I know nothing about video streams or editing them at all.

Here is a 12000682 byte sample clip showing my problem. The first 6000000 bytes are from the first video file and contain the unmodified header, the last 6000682 bytes are from the second file which I need to join and of course are taken from the middle of some video/audio data which is identical in both files. This isn't exactly where I need to merge them but is the shortest clip I could make where they overlap. The actual files are much larger.

http://www.mediafire.com/?y2h9o6dml11kaz1

Any assistance people could give with fixing this would be greatly appreciated. If the yaflvfix.c program can be modified to handle this type of file I think that seems most promising right now. As I said this file plays flawlessly in a recent mplayer2 build so there is no video or audio corruption at all, it appears to be entirely a problem with timestamps and how various software deals with the timestamps.

Thank you for reading, and thank you for any help you can give.

KSV 01-20-2013 10:13 AM

Re: FLV fixer script


 
@grobatob

Try this one:
http://pastebin.com/NHCE3c3f

grobatob 01-20-2013 06:32 PM

Re: FLV fixer script


 
Quote:

Originally Posted by KSV (Post 58705)
@grobatob

Try this one:
http://pastebin.com/NHCE3c3f

Wow, thank you so much this seems to work exactly as I had needed! I only tried it on that sample file and a larger one with a single "seam" for now but it does exactly what I had hoped for! I can even now run it through ffmpeg without error to losslessly remux as mp4. Great!

I will try it on a much larger file soon with several "seams" and let you know how it goes, but I anticipate it would work fine. At any rate I could probably just join one file at a time then run the fix after each join if needed.

Will these changes eventually be merged into the main script you host on github, or is it something too custom and alters the behaviour in a way that it no longer works for other files it was originally intended for?

Thanks again. You fixed it so fast when I had been struggling with it for a long time. Your work is very much appreciated.

KSV 01-21-2013 04:22 AM

Re: FLV fixer script


 
i have pushed the update to the repo. hopefully it wouldn't break any previous functionality. before reporting any problem with any of my scripts make sure you are using the latest version of the script from repo.

KSV 03-02-2013 07:38 AM

Re: FLV fixer script


 
Changes:

Code:

1. improved performance of FlvFixer
Batch file for drag and drop functionality:
Code:

@echo off
title KSV FlvFixer Script

rem == Set input output filenames ==
set IN_FILE="%~dpnx1"
set OUT_FILE="%~dpn1_fixed.flv"

rem == Change current directory ==
cd "%~dp0"
cd %~d0

php FlvFixer.php --in %IN_FILE% --out %OUT_FILE% --debug --nometa 2> Debug.txt


Mary Chris Smith 03-02-2013 01:15 PM

Re: FLV fixer script


 
Hey KSV,
I want to fix a FLV file which rtmpdump (live stream) generated.
I get the following error:
Code:

FlvFixer.php --debug --nometa --in foo.flv --out bar.flv
Code:

                                KSV FLV Fixer

 Type    CurrentTS      PreviousTS      Size    Position       
 VIDEO  0              -1              15641  13             
Fixing video timestamp
 VIDEO  0              0              7796   
 VIDEO  8              0              7796    15669         
Fixing video timestamp
 VIDEO  0              8              9197   
 VIDEO  16              8              9197    23480         
Fixing video timestamp
 VIDEO  0              16              7792   
 VIDEO  24              16              7792    32692         
Fixing video timestamp
 VIDEO  0              24              8003   
 VIDEO  32              24              8003    40499         
Fixing video timestamp
 VIDEO  0              32              7762   
 VIDEO  40              32              7762    48517         
Fixing video timestamp
 VIDEO  0              40              9007   
 VIDEO  48              40              9007    56294         
Fixing video timestamp
 VIDEO  0              48              7926   
 VIDEO  56              48              7926    65316         
Fixing video timestamp
 VIDEO  0              56              9196   
 VIDEO  64              56              9196    73257         
Fixing video timestamp
 VIDEO  0              64              421   
 VIDEO  72              64              421    82468         
Fixing video timestamp
 VIDEO  0              72              7848   
 VIDEO  80              72              7848    82904         
Fixing video timestamp
 VIDEO  0              80              7474   
 VIDEO  88              80              7474    90767         
Fixing video timestamp
 VIDEO  0              88              8066   
 VIDEO  96              88              8066    98256         
Fixing video timestamp
 VIDEO  0              96              7232   
 VIDEO  104            96              7232    106337         
Fixing video timestamp
 VIDEO  0              104            8107   
 VIDEO  112            104            8107    113584         
Fixing video timestamp
 VIDEO  0              112            7724   
 VIDEO  120            112            7724    121706         
Broken FLV tag encountered! Aborting further processing.
Processed input file in 0.06 seconds
Finished


KSV 03-02-2013 11:52 PM

Re: FLV fixer script


 
@Mary Chris Smith

Well script isn't lying. rtmpdump actually saved the corrupt file. it's a known bug in official version which i fixed ages ago. you need to use my version of rtmpdump to save the proper file in such cases. if you wanna recover the already saved files you have to fix them first by hand.

Mary Chris Smith 03-03-2013 11:29 AM

Re: FLV fixer script


 
Quote:

Originally Posted by KSV (Post 60225)
@Mary Chris Smith

Well script isn't lying. rtmpdump actually saved the corrupt file. it's a known bug in official version which i fixed ages ago. you need to use my version of rtmpdump to save the proper file in such cases. if you wanna recover the already saved files you have to fix them first by hand.

Ok, I'll try your version, thanks!


All times are GMT -6. The time now is 12:59 PM.