PDA

View Full Version : Batch convert JPG to x264 and vice versa?


GamesSmash
3rd November 2007, 01:50
Hello fellow x264 users.

I have a lot of pictures on my computer and they take up quite some room. I was wondering if it is possible to batch convert JPGs into x264 with some file extension like .x264 AND be able to convert them back. The only thing I can think of right now is using VirtualDub (with batch encoding into .avi), however this would probably not let me return the images to their previous states.

Does anyone have any suggestions? :confused:
:thanks:

neuron2
3rd November 2007, 02:23
It's not a good idea. H.264 compresses well by using temporal features of the video. You won't be able to take advantage of that if you have a series of unrelated stills.

GamesSmash
5th November 2007, 01:26
But it probably would still be better than JPG compression, ne?

Dark Shikari
5th November 2007, 02:00
But it probably would still be better than JPG compression, ne?Mildly so due to a combination of CABAC and 8x8dct. But to save space, your best method is either to use a compression utility with a built-in JPEG compressor (such as Stuffit, which can compress JPEGs by about 15-20% losslessly) or to reduce the resolution of the images. Encoding them as a video seems very silly to me.

Adub
5th November 2007, 03:27
Dark Shikari is right, single still images to video streams for just the sake of compressing is really not the best choice. Either you try a different format, compress in archives like 7zip or rar, or you buy a bigger harddrive.

They really are getting pretty cheap now. Believe it or not I got a 500gb drive for $90 USD not more than a month ago.

I have never used Stuffit before, but it seems like a good place to start if you are desperate.

raezr
5th November 2007, 17:00
The only way this would make sense is if you created a video by using each of the JPGs as a frame. But either way it's incredibly impractical and a much better idea would be to use something like 7zip or a JPEG compressor as was already mentioned.

Ranguvar
5th November 2007, 20:24
Yup. Also try PNG for pure lossless, or use BZ2 (7-Zip) for very efficient compression on top of what JPEG does. Try JPEG-2000 for a newer, wavelet-based approach to lossy image compression. And, of course, GIF for simple (max 256 colors) lossless.

jethro
7th November 2007, 20:09
Hi,

I've experimented a bit with image compression and x264. I think the quality/size ratio is very promising to say the least.

You can see an exemplary video here (900kb)
http://www.savefile.com/files/1179005


You can modify this simple script below for your needs:

ImageSource("C:\1.bmp", 0, 59,10,true).ConvertToYv12()+\
ImageSource("C:\2.bmp", 0, 59,10,true).ConvertToYv12()+\
ImageSource("C:\3.bmp", 0, 59,10,true).ConvertToYv12()


I also advise you to use TCPMP player as it works very nice for single images.

Dark Shikari
7th November 2007, 21:19
Hi,

I've experimented a bit with image compression and x264. I think the quality/size ratio is very promising to say the least.

You can see an exemplary video here (900kb)
http://www.savefile.com/files/1179005


You can modify this simple script below for your needs:

ImageSource("C:\1.bmp", 0, 59,10,true).ConvertToYv12()+\
ImageSource("C:\2.bmp", 0, 59,10,true).ConvertToYv12()+\
ImageSource("C:\3.bmp", 0, 59,10,true).ConvertToYv12()


I also advise you to use TCPMP player as it works very nice for single images.I would suggest you use 8x8dct in your commandline; it will help you considerably.

jethro
7th November 2007, 22:20
I would suggest you use 8x8dct in your commandline; it will help you considerably.

thanks Dark Shikari but I've re-checked and it did not make any difference.

I use megui for this. the commandline from megui...


--qp 26 --deadzone-inter 6 --deadzone-intra 6 --no-fast-pskip --nf --subme 7 --analyse --8x8dct --me dia --merange 4 --threads auto --thread-input --progress --no-dct-decimate --output "output" "input"


is no different in effect than without --8x8dct.


Edit:
and "--analyze all" even bloats the size.

Dark Shikari
8th November 2007, 05:53
thanks Dark Shikari but I've re-checked and it did not make any difference.

I use megui for this. the commandline from megui...


--qp 26 --deadzone-inter 6 --deadzone-intra 6 --no-fast-pskip --nf --subme 7 --analyse --8x8dct --me dia --merange 4 --threads auto --thread-input --progress --no-dct-decimate --output "output" "input"


is no different in effect than without --8x8dct.


