Log in

View Full Version : decoding then encoding without losing quality


theophyman
21st April 2010, 15:03
hello,
is it possible to decode a DIVX or XVID video (and do some operations on it,like non linear editing) then encode it again without losing (noticeble) quality?

Inspector.Gadget
21st April 2010, 15:27
Yes. XviD Q2 should be visually transparent to the original in the majority of cases, subject of course to whatever edits you've made.

Blue_MiSfit
22nd April 2010, 00:46
You will always lose quality when re-encoding. This is unavoidable, of course.

However, the amount of loss can be controlled :)

I suggest x264, as its different QP scale gives you a lot more granularity on the high end (and even includes a lossless mode). Even Q2 Xvid introduces visible losses in my opinion, whereas CRF12 - CRF14 with x264 does not (except when pixel peeping).

If has to be MPEG-4 ASP, then you're already set.

~MiSfit

BigDid
22nd April 2010, 02:31
Hi,

I agree with both posters.

X264 would be easier to set for a transparent or lossless encode.

If it has to be ASP, Q2 is needed AND a very good and high bitrate CQM (matrix); besides Didée 6of9 you may want to look at Sharktooth ASP-CQM here:
http://forum.doom9.org/showthread.php?s=&threadid=83125
I would suggest HR or UHR but to test to your needs.

Did

theophyman
6th May 2010, 16:13
ok, thank you all,
my goal in decoding then encoding again was to remeve some unwanted scences from a divx avi video, i found some way to this but it is not perfect, i used virtual dub to split/join video parts.
it worked good,but some time the split operation does not split as desired:when i try to split on frame 15000 for example , it splits on frame 14800 for example.
i think it is related to keyframes, i dont know how to get rid from this problem.

any ideas/suggesions

thank you

Blue_MiSfit
8th May 2010, 06:33
Well... there's a theoretical solution (and practical applications exist for MPEG-2 and H.264, but none I know of for MPEG-4 ASP) - Smart re-encoding!

You're correct in assuming that when doing direct stream copy edits of a long-gop bitstream, one can only reliably cut on I-frames. When using up to a 10 second GOP as is common practice in the ASP / AVC worlds, this usually means an arbitrary edit will NOT work, and you will actually cut (up to) 10 seconds off!!!

Smart re-encoding is "smart" in the sense that it only decodes the GOP containing your desired trim point, applies the trim, and then re-encodes the remaining piece, with settings that adequately match the surrounding region.

Again, not sure if such a thing actually exists for ASP, but I know it certainly does for MPEG-2, and possibly for AVC, but I'm not 100% certain of that.

~MiSfit

AnonCrow
8th May 2010, 09:27
There's even a more theoretical solution for quick&dirty MPEG-2/MPEG-4 ASP/MPEG-4 AVC transcoding (haven't came across any practical solutions for it):
Skip motion motion vector estimation/prediction alltogether, just use (scale if needed) the motion vectors from the source ( a bit oversimplified).
Google for 'mpeg4 transcode by copying motion vectors' and there should be a few hits to different patent abstracts.

Loosely or tightly coupled transcoding, or transrator:
http://www.videsignline.com/212903610?pgno=2

Gavino
8th May 2010, 18:13
Smart re-encoding is "smart" in the sense that it only decodes the GOP containing your desired trim point, applies the trim, and then re-encodes the remaining piece, with settings that adequately match the surrounding region.

Again, not sure if such a thing actually exists for ASP
VirtualDub supports smart re-encoding (they call it 'smart rendering'). I'm not sure if it works for ASP codecs such as Xvid or DivX.
From VirtualDub help file:

When smart rendering is active, VirtualDub tries to copy all the frames verbatim; whenever it detects a violation in frame dependencies, it drops to recompressing frames, and continues to do so until the next key frame, at which direct copying resumes. The recompression of the necessary segments is done by "hot-starting" the video codec for each segment; from the video codec's standpoint, each range to be recompressed is a separate video. The copied and re-encoded sections are then seamlessly joined during the output process.

mariush
8th May 2010, 19:22
It should work with Xvid, haven't tested personally... I think you need to set Virtualdub to at least Normal Recompress mode (if not Full recompress) and enable Smart Rendering. It will copy compressed frames as they are stored up the the iframe before the cut point , decode the frames between the iframe and cut point on one side and does the same on the other side of the cut ... so it recompresses just those frames between iframes.

The alternative would be to select Direct Stream Copy on both audio and video, save the chunks of video you don't wish to edit and then decompress to some lossless format (huffyuv, lagarith), and then recompress these edited parts when you're done - but the encoding parameters must be close if i remember correctly

7ekno
9th May 2010, 01:08
Avisynth Trims() will also get the frames you want, as long as your source filter is frame accurate ...

Tek

Gavino
9th May 2010, 13:10
Avisynth Trims() will also get the frames you want, as long as your source filter is frame accurate ...
Yes, but using Avisynth involves re-encoding the entire output, as it delivers uncompressed video.

However..., one thing often overlooked is that you can use the Avisynth script itself as the output, if all you want to do is play it on your PC. No need to create a new media file, as most media players will accept Avisynth scripts as input.

So, you can create a number of different edited versions with a set of Avisynth scripts, without using up disk space, as long as you keep the original around. Of course if you're doing heavy duty filtering, it might be too slow to play in real time, but for simple edits and adjustments, it's fine.

sneaker_ger
9th May 2010, 13:47
As others already pointed out: VirtualDub's smart rendering will only reencode the parts necessary. Select "fast recompress", "smart rendering" and set the Xvid codec to single pass Q2 and the rest according to the original file. Deleting scenes works fine in "one go" (just mark the scene you want to delete and press "del", then do the same for all scenes you want to delete.) Reordering doesn't work that easy, though. You have to use the append feature for that, which means quite some work.