This is a message.

Dealing With "Stuck" Videos Created Jun 7, 2009

This thread is solved

Views: 3448     Replies: 9     Last reply Jun 8, 2009  
You must login first before you can use this feature

gmccomb

Posts: 746

Registered:
Apr 9, 2009

Dealing With "Stuck" Videos

Posted: Jun 7, 2009

Work with FLV video long enough and you'll find a common problem is videos that stop playing correctly once you play at or near the end. Typically they stutter if you try to reply them, or only play from the beginning (losing seek ability), or just plain stall out if you try to view them again after they've run once to the end.

It's caused by faulty encoding, and while I have not yet determined what encoders create the problem, I have found a fairly easy method to fix it that doesn't require re-encoding.

(The current builds of FFMPEG do not seem to be the culprit, but given how I encounter so many of these files "in the wild," and the near ubiqitous nature of FFMPEG, I suspect it might be from an earlier build of the program. If you use FFMPEG be sure to have a reasonably up-to-date version.)

According to Adob'e FLVCheck tool these files suffer from a "backwards" or anachronistic timestamp. That's always been a given, but it took my experimenting with writing my own metadata injector to find out that the bad timestamp is almost always placed at the end of the file, and has a value of 0. Not good.

One way to fix the problem is simply to re-encode, but this can cause a deterioration of quality. I tried a variety of metadata injectors, and so far have found only one that can fix this. It's Yamdi, available on sourceforge.

The trick with Yamdi is that you need to run it twice. The first time it will incorrectly set a duration and last timestamp of 0, probably reflecting the bad timestamp placed at the end of the file during encoding. However, if you run it again the proper durations and last timestamp values will be inserted in all the proper places.

Gordon

Christian Ebert
Flowplayer support

Posts: 3024

Registered:
May 27, 2008

» Dealing With "Stuck" Videos

Posted: Jun 7, 2009

Reply to: Dealing With "Stuck" Videos, from gmccomb
Reencoding with


ffmpeg -i faulty.flv -vcodec copy -acodec copy fixed.flv

does not lose quality.

I also recommend flvtool++ as it is way faster than other tools I tried, plus it deals correctly with very long videos:


flvtool++ -nomerge faulty.flv fixed.flv

See this page to read more about flvtool++.

gmccomb

Posts: 746

Registered:
Apr 9, 2009

» » Dealing With "Stuck" Videos

Posted: Jun 7, 2009

Reply to: » Dealing With "Stuck" Videos, from blacktrash
Any links to a compiled Windows binary for flvtool++?

Christian Ebert
Flowplayer support

Posts: 3024

Registered:
May 27, 2008

» » » Dealing With "Stuck" Videos

Posted: Jun 7, 2009

Reply to: » » Dealing With "Stuck" Videos, from gmccomb
I don't know; I compiled myself on a Mac. When I had problems I asked directly at the developer's page and Robert came up with a fix a few days later.

Either Google might be your friend, or go ask directly like I did?

gmccomb

Posts: 746

Registered:
Apr 9, 2009

» » » » Dealing With

Posted: Jun 7, 2009

Reply to: » » » Dealing With "Stuck" Videos, from blacktrash
No, I haven't yet asked directly, but nothing readily comes up in a Google search. I might be compelled to try to compile it myself but after finding Yamdi I haven't felt the urgent need.

Now all I need to do is find a better FLV cutting tool than flvtool2. That's also a pretty slow process for bigger files. Unless you know of a reliable ffmpeg string that doesn't cause the 2-4 second "run on" common when encoding FLVs with the -t switch.

Christian Ebert
Flowplayer support

Posts: 3024

Registered:
May 27, 2008

» » » » » Dealing With

Posted: Jun 7, 2009

Reply to: » » » » Dealing With , from gmccomb
Just tried


ffmpeg -ss 31.68 -t 4.44 -i in.flv -sameq -y out.flv

and it seems to work fine.