Edit:
and "--analyze all" even bloats the size.Increased size doesn't mean worse; if size increases by 5% but quality increases by 10%, you've done good, right?

Anyways, you can vastly speed that up by putting --subme to 1, since you're dealing with all intra frames. Remove --no-fast-pskip, deadzone inter (since you have no inter blocks), and so forth. I'm not sure about disabling the inloop deblocker though.

toytown
8th November 2007, 12:10
I counted 4 pics in that video and a filesize of 903KB. Given the resolution of 1408 x 1056, i really dont think you are gaining much, if anything at all by converting it to AVC, you may as well just re-save them as JPEG or JPEG2000.

I took a frame from your video and then converted it to JPEG at a file size of 225KB (903KB/4 pictures), comparing the 2 pictures i couldnt make out any real differences. If i had made the JPEG from the original source and not your MP4 file, im pretty sure you wouldnt be able to tell the difference either.

What you are doing, comes with a long list of cons including
- Making searching for pictures a complete nightmare
- No way to return the filenames to normal
- Complete removal of image META TAGS.
- No easy way to share them between devices, such as mobiles etc
- No easy way to add the picture to an email

I just cant think of a single reason why i would do this.

Irakli
8th November 2007, 15:05
IMHO, resaving to JPEG2000 is the best option since in my experience quality is much higher than JPEG.

Regards,
Irakli

P.S.: I just wonder why JPEG2000 is not widely used nowadays considering it's advantages over JPEG...

Adub
8th November 2007, 19:32
jpeg is just so largely excepted as a format that it will take a while before jpeg2000 can replace it completely. Although I totally agree with you about it's advantages.

Irakli
8th November 2007, 20:02
I just really hope that it will be JPEG2000, not Microsoft HD Photo, that will replace JPEG.

Atak_Snajpera
8th November 2007, 20:13
I just wonder why JPEG2000 is not widely used nowadays considering it's advantages over JPEG...
You could also ask why mp3 and AC3 are still used if we have new better formats like ogg or aac? :)

In my opinion Jpeg2000 is not better than old jpg. I made few test and sometimes jpg2000 looked less sharp due to implemented "deblocking"
Microsoft's format is a joke... Tests show no advantage over "old technology"

jethro
8th November 2007, 23:31
@Dark Shikari

Increased size doesn't mean worse; if size increases by 5% but quality increases by 10%, you've done good, right?

Yes, but i looked at the PSNR/SSIM too, it was basically the same.

Anyways, you can vastly speed that up by putting --subme to 1, since you're dealing with all intra frames.
I certainly can't tell you why, but quality in metrics drops and filesize increases with subme 1.
Besides the point I think is to make it slower (better), images compress fast enough.

Remove --no-fast-pskip, deadzone inter (since you have no inter blocks), and so forth. I'm not sure about disabling the inloop deblocker though.

--no-fast-pskip very sligthly changes output, probably does not matter. Deadzone inter, yes tried it and no difference. About inloop I'm not sure too but i like to set it less agressive than I would for movies.

jethro
9th November 2007, 00:46
@ toytown
I counted 4 pics in that video and a filesize of 903KB. Given the resolution of 1408 x 1056, i really dont think you are gaining much, if anything at all by converting it to AVC, you may as well just re-save them as JPEG or JPEG2000.
Afaik the pictures were JPEGs (already compressed), also resized and sharpened for the video. The video you have is just a stupid example... It did not mean to be anything breathtaking.

I took a frame from your video and then converted it to JPEG at a file size of 225KB (903KB/4 pictures), comparing the 2 pictures i couldnt make out any real differences. If i had made the JPEG from the original source and not your MP4 file, im pretty sure you wouldnt be able to tell the difference either.

I agree JPEG is very good. At --qp26 (23 quant in fact) the picture quality is very good for x264 also. If you go higher like --qp35+ you'll see that JPEG at these sizes is a lot less pleasing (nasty blocks show up, more mosquito noise, bigger ringing/halos) and x264 usually just blurs the picture a little.

I strongly encourage you to try and compare some of your images on various compression levels (JPEG vs J2k vs x264). Also please try lossless.

What you are doing, comes with a long list of cons including
- Making searching for pictures a complete nightmare
- No way to return the filenames to normal
- Complete removal of image META TAGS.
- No easy way to share them between devices, such as mobiles etc
- No easy way to add the picture to an email

It is just experimenting... about what you wrote:
1. Not sure what you mean, but if you refer to bundling many pictures in one video and then looking for one particular picture in there - just encode each image separately. And as I written before - TCPMP player makes a nice "viewer for these "images" (just not too large).
2. Really don't understand.
3. If existed and afaik its JPEG and JPEG-2000 mostly? I never cared about meta data in images, but yes, you're right.
4. I'm not versed in mobiles but bluetooth?
5. How is it different than attaching a zip file?


I just cant think of a single reason why i would do this.
First real use for this that comes to my mind is a compilation of images you made on some occasion (like trip/wedding), then you add some avisynth effects and transitions between images (like the ones on vcmohan's site), maybe music and after you're done send it to somebody. Now you :)


IMHO quality/size ratio for x264 is better that jpeg or j2k for most images. Don't know how hard it is but 4:4:4 for true lossless would be very nice...

toytown
9th November 2007, 13:57
- No way to return the filenames to normal

Well you mentioned that you would be converting a whole set into a single file (perhaps with music), if you ever wanted to get the original file names back, then your out of luck. We have a big personal online gallery with all our family images and everybody references a picture by its filename. Of course if you make a single frame mp4 then thats different and the point becomes moot.

I'm not versed in mobiles but bluetooth?

I meant that typically most mobiles etc JPEG nowdays and will display it (and resize to screen), so right now i can send any image i have to anybodies mobile phone/PDA etc and they can see it immediately. If they want to print it out or look at it on an pc, then same goes. With MP4/AVC especially with options for high quality, then most mobiles wont play it and most PC's wont have the codec to watch your video.

How is it different than attaching a zip file?

Its no different, except im sending single JPEG images of exactly what i want, every PC out there has the ability to display this. Every online printing facility will accept this.

What happens when you send an mp4 and it doesnt display on there end? You tell them to download an MP4 decoder? Most people wouldnt even bother and tell you to send the picture in a proper format. Which means reconverting the image back to JPG.

First real use for this that comes to my mind is a compilation of images you made on some occasion (like trip/wedding), then you add some avisynth effects and transitions between images (like the ones on vcmohan's site), maybe music and after you're done send it to somebody

The problem with that is it becomes a ballache to transfer to anybody, email wise your still going to be stuck with smtp servers balking at 10MB+ posts and people who only want to see specific images have to download the whole lot and fast forward through a video (assuming they bother to install an MP4 decoder) to get to the images they want.

Now you, IMHO quality/size ratio for x264 is better that jpeg or j2k for most images

It just seems to be a totally useless idea, you are basically taking something which can be shown on thousands of different devices worldwide (with no extra software) and is an accepted standard for almost anything regarding photography/printing and throwing it all away in the vain effort to save yourself some cents/euro cents.

With my Ixus taking images at the full 10Megapixel i can store between 140,000 to 180,000 pictures on a £55/78E/$115 Harddrive, with no loss of quality from the original picture.

If you gained an extra 25% storage space and could get 200,000 images on the harddrive now, is all that extra hassle worth the £14/20E/$28 you have saved? Converting to H264/AVC will allow me a few thousand more pics at best, with a loss in quality from the original, is it really worth doing, for the time and everything you lose by dropping JPEG?

GamesSmash
13th December 2007, 03:24
Well, what I had in mind really, was that if some talented programmer out there could make a ".xpic" format or something that are just .jpg's compressed with x264.

Now instead of having to difficultly locate images to save a bit of space turns into easily locating images with a lot of space saved!

What do you guys think about this?

fields_g
13th December 2007, 23:37
Well, what I had in mind really, was that if some talented programmer out there could make a ".xpic" format or something that are just .jpg's compressed with x264.

Now instead of having to difficultly locate images to save a bit of space turns into easily locating images with a lot of space saved!

What do you guys think about this?

No.... still a bad idea. h.264 is a codec that likes MOTION, preferrably predictable motion. JPEG images are almost always NOT sequences of motion. If you are really hard up for space,

a) Use a greater JPEG compression ratio
b) Use a program to losslessly compress JPEGS (eg. Stuffit)
c) Reduce image resolution
d) Use a different codec (eg. JPEG2000)
e) Buy a hard drive
f) Any combination of the above

Locating images? How about folders? How about albums that allow tagging? By converting to video, you loose your filenames and exif info. This is not going to help you.

Let picture compression be picture compression and video compression be video compression. They just don't efficiently mix.