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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
lahabana
Posts: 8
Joined: 2013-04-26T06:41:57-07:00
Authentication code: 6789

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

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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
snibgo's IM pages: im.snibgo.com
lahabana
Posts: 8
Joined: 2013-04-26T06:41:57-07:00
Authentication code: 6789

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

Post 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
Post Reply