Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to write a script that should take all sort of images (format, size...) and create a video with avconv. I've managed to make it work with a series of jpg (all the same size though) and I'm now trying to use convert to make sure it will create the video by making all images similar in size and format. Here is how I do it:

(for J in $(ls "$1/"* 2> /dev/null); do
     convert "$J" -resize 640x480 -gravity center \
             -size "$FORMAT" -fill black -extent 640x480 jpg jpeg:-
done) | avconv -f image2pipe -r 1/5 -c:v mjpeg -i - \
               -vcodec libx264 -r 20 -f mpegts video.mpeg

I've got a series of images where avconv returns:

Input stream #0:0 frame changed from size:640x480 fmt:yuvj420p 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've checked and the image looks ok when I'm just using convert. I guess I am missing something in convert to make the image perfectly identical for avconv to work. But I can't really find it

Thx for your help!

EDIT

So after investigating this seems to be cause by the output images not having the same resolution and/or sampling ratio. So I've tried this:

(for J in $(ls "$1/"* 2> /dev/null); do
    convert "$J" -background '#000000' -resize "640x480" 
                 -gravity center -extent "640x480" -sampling-factor '4:2:2' 
                 -resample '72x72' jpeg:-
done) | 
avconv -f image2pipe -r 1/5 -c:v mjpeg -i - 
       -vcodec libx264 -r 30 "foo.mpeg"

Still no success though...

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

pipe:: Input/

Here are the image I use:

Hope this helps...

share|improve this question

1 Answer 1

up vote 1 down vote accepted

After a lot of search I finally found something working (at least with my few test files):

convert "$J" -background '#000000' -resize "$FORMAT" \
        -gravity center -extent "$FORMAT" -strip \
        -sampling-factor '4:2:2' -type TrueColor jpeg:- | \
avconv -f image2pipe -r 1/"$DURATION" -c:v mjpeg -i - \
       -vcodec libx264 -r 20 -f mpegts "$RESULT_FILE"

The important options are:

  • -strip removes all extra info from the input (I had for example Color profile or some EXIF data) this was causing problem to avconv apparently
  • -sampling-factor '4:2:2' This fixes jpeg sampling factor to 4:2:2 (If you think there is a wiser choice than 4:2:2 please tell me)
  • -type TrueColor this is untested but an image in gray scale will have a different format which will be kept in jpeg this options forces to convert into TrueColors so that all images use the same color coding.

This solved my problems ftm. Please tell me if you see anything else... Thx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.