Log in

View Full Version : Any way to just skip defective frames?


theReal
10th August 2002, 14:18
Since I'm using avisynth 2.04, when encoding tv-captures to Realmedia 9 I get one or two errors on every encoding because of one or two defective frames in the capture (Avisynth returns an error message and stops decoding)

The way I'm "solving" the problem right now is to skip the frame that could not be encoded by using trim commands, but this isn't exactly a very easy solution. Maybe there's a command to tell avisynth to just skip a defective frame and go on with the next? Or maybe repeat the last frame instead of the defective frame to stay in sync? However it wouldn't matter for the Simpsons to just skip one frame including the audio.

I don't know where these defective frames come from, but when I open the files in VDub, these frames are shown as D-frames, while it should be all Key-frames (the files are MJPEG, YUY2). Also they are not shown in the VDub preview, so VDub can't decode them neither (but doesn't care and just goes on with the next frame - and I would like avisynth to do the same!)

I'm not sure if this problem is a new problem with my captured files or a problem with the new version of avisynth (and maybe older versions just skipped un-decodable frames by default).

Any help appreciated. Maybe I can prevent those frames from being copied with direct stream copy in VDub, that would be a good solution as well because I'm direct-stream-copying all of the files before encoding anyways (I know I can manually cut them out in VDub - the problem is how to find those frames. Right now I only find them as soon as avisynth says "can't decode frame 2345").

Richard Berg
10th August 2002, 14:29
The easiest solution is to use one of the simple standalone programs hosted here like "DivxFix" (I think that's the name). For curiousity's sake, consider trying HuffYUV or a different MJPEG codec to see if that eliminates the corruption.

hakko504
10th August 2002, 15:07
You could use the command FreezeFrame([clip],first-frame,last-frame,source-frame) to accomplish this. Say frame 2345 is defective and you wish to replace it with the previous one. Then your command would be FreezeFrame(2345,2345,2344).

trbarry
10th August 2002, 15:35
I wonder if it would be possible for Avisynth to have a filter that would trap those "can't decode" errors and just substitute the previous good frame?

Anybody know enough about how this works?

- Tom

theReal
10th August 2002, 16:18
Richard, DivFix doesn't find any errors. When I rebuild the index with DivFix, the index is stripped and not rebuild correctly (only works for Divx?). VDub can rebuild the index, but then the corrupt frames are marked as D-Frames again. The files play in Mediaplayer, there are no frozen frames. In VDub in the preview the previous frame is shown again (just like I'd like avisynth to do it...).

hakko504, that's better than my method (I make two or more clips with trim() and leave out the corrupt frame(s) )
BUT, it's still not good because I have to know the bad frame number(s) first. For that, I have to encode the Realmedia File, then see if it's 100MB, like it should be, or if it's smaller. If it's smaller that means: avisynth error occured. Open the Realmedia file, forward it to the avisynth error message. Get frame number from that message, change the avisynth script accordingly. Encode again, wait for another 1 two 2 hours, then see if the file is 100MB now. If it isn't, open it, forward to the avisynth error message, get the next corrupt frame number, change the avisynth script accordingly...

You can imagine that with this method, 24 hours a day is not enough for encoding two of these files per day (and that's what I'm doing).
I really need uninterrupted batch-encoding. All I want to do is trim the commercials from the capture, then start my batch script (it executes the VDub job list that saves the clips without commercials, then encodes the files to Realmedia).

I think I will try HuffYUV instead of MJPEG (I just added two new 120GB 7200Rpm drives, so I have enough place to do that)

trbarry, it would be really great if you'd want to write something like this :)
Unfortunately my own programming skills end with batch scripts and "hello world" ;)

dividee
10th August 2002, 16:46
Is the error you get this one:
"AVISource: failed to decompress frame 2345 (error x)"
If that's the one, what is 'x' ?
It should be easy to return the last good frame instead of throwing this error. However, for codecs that are not all-keyframes, it would cause all frames till the next keyframe to be freezed, I guess.

theReal
10th August 2002, 18:53
I'm not at my own computer right now, so I can't look, but I think it is "error -369". Does that make any sense? I'll be back home on Monday, then I can check for sure if it is -369

btw is there any reference to look up what these error codes mean?

trbarry
10th August 2002, 19:49
trbarry, it would be really great if you'd want to write something like this ;)
Unfortunately my own programming skills end with batch scripts and "hello world"

