12

Im trying to make a video (whatever the format) from a directory full of jpeg frames.

I tried with avconv (v0.8), as seen on many topics on the internet, and the libav documentation as well :

avconv -i samples/*.jpeg output.mpeg

It seems to work nicely and create the output.mpeg file.

But the file can't be read by any reader (vlc, banshee, totem,...). No error, but nothing happend when I press Play.

If I check the video file size, it is about 20kB, whereas the original video is 10MB. So we can assume the data has not been stored into the file (it is about 20kB no matter the number of frames given on input)

I made a pastebin of the debug log of the processing. I am not familiar with codec world, so I don't understand many things : http://pastebin.com/9dfxFWZe.

I also try a lot of combinations with -s, -r, -b, -vcodec, -f format, etc.. but the probleme is still there.

Am I doing anything wrong ?

Ask me anything that could help you, I will answer very quickly.

Thank you for your help :)

OoDeLally
  • 514
  • 1
  • 3
  • 20

3 Answers3

10

avconv expects you to give the input filenames in a printf-like syntax. Simply using shell wildcards (such as samles/*.jpeg) is not enough.

Your samples seem to be named sample/lapinsnipermin/.jpeg, so try the following command line:

avconv -f image2 -i samples/lapinsnipermin/%03d.jpeg output.mpeg

Does this work? You might also want to add options for the bitrate (e.g -r 25).

Sjlver
  • 1,120
  • 1
  • 7
  • 22
  • Thank you for your answer. The jpeg files were successfully found, according to the log (see the pastbin posted above from lines 93). I tried many combinations of options, including -r, but no result :( Can you find anything relevant in the log ? Thank you – OoDeLally Jul 22 '12 at 13:25
  • 1
    Also note that when using %03d that there seems to be some constraint, possibly that it starts at zero. Thus, I have images that would match IMG_{2550..2850}.JPG but IMG_%04d.JPG does not work and I must rename my files to start at IMG_0000.JPG. – altendky Sep 16 '12 at 19:14
  • Actually, %03d uses the syntax of the printf function of the C programming language. It translates roughly to zero-filled (0) three-digit (3) decimal (d). You'll need to adapt the pattern to suit your filenames. – Sjlver Oct 23 '12 at 21:35
  • @Elby Sure! Use the -r option to control the bitrate. `-r 25` would give you 25 frames per second. Use smaller numbers to increase playing time. – Sjlver Dec 03 '12 at 16:38
  • My code is shell_exec("avconv -f image2 -r 1000 captcha.jpg outputText.mpg"); i got a out put outputText.mpg but when i tring to play it shows Stream contains no data – Elby Dec 04 '12 at 05:04
  • @Sjlver please answer to my question http://stackoverflow.com/questions/11582624/create-a-video-from-jpeg-with-avconv-corrupted-video – Elby Dec 04 '12 at 05:28
  • @Elby I had a look at that other question. It's hard to give you more information; I'd really need to know the details of your setup. Also, the pastebin link has apparently expired :-( – Sjlver Dec 04 '12 at 17:34
  • ```%03d.jpeg``` works nice if you have ```034.jpeg``` file names, but how you would do if files names like ```15_04_30.jpg``` without batch renaming them? ```%02d_%02d_%02d.jpg``` does not work – Gtx Jan 11 '13 at 04:51
  • 5
    @Gtx What avconv requires is that the filename has a single number somewhere that increases from 0 to #files-1. So this would probably not work unless 15, 04 or 30 is such a number. If you don't want to re-name your files, and you work on a unix environment, you could use the following to create a set of symbolic links: `i=0; for f in *.jpg; do ln -s $f $(printf "%04d.jpg" $i); i=$((i+1)); done` – Sjlver Jan 11 '13 at 09:42
  • Thanks, now it is clear. But i would better rename all my files before process them by ```avconv``` :) – Gtx Jan 11 '13 at 09:48
  • I found what @Sjlver said to be most helpful here - not only does `avconv` seem to require numeric filenames that are monotonically increasing sequential integers (perhaps starting at 0 is a condition too), but it also seems to require a string format specifier like `%04d` be supplied to the `-i` argument, whereas using a wildcard like `*.png` doesn't seem to work. Worse yet, when using something like `*.png` it kind of looks like it's working based on the console output, but the output file is a small unplayable file. – Bryce Thomas Oct 15 '13 at 03:54
5

Resurrecting this since it came up when Googling for a solution. I finally got it working using this:

knoppix@Microknoppix:~$ avconv -r 1 -i /tmp/photo%d.jpg -r 24 -s 320x240 -vsync cfr /tmp/video.mpg

I couldn't get avconv to recognize the input files in the original names; this shows why:

knoppix@Microknoppix:~$ strace avconv -i /media/sdb1/DCIM/188_0408/IMGP%04d.JPG /tmp/video.mpg 2>&1 | grep 188_0408
execve("/usr/bin/avconv", ["avconv", "-i", "/media/sdb1/DCIM/188_0408/IMGP%0"..., "/tmp/video.mpg"], [/* 36 vars */]) = 0
stat64("/media/sdb1/DCIM/188_0408/IMGP0000.JPG", 0xbf925b00) = -1 ENOENT (No such file or directory)
stat64("/media/sdb1/DCIM/188_0408/IMGP0001.JPG", 0xbf925b00) = -1 ENOENT (No such file or directory)
stat64("/media/sdb1/DCIM/188_0408/IMGP0002.JPG", 0xbf925b00) = -1 ENOENT (No such file or directory)
stat64("/media/sdb1/DCIM/188_0408/IMGP0003.JPG", 0xbf925b00) = -1 ENOENT (No such file or directory)
stat64("/media/sdb1/DCIM/188_0408/IMGP0004.JPG", 0xbf925b00) = -1 ENOENT (No such file or directory)
write(2, "/media/sdb1/DCIM/188_0408/IMGP%0"..., 66/media/sdb1/DCIM/188_0408/IMGP%04d.JPG: No such file or directory

I didn't see an option for setting the starting number, so I did this:

i=0; for file in /media/sdb1/DCIM/188_0408/IMGP28*.JPG; do cp $file /tmp/photo$i.jpg; i=$((i+1)); done

The end result is a video of my photos, showing one for each second; the -vsync cfr tells avconv to pad the input frames to match the output framerate.

jcomeau_ictx
  • 35,098
  • 6
  • 89
  • 99
  • 1
    According to [another answer](http://stackoverflow.com/questions/16315192/avconv-make-a-video-from-a-subset-on-images#16402102), since avconv 9.x there is the `-start_number` option. – Thomas W Mar 02 '16 at 09:38
5

I found it better to pipe the jpg file in you want so you can control the selection with standard wildcards, try something like this. This also outputs a video that you can user on the web and mobile (ie. using the standard browser tag):

cat samples/*.jpeg | avconv -r 30 -f image2pipe -codec:v mjpeg -i - -pix_fmt yuvj420p -r 30 -c:v libx264 -vf scale=480:300 -y output.mp4
Ben
  • 1,437
  • 1
  • 10
  • 6