Hi to all
As many of us know, many digital cameras record video in AVI using MJPEG compression - basically a bunch of JPEGs stacked together. Images are compressed *within* frames, presumably by camera hardware. Now for various reasons we may record a video clip in portrait mode and have to rotate the AVI to watch it properly. If we are storing in another format, there are a wide range of tools including VDub. However, a certain amount of recompression is inevitable, with loss of quality.
In theory it should be possible to split the AVI into separate JPEGs, do a lossless rotate and reassemble the JPEGs with no loss of quality.
Now, using lavtrans, (part of the mjpegtools suite of software) to split the AVI, the disassembled jpegs are missing Huffman tables (to save space?) and most image processing software will not touch them.
I managed to modify the source code of sfw2jpg (look for it...) and put in default tables. So now I can view and do a lossless rotate of the JPEGs
Finally, I tried looking for software that can do a simple reassembly of the JPEGs *without* any recompression. Even mjpegtools makes you convert to YUV first
Can anyone please help?
Thanks in advance!
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 1 to 19 of 19
Thread
-
-
Originally Posted by Midzuki
-
Since you seem happy to fiddle with source code, you could use Windows' GDI+ API to do the lossless rotation for you. You could also use the AVIFile API to read and write the JPEG frames as a MJPEG stream.
-
Hi to all
Thanks for the responses, the question is rather academic, as I'm already using VDub with rotate and ffdshow mjpg encoder at the max bitrate - which looks good and fast!
To Johnny, I like to fiddle with code, but not compose it (from scratch that is)
However, when I have time, I'll look into it.
I would have thought a simple reassemble of jpegs into mjpeg would be widely available?
Cheers! -
Hi to all
I'll post some latest findings before I go into hibernation...Here are some results from searching the 'net.
It seems that writing code to get an image into any compressed video format using current Windows codecs, the source must be an uncompressed bitmap.
This makes sense from a general codec point of view, you need a common source from which to process the data.
So if one wishes to append compressed images to a video file without recompressing, we need to construct our own AVI file from scratch - possible but tedious
Cheers -
Originally Posted by kmlee
However, ever since I noticed this thread I've been wondering - how the hell do you do a lossless rotate of a JPEG image? (if I knew that then I could have the tool convert AVI->AVI rather than requiring a list of individual JPEG images). AFAIK, rotating the JPEG means rotating the DCT matrix, and I can't see how you would do that except by decoding and re-encoding - a lossy process (through it could use floating point so the losses would be small).
One thing - my existing code for reading/writing AVIs (bypassing Windows APIs) ignores any audio stream since I don't need audio in my clips. Is this a problem? If so you could always use other tools to demux/remux the audio. -
Lossless rotation (and mirroring) of DCT blocks is possible while staying in the DCT domain. The GDI+ API has functions to do it. The only place losses may occur in the compressed image is in quantization changes between the original and new Huffman encoding.
I would write a DirectShow transform filter to input and output compressed JPEG images. Then it would be a simple matter of using GraphEdit to create a suitable graph to read the existing file, run it through the transform filter and write the new file (mux with the original audio stream if necessary). -
airalaMynnhoJ is right.
http://en.wikipedia.org/wiki/Jpeg#Lossless_editing
A number of alterations to a JPEG image can be performed losslessly (that is, without recompression and the associated quality loss) as long as the image size is a multiple 1 MCU block (Minimum Coded Unit) (usually 16 pixels in both directions, for 4:2:0).
Blocks can be rotated in 90 degree increments, flipped in the horizontal, vertical and diagonal axes and moved about in the image. Not all blocks from the original image need to be used in the modified one.
The top and left of a JPEG image must lie on a block boundary, but the bottom and right need not do so. This limits the possible lossless crop operations, and also what flips and rotates can be performed on an image whose edges do not lie on a block boundary for all channels.
When using lossless cropping, if the bottom or right side of the crop region is not on a block boundary then the rest of the data from the partially used blocks will still be present in the cropped file and can be recovered relatively easily by anyone with a hex editor and an understanding of the format.
It is also possible to transform between baseline and progressive formats without any loss of quality, since the only difference is the order in which the coefficients are placed in the file. -
Originally Posted by JohnnyMalaria
Does anyone actually have any C or Pascal code for a simple 90deg rotate of a simple 8x8 DCT matrix? (obviously if you can do that then you can handle the entire MCU). -
Originally Posted by mpack
-
Irfanview can do lossless jpg rotation in batch mode, it also supports video but I don't know if that's going to apply to flipping a "video" or even what types of tools it has for video.
http://www.irfanview.com/ -
Originally Posted by jagabo
Maybe I should do some experiments (apply FDCT to the same 8x8 matrix at different rotations) to see for myself what the effect is. -
In this context, rotation means +/- 90 degrees, not arbitary angles. Since this thread is about horizontal-to-vertical rotation, it's OK.
-
Originally Posted by JohnnyMalaria
-
After rotating right by 90 degrees the elements are reversed along the (new) X axis. So flip the matrix horizontally:
Of course, this is equivalent to flipping along the diagonal.
Then, if this was the top left block, move it to the top right to rotate its overall position. -
So, has this been solved at all?
I would LOVE to be able to use a tool to turn my movies around the right way.
I am recording some scenic driving with a mount that attaches to the windshield (through suction) and ends up screwing into the little camera, holding it upside down as a result.
@kmlee, can't find your "sfw2jpg" anywhere.
Is it supposed to take an mjpeg .avi and create a bunch of jpegs, without loss of image quality?
Thanks,
a1 -
Hello
Seems like it's not possible
http://forums.virtualdub.org/index.php?act=ST&f=5&t=4796
http://forums.virtualdub.org/index.php?act=ST&f=2&t=8369 -
Actually, they are saying it can be done -- but the JPEG images must be YUV 4:2:0 subsampled (most JPEG files are) and they cannot use custom Huffman tables. I don't know how common the latter is.
Similar Threads
-
How to rotate a MOV file? I just gave up.
By Pixelrage in forum EditingReplies: 10Last Post: 28th Oct 2009, 22:30 -
Rotate Video file from iPhone
By alexs77 in forum EditingReplies: 5Last Post: 31st Jul 2009, 16:13 -
Does an .avi file stay lossless...?
By Slowburn in forum Video ConversionReplies: 1Last Post: 18th Mar 2009, 05:56 -
Rotate .MOV file
By Leo48 in forum Newbie / General discussionsReplies: 6Last Post: 21st Apr 2008, 23:34 -
Need freeware software to rotate avi file.
By Confused Chimp in forum EditingReplies: 5Last Post: 9th Jan 2008, 12:47