Welcome Guest ( Log In | Register )


Important

The forums will be closing permanently the weekend of March 15th. Please see the notice in the announcements forum for details.

 
Cropping Interframe Encoded Video, without re-encoding
« Next Oldest | Next Newest » Track this topic | Email this topic | Print this topic
Sarreq Teryx
Posted: Dec 31 2002, 07:14 AM


VirtualdubMod Alpha tester


Group: Vdubmod Alpha Testing Team
Posts: 175
Member No.: 41
Joined: 16-July 02



2 things, both questions about any interframe encoding codec (mpeg-1,2,4, tarkin [I'm guessing], etc.)

1. 3d frame (temporal) cropping:
Is it possible to make a program able to clip out frames from a file, precise to the B-frames, by having the program reconstruct an I-frame and replace the P or B-frame it's been reconstructed from, so that when played back it's not screwed up, and can be re-assembled without having 2 frames with the same exact data, without fully recompressing the file. I'd guess the related codec would have to be used to create the single frame (or multiple for cutting in multiple positions in the file)

2. 2d frame (picture) cropping
cropping horizontally and vertically without re-encoding, can it be done? I'd guess, if yes, it'd have to be only macroblock (cutting off in 8 or 16pixel increments) precise.

--------------------
And as I walk through the Valley of the Shadow of Death, Lord, thy balls and shaft, they comfort me, you annoint my head with oil, some salt, a dash of pepper, a sprigg of parsley......Lord?............Lord??? What dost thou intend to do with that fork???
 
    Top
phaeron
Posted: Dec 31 2002, 08:48 AM


Virtualdub Developer


Group: Administrator
Posts: 7773
Member No.: 61
Joined: 30-July 02



Time cropping is doable for MPEG-1 if you are replacing a P-frame, but you have a major problem -- I-frames are a lot bigger than a P-frame, and are even bigger when used to emulate the image of one (you would have to encode a very high quality frame to avoid screwing up subsequent predictions). If you are editing a CBR file, such as a VideoCD file, you would have a hard time making an I-frame that didn't have too much error and also stayed within the VBV buffering parameters of the stream. For VBR streams or CBR streams that can be reinterleaved, I wouldn't be surprised if that's how most MPEG-1 editors work. This would probably be doable for DivX 5 if the codec can be told to encode a matching high-quality I-frame, since the codec doesn't ever backwards predict from an I-frame, even in B-frame mode. I'm not very confident in this since the codec seems rather prone to crashing whenever you mess with its streams. That the codec doesn't have a public API for setting advanced parameters makes it more difficult to do this automatically.

Nonzero motion prediction vectors make the 2D cropping idea very difficult -- even in MPEG-1 the prediction window can be as large as 63.5 pixels, and thus you may end up having to reencode half the next P-frame and all of the subsequent one. Which means that reencoding the whole GOP is probably easier than trying to selectively reencode, making sure you're still under bitrate, warding off low quality turds, etc. The idea is suitable for JPEG, however, and several utilities exist that can do lossless block-boundary crops, right-angle rotates, and flips of JPEG images.
 
    Top
Sarreq Teryx
Posted: Jan 1 2003, 11:48 PM


VirtualdubMod Alpha tester


Group: Vdubmod Alpha Testing Team
Posts: 175
Member No.: 41
Joined: 16-July 02



QUOTE
Time cropping is doable for MPEG-1 if you are replacing a P-frame, but you have a major problem -- I-frames are a lot bigger than a P-frame, and are even bigger when used to emulate the image of one (you would have to encode a very high quality frame to avoid screwing up subsequent predictions).
I really wouldn't mind having 1 gimungous I-frame (out of a possible ~several thousand frames for a couple of hours), if it meant I could cut presicely where in the file I wanted without a full re-encode. That divx5 problem sounds nasty though.
QUOTE
Nonzero motion prediction vectors make the 2D cropping idea very difficult -- even in MPEG-1 the prediction window can be as large as 63.5 pixels, and thus you may end up having to reencode half the next P-frame and all of the subsequent one.
nuts dry.gif



--------------------
And as I walk through the Valley of the Shadow of Death, Lord, thy balls and shaft, they comfort me, you annoint my head with oil, some salt, a dash of pepper, a sprigg of parsley......Lord?............Lord??? What dost thou intend to do with that fork???
 
    Top
fccHandler
Posted: Jan 2 2003, 03:32 AM


Administrator n00b


Group: Moderators
Posts: 3961
Member No.: 280
Joined: 13-September 02



QUOTE
I really wouldn't mind having 1 gimungous I-frame (out of a possible ~several thousand frames for a couple of hours), if it meant I could cut presicely where in the file I wanted without a full re-encode. That divx5 problem sounds nasty though.

I've never had problems cutting or joining DivX files as long as the cuts are on key frames. If I needed to cut from a non-key frame, what I would do is recompress only the portion up to the next key frame, and append the remainder losslessly.

BTW, is there any reason lossless frame cropping / rotating / flipping wouldn't work for MJPEG movies? What about DV movies?

(just thinking aloud) smile.gif

--------------------
May the FOURCC be with you...
 
     Top
phaeron
Posted: Jan 2 2003, 05:44 AM


Virtualdub Developer


Group: Administrator
Posts: 7773
Member No.: 61
Joined: 30-July 02



The main problem with rotating MJPEG and NTSC DV is that losslessly rotating the frame also rotates the chroma subsampling. Rotating an image that is chroma subsampled 2:1 horizontally produces 2:1 vertical subsampling, which can be handled by JPEG viewers but usually not MJPEG. Motion JPEG can be written in the non-standard 4:2:0 or 4:4:4 formats, and software decoders will accept it, but hardware is pretty likely to balk unless the frames are standard 4:2:2. I don't think PAL DV has a problem since it is 4:2:0 instead of NTSC's 4:1:1.

Cropping and flipping should be OK, but the granularity is pretty large for cropping: 16x8 for standard MJPEG and 16x16 for interlaced. I don't know the DV format, so I can't comment on it.
 
    Top
Sarreq Teryx
Posted: Jan 2 2003, 07:43 AM


VirtualdubMod Alpha tester


Group: Vdubmod Alpha Testing Team
Posts: 175
Member No.: 41
Joined: 16-July 02



QUOTE
I've never had problems cutting or joining DivX files as long as the cuts are on key frames. If I needed to cut from a non-key frame, what I would do is recompress only the portion up to the next key frame, and append the remainder losslessly.
but that still involves re-encoding an entire portion of video, taking up plenty of time, and degrading the quality of that portion if you use the same or lower bitrate, and inflating it if you use a higher one. If it can be cut at the p and b-frames, and just encode that single first and/or last frame as an I frame, whether it's huge or not, it still doesn't take up as much space or kill the quality as fully re-encoding that segment would, and should definitely be much faster.

--------------------
And as I walk through the Valley of the Shadow of Death, Lord, thy balls and shaft, they comfort me, you annoint my head with oil, some salt, a dash of pepper, a sprigg of parsley......Lord?............Lord??? What dost thou intend to do with that fork???
 
    Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
5 replies since Dec 31 2002, 07:14 AM Track this topic | Email this topic | Print this topic

<< Back to VirtualDub Development Forum