TheReal -

I'm afraid my own knowledge of Avisynth error handling is not good enough for me to do this either. But I was hoping some other clever individual could be inspired to do this. ;)

But I guess the main issue is whether it would be possible to get past the error. Sometimes a codec might just decide all was lost after one of these errors. But as long as it would pick up after the error record or even at the next key frame then I guess all would not be lost.

I've had similar cases with MPEG2DEC where it will blow up on a few records of my ATSC HDTV captures. There are always some garbage frames in those. At home I can run a version of MPEG2DEC.dll I wrote that traps the error and properly returns a garbage frame, instead of dying.

But I haven't released that version since it will for some reason only run when compiled for debug and pretty reliably will cause Vdub to crash when you finally exit. But sometimes something like this is the only way to get through the whole clip.

- Tom

WarpEnterprises
10th August 2002, 21:31
As I did in another thread you should verify that it's not audio related (and a Dropped frame for sure has some implications on audio too.).
Maybe someone can post a mini-avi with 3 frames before and after the defective?

theReal
11th August 2002, 11:14
I will upload a small part of the avi tomorrow (and I'll also check what older versions of avisynth will do with the same files - it seems that some more people are getting AVISource errors with 2.04)

Richard Berg
11th August 2002, 15:14
The files play in Mediaplayer, there are no frozen frames.
Maybe try DirectShowSource?

Didée
11th August 2002, 21:19
theReal,

in the past I´ve had some great fights with those [D]´s, and my poor keyboard had danger of life, after uncounted crashed encodings, because of those [D]´s.

For me too, it was simply audio related.
My soundcard (and another one, and a third one) was a little bit too slow, therefore the encoder had to insert frames, speak double frames, to wait for audio to synch up. Those doubled frames were report as [D], but it was [D]oubled, not [D]ropped ...
None of all the existing variations of Vdub did clear this problem completely - now I own a Santa Cruz ;), and all problems are gone.

The interesting point is:
AviSynth only was unable to decode those [D]´s when I captured to XviD.
Capturing to Huffyuv, I had similar [D]´s, but those get decoded by AviSynth without any problem.

Anyways, it would be really great to have AviSynth managing bad frames correcly! Lately, I had ~80 GByte of HDspace blocked for more than a week, only because of a single bad frame :devil: ... and I was much too busy with life to figure it out just in time, and I ran totally out of HD space. That was not jokey.

Si
12th August 2002, 00:32
Just for a bit of historical info - Avisynth used to deal with these dropped frames "reasonably" in v0.3 and 1.0 but Ben decided that they should throw an error in 1.0b2.

"AVISource now reports decompression errors (as it was supposed to) instead of returning a blank frame."

I emailed him about it but off he went into the sunset....

For info, I get these using WinTV card and the PICVideo MJEPG codec- I don't get them with Huffyuv captures.

The normally excellent people at PIC aren't interested in the problem and I just lived with using 1.0 and having to not use any later versions. I'm sure others just gave up on Avisynth completely :-(

The "faulty" frames have a zero length if you look at the avi file using John McGowans vidtrace prog.

I don't know if anyone could compare the diffs between 1.0 and 1.0b2 and see what could be done.

I've attached my sample error.avi - the drop is at Frame 3.

This is my 1st post so apologies if I've not followed the rules/etiquette!

regards
Simon
PS Keep up the good work on developing V2.
Don't know where the attachment went (must read instructions again!)
- the files at http://www.geocities.com/siwalters_uk/error.zip

dividee
12th August 2002, 01:20
Welcome Simon. I saw you were editing the Wiki and I wondered who you were. Now my curiosity is satisfied :)