It might not be a hundred percent frame exact because a keyframe might be needed.

gmccomb

Posts: 746

Registered:
Apr 9, 2009

» » » » » » Dealing With

Posted: Jun 7, 2009

Reply to: » » » » » Dealing With , from blacktrash
I've tried cutting with -sameq in the past and it almost always created larger files. To check again I tried a two minute clip that ffmpeg originally padded with an extra 4 seconds of soundless video at the end. Original filesize was 7.8M; re-pressed with -sameq and cut back to the proper 02:00 the file became 9.4M.

I am also concerned as it is a compression, whereas something like flvtool2 merely chops off the file and re-aligns some of the metadata. This is how the WMV and other cutters work, too, but flvtool2 is much, much slower than the others.

Christian Ebert
Flowplayer support

Posts: 3024

Registered:
May 27, 2008

» » » » » » » Dealing With

Posted: Jun 7, 2009

Reply to: » » » » » » Dealing With , from gmccomb
Yes, -sameq is an overestimated option ;-) But with -vcodec copy it doesn't work of course, reencoding of keyframes is required etc.

FYI, you can't cut with flvtool++ (yet), so no need to worry about compiling it if you need it for this purpose.

Can you cut with yamdi? I don't use yamdi because it messed up metadata, and I did not find out what I might have done wrong.

I guess you'll have to stay with flvtool2 and patience ;-)

gmccomb

Posts: 746

Registered:
Apr 9, 2009

» » » » » » » » Dealing With

Posted: Jun 7, 2009

Reply to: » » » » » » » Dealing With , from blacktrash
I don't give up quite that easily!

You can't cut with Yamdi, but I'm curious what metadata errors you encountered (other than the one I mentioned where the wrong duration is set on the first pass). FLVParser also cuts, and is much faster, though it litters your drive with files -- minor issue but when trying to automate things for people it's an extra step. You have to guess the filenames it uses for the trims and delete those.

Truth is, both FLVtool2 and FLVParser both corrupt the metadata of a cut video and especially with FLVParser you have to pass it through a metadata injector to fix things (it doesn't bother to update any metadata, apparently).

I haven't discovered the source of it, but when you get to the end of a file, then reseek, Flash often thinks you're back at the end of the file again. In my test player I see a Notify on the seek, with a value for Netstream.time equalling the duration of the clip, even when seeking at the middle or start of the file. Weird.

I'd still be interested in testing flvtool++ so I'll probably be setting up a test compile for it in the next day or two. Amazing no one has a pre-compiled version around; I hate working up a new compilation environment just to discover something isn't going to work.

gmccomb

Posts: 746

Registered:
Apr 9, 2009

» » » » » » » » Dealing With

Posted: Jun 8, 2009

Reply to: » » » » » » » Dealing With , from blacktrash
Looks like flvtool++ heavily favors POSIX OS's with some of the .h files it uses, and while I think I can go the Cygwin or MinGW route to try to get a good compile I think I'm going to table the app for a while and get some other work done.

I sort of doubt flvtool++ will be any more successful at really cleaning up these cut files, as the cutting basically corrupts the file, and apparently in a way that the other metadata injectors don't recognize. Looking at these file via flvdump I can't spot any real problem. It's possible that ffmpeg is not properly definining the files structurally and the problem has nothing to do with metadata. I note this happens only when using the -t switch. A straight encode of a whole file doesn't exhibit the problem.

I've also discovered that only *some* files have the 3-4 second soundless padding at the end. At first I thought it might be all converted WMVs, but I have some Windows Media files where the problem doesn't occur.

Certainly another route is to cut them while they're still WMVs. That process is very simple and I already have the programmatic tools for that. The cut isn't frame accurate because as usual it relies on keyframes, but it would only require one compression through ffmpeg. The resulting file doesn't have the unwanted padding at the end so there's no need to cut the FLV, which means it won't have the "early end" problem on replaying.