Page 1 of 1

convert from multiple format/size to fixed size/format jpeg

Posted: 2013-04-26T06:49:45-07:00
by lahabana
Hi everybody,
I have been fighting quite a lot right now to try to make image magick convert all sorts of images (jpeg, png, gif will be enough) into a jpeg. However this jpeg needs to really standard (sampling, format, resolution...) this because I want to feed the images after to avconv to make a video and it's quite strict regarding to files. Currently this is what I do:

Code: Select all

convert "$J" -background '#000000' -resample '72x72' -resize "640x480" -gravity center -extent "640x480" -sampling-factor '4:2:2' -type TrueColor -quality 75% jpeg:"$J.jpg"
Some of my files are smaller than 640x480 some bigger, I've got some png and a few jpeg coming from different cameras. and this creates files which seem similar (seen from a regular viewer) but avconv refuses them because they don't seem to have the same size/resolution. I this helps here is the error returned by avconv:

Code: Select all

Input stream #0:0 frame changed from size:640x480 fmt:yuvj422p to size:160x120 fmt:yuvj422p
Input stream #0:0 frame changed from size:160x120 fmt:yuvj422p to size:320x240 fmt:yuvj422p
Input stream #0:0 frame changed from size:320x240 fmt:yuvj422p to size:88x128 fmt:yuvj420p
[mjpeg @ 0x101838800] only 8 bits/component accepted
Error while decoding stream #0:0
Input stream #0:0 frame changed from size:88x128 fmt:yuvj420p to size:120x160 fmt:yuvj420p
I have searched more or less everywhere and I don't really know what I am missing so if you could help me it would be perfect.

Thx

Re: convert from multiple format/size to fixed size/format j

Posted: 2013-04-26T06:58:20-07:00
by snibgo

Code: Select all

-resize "640x480!"
(note the exclamation mark) will resize to exactly 640x480.

For other possibilities, see http://www.imagemagick.org/script/comma ... p#geometry

Re: convert from multiple format/size to fixed size/format j

Posted: 2013-04-26T07:17:03-07:00
by lahabana
The problem isn't that all images are not the same size. I have found a solution. The problem was the extra info in the jpeg '-strip' solved the problem. Here is my final command:

Code: Select all

convert "$J" -background '#000000' -resize "$FORMAT" -gravity center -extent "$FORMAT" -strip -sampling-factor '4:2:2' -type TrueColor jpeg:"$J.jpg"
This works with my test files but maybe it will fail in some case. Tell me if I'm missing something thx