PDA

View Full Version : How to cut x264?


aLu
27th March 2007, 00:43
... in whatever container - keyframe-accurate, lossless, visually, like in VirtualDub? Also in HDTV resolutions?
So far as I know, there's only VirtualDub with DTS x264 VfW/ffdshow. And is cutting lossless and accurate - what about the b-frame-as-reference thing?
Is there a tool to mux from other containers or raw x264 to AVI reliably, without having to recreate the index (i.e. AVC2avi) or damaging side-effects? (audio tracks don't have to be included, only for video editing).

LoRd_MuldeR
27th March 2007, 00:51
You can try Avidemux to do this!
It has VirtualDub-like interface, has built-in H.264 support and supports various containers (AVI, MP4, OGM, etc).
Nevertheless frame-accurate cutting is problematic with AVI files...

http://www.avidemux.org/admForum/viewtopic.php?id=768

aLu
27th March 2007, 08:50
I have already tried Avidemux (I'm still), it always wants to rebuild the AVI index, while VirtualDubMOD accepts the file without complaining. I've errorchecked it with Digital Video Repair.

Accurate cutting is "... difficult with AVI files"? Technically maybe, practically to the contrary - AVI tools are the only ones around! MP4/x264 support in Avidemux is very limited, and it can't handle HDTV resolutions (Yamb can't too). I don't know a tool that can open big MKV files.
There are great muxers and demuxers, but no (free) editing tools except for AVI.

So there's still the question how to produce an AVI from raw AVC or whatever. AVC2avi in the latest MeGUI doesn't even support segmented output (-s) any more and produces non-OpenDML files. Reminds me on how Apple used to hand DOS decompressors for its "advanced" packaging tools to the unenlightened Windoze community ... ;-) Old style AVI is REALLY outdated. And really fun to watch VDub rebuild the index for an 8 GB file - I didn't have the patience.

LoRd_MuldeR
27th March 2007, 11:59
The problem with AVI is that it doesn't have native support for B-Frames. So Avidemux cannot tell whether a frame is P or B. In this case Avidemux needs to let the decoder decide, which means it isn't frame-accurate anymore. That's at least how I understood that topic so far.

Furthermore I don't understand why Avidemux shouldn't support HDTV resolutions. I got an HD trailer here at 1920x1088 resolution, the format is H.264 in MP4 and it opens in Avidemux just fine. Of course the preview will be scaled down to fit on the screen (if necessary). I was even able to cut a piece out of that file and the result plays fine.

Last but not least: If Avidemux wants to rebuild the index, than there has to be a reason for that....

aLu
27th March 2007, 12:08
In this case Avidemux needs to let the decoder decide, which means it isn't frame-accurate anymore.
I haven't really done anything useful with Avidemux because it chokes on my 1280x528, ~ 8 GB MP4 file (and always wants to rebuild AVI indexes even if the file is fine). So if it can open large MP4s, how does that frame-accurracy issue work out in a longer file?
With DTS x264 VfW and ffdshow I managed to open the (AVI) file in VDubMOD, and it shows where the keyframes are. But I haven't really started cutting, and I don't yet know how well VDub and the decompressor work together.

Where can you cut h264 anyway without inadvertedly losing extra frames? (B-frames for reference issue)

LoRd_MuldeR
27th March 2007, 14:07
What version of Avidemux did you try?

Please try with latest SVN build if you did not do so:
http://mulder.dummwiedeutsch.de/home/?page=guestbook&app=avidemux&file=latest&mirror=brhack

aLu
27th March 2007, 18:57
I used Avidemux version 2.3.0+. I'll try your version next.

My experiences of cutting in VDubMOD and Nandub so far:
I cut a sequence of garbled and double frames out of a normal size h264 AVI. There seems to be a 1 frame difference in framestepping back and forth. Cutting out everything before a key(I-)frame is no problem. The last frame in the first part - the one before the cut-outs - played fine in VDub only before the two parts were joined, afterwards this frame was slightly garbled. I tried cutting off more frames at the end of part 1 and got it right on the third try (i.e. frame was not damaged after joining). So exact cutting seems only possible by chance - unless you can live with 1 frame of garbage.
I'll have to reencode a few frames though, and so tried the VfW encoder (in Fast recompress mode). Depending on the number of allowed consecutive b-frames - 1, 2 (default) or 3 -, I got zero, one or two black frames at the start of the encoding (marked "D" in the status bar). Then comes a keyframe, this frame is repeated, and from then on it's okay - of course the video ends too early. I counterchecked the setup with Xvid and also used the XVID file as input, it makes no difference.
The "D" frames cannot be gotten rid of once they're there, it seems. Digital Video Repair doesn't find anything defective. And the nasty repetition of the first keyframe doesn't stop in Full processing mode. The good news is that the new and the old encoding can be joined without complaints.

P.S. The "doubled" keyframe is rather a black D-frame in the newest build of VirtualDub (not MOD).

Brother John
28th March 2007, 01:39
Is VDub/VfW able to distiguish between I-frames and IDR-frames? (I'd be a little surprised if yes) If no, that's your likely reason for the garbled frame(s). Probably you cut at a simple I-frame and the next P/B-frame(s) referenced an earlier frame. I suggest you just forget AVC in AVI. It has too many issues.

aLu
28th March 2007, 08:33
I suggest you just forget AVC in AVI.
I'll be happy to, as soon as something else does the trick.

Is VDub/VfW able to distiguish between I-frames and IDR-frames?
I have noticed no damaged frames at the beginning of a cut part. But the "K"-frame interval is about 25-30 frames, so maybe I was just lucky. (I'm an AVC newbie, so when I wrote "I-frame" I meant simply "keyframe".)

I'll try Avidemux again today - on the same file in a MP4 container. One thing I noticed - when it appends AVI chunks cut in VDubMOD, the audio doesn't blend as seamlessly (tho' MOD says the stream lengths match exactly). There is a very short silence at each cut point. No hidden frames pop up (why does the last frame not look garbled before joining?) and the same happens.
BTW: It doesn't re-index these files - because they're OpenDML?

KoD
28th March 2007, 09:23
I believe everybody here will let you agonize until you'll have finally realized yourself VDubMod is not going to work. The alternative Avidemux is not better in many regards either.

aLu
28th March 2007, 09:35
I'm not agonized, but actually having fun - thanks :devil: I'm learning something ...
And it works to 99,8 %.

Brother John
28th March 2007, 17:42
AVC has two types of non-delta frames:
Simple I-frames. Following frames may have references to frames before those I-frame. That means: Cutting on simple I-frames may cause garbage.
IDR-frames. References to earlier frames are not possible. Only IDR-frames are real "keyframes" and suitable cut points.
All of the above (as well as b-frames actually) is a concept completely unknown to VfW. That's why I assume VDub won't distinguish between I and IDR.

foxyshadis
28th March 2007, 19:38
x264 doesn't produce non-IDR I frames iirc. If it does, I've never seen them. Any well-written avi hack would call them delta frames anyway, even if technically they aren't.

bond
31st March 2007, 14:27
x264 doesn't produce non-IDR I frames iirc. If it does, I've never seen them. Any well-written avi hack would call them delta frames anyway, even if technically they aren't.hm, i think its able to write non idr keyframes (not sure tough)