Now that you mention the previous behaviour of AVISource I remember I read something about it on Ben's Site... Yes I just found it back.
(here (http://math.berkeley.edu/~benrg/avisynth-beta.html)). It shouldn't be too hard to revert to the previous behaviour (or better, duplicate the previous frame instead of returning a blank one).

PS: attachments needs to be validated by a moderator before showing up, but in your case i can't see any attachment. And the link you provide doesn't seems to work. Doesn't geocities prohibits direct linking ?

WarpEnterprises
12th August 2002, 07:45
.And the link you provide doesn't seems to work. Doesn't geocities prohibits direct linking ?
If you cut&paste the link it works

Si
12th August 2002, 10:52
Originally posted by dividee

PS: attachments needs to be validated by a moderator before showing up, but in your case i can't see any attachment. And the link you provide doesn't seems to work. Doesn't geocities prohibits direct linking ? [/B]

Trying to attach again - I've put d:\Yahoo\error.zip in the Attach file: box - lets see what happens - ah got it - I previewed this reply (as I did the 1st time) and I now see that the attach file: box gets wiped :-( So I'll now re-enter it and I'll bet it works (Whats the chances of hitting a bug in the forum on 1st go!!!!)

BTW I can right click the embedded link and download the file but maybe that's specfic to my browser(IE6)

dividee
12th August 2002, 11:32
Now it works :)
But WarpEnterprises solution worked too (thanks Warp, I should have known that).

Guest
12th August 2002, 13:44
Simon is a long-time contributor to the Usenet newsgroup rec.video.desktop, where he is a really great resource. It is really fantastic to see him here.

Welcome aboard, Simon!

WarpEnterprises
12th August 2002, 21:31
With Simon's hint I have located an error I mentioned some time ago.
Try this script:

V=AviSource("d:\avitest\125.avi")
A=WavSource("d:\avitest\tone5000ms.wav")
AudioDub(V, A)
DelayAudio(1)

where 125.avi is 125frames@25fps and tone5000ms.wav is 5s@44100
(although this doesn't matter)

Due to the DelayAudio with a positiv value Avisynth (>1.0) crashes.
Negative values are ok.
And v0.3 works too.
But not always is an error reported
("Avisynth read error: Avisynth: caught an access violation at ...")
Sometimes (other VD-operation, some filters after DelayAudio,...) VD/TMPG,... crashes completely.

This is very annoying - how else could you correct a positive audio delay?

dividee
13th August 2002, 05:50
By pure luck, I just found out why the dropped frame bug reappeared in 2.04:
when I added compressed audio support to avisynth, I also took the occasion to update the avi stream reader with the latest version from virtualdub (as this part comes straight from vdub). Part of the dropped frames workaround that was introduced in 1.0beta5 (I think) was in there and I didn't see it.
I found out by browsing the avisynth-dev mailing list archive. Back then, Avery suggested a better solution than the one that was implemented (the fix was quite ugly). This will be fixed in the next build. Meanwhile, if you encounter this bug go back to 2.03.

@WarpEnterprises:
this DelayAudio bug shouldn't be too hard to fix. Thanks for reporting it.

theReal
13th August 2002, 05:54
I wasn't sure - but one of my captured files has worked with avisynth 2.03. I wasn't sure if the file was just ok, or if it was due to avisynth 2.03.

Thanks very much! I'll stay with 2.03 until the next release or so :)

Si
13th August 2002, 11:09
Originally posted by dividee
[B]By pure luck, I just found out why the dropped frame bug reappeared in 2.04:

Part of the dropped frames workaround that was introduced in 1.0beta5
Where was the fanfare when Edwin fixed it (in beta4 it seems now I've done a test)

I must have not installed it properly at the time :o

Simon

1loser
29th September 2002, 22:42
Originally posted by hakko504
You could use the command FreezeFrame([clip],first-frame,last-frame,source-frame) to accomplish this. Say frame 2345 is defective and you wish to replace it with the previous one. Then your command would be FreezeFrame(2345,2345,2344). I had 13 bad frames in my source vob file. Using the command: FreezeFrame(98054,98066,98053) solved the problem by replacing the 13 bad frames with one good frame. The nice part is that the audio will still be in sync.

Reading through these posts really helps.
Thanks for the suggestion.

Didée
30th September 2002, 02:10
1loser,

while you´re at it, why not doing
dissolve( trim(0,98053,98053).loop(14,98053)
\ ,loop(14,98067,98067).trim(98067,0)
\ ,13
\ )

:)

1loser
30th September 2002, 12:03
Originally posted by Didée
1loser,

while you´re at it, why not doing
dissolve( trim(0,98053,98053).loop(14,98053)
\ ,loop(14,98067,98067).trim(98067,0)
\ ,13
\ )

:) I could try this but it would be nice to know what it does.

Thanks

Didée
30th September 2002, 16:58
It performs a smooth blend from last-intact-before-broken to first-intact-after-broken.
In the cases I have to skip defective frames, I do it always like this.

:) read the documentation ;)

Regards

Didée