I am running Ubuntu 10.04. I have generated a series of images in pbm format and I want to convert them to a movie file. I dont particularly care which format as long as it is widely used. I have 100 files in a directory, named 0.pbm to 99.pbm. I want to create a video, using these images and at 30 fps, and at as high of quality as possible. As I understand it, this functionality is available in the netpbm program, but I am not very familiar with using the terminal and I dont understand what I need to type in the terminal to get this to work. To get the reward, please explain what I need to type and also a little why - I want to learn a little about using the terminal here as well. You can check my history and see that I have already paid out on two different bounties like this, so I can assure you I will pay up if you help me. Thanks in advance.

You'll most likely use the bash shell. That shell is not simply a terminal, but it also contains a pretty much complete programming language, so you can write (shell) scripts with it!

The line:

for f in *pbm ; do convert -quality 100 $f `basename $f pbm`jpg; done

is such a (small) script.

The shell expands *pbm to the list of pbm file in your directory, so it evaluates to

0.pbm 1.pbm 2.pbm ...

The 'for' commands lets you loop over this list of filenames, so the variable f becomes one of the filenames in each iteration. During the first loop iteration f is 0.pbm, then it's 1.pbm etc.

The 'do' part simply describes what to do in each loop iteration. So we call a program called 'convert', which is part of the imagemagick package and converts image files. So in the first iteration, we call

convert -quality 100 0.pbm 0.jpg

, because $f simply means 'the value of f' , which is 0.pbm at the time. `<command>` is a construct to run a command and use it's return value. So basename is just a program to a) remove a path from a filename andb) remove a suffix from the filename.So "basename 0.pbm pbm" is just a way to remove the pbm suffix from the filename. Then we add jpg to the filename and 0.pbm becomes 0.jpg.

So this whole line is just a short way to executeconvert -quality 100 0.pbm 0.jpgconvert -quality 100 1.pbm 1.jpgetc...So we convert each pbm file with quality 100 (no quality loss) to a jpg file.

So you should have the files 0.jpg 1.jpg 2.jpg ...in your directory and you could use them as the input of ffmpeg or mencoder to create a movie from them.

PS: if you don't know what a command like 'convert' does, just type 'man convert' and you'll get a manual for this program. Use 'q' to leave the manual.

So, you your jpg files now as the input to ffmpeg:

ffmpeg -r 30 -b 1800 -i *.jpg output.mp4

, which calls ffmpeg with *.jpg (all the images) as the input (the part after -i is the input), a framerate of 30 fps (-r 30 means rate 30), a bitrateof 1800 kbit / second and and outputfile named 'output.mp4'.

The %02d was actually an error by me, since it means '2 digits', but this wouldn't match for your first files 0.pbm, but only for 00.pbm, 01.pbm etc.

Does this help you a bit further?

You could also send me the files, if you want, so I could create the video, but I thought you want to learn bash...

Thank you for your very detailed reply. I don't have time right now to work on this issue, but I will send you 2.7 of the 3 promised BTC. In 48 hours I will have time to work on this issue and if I can get it to work I will send you the rest, otherwise I will ask some more questions. Thanks again!

Ok - I was able to get it to work, thanks for your help. This was the first bash scripting I have ever done. I am pretty capable at scripting in other contexts, just had no idea how it worked from the terminal. Thanks for your help. The only part that didnt work was the " *.jpg " part in:

Quote

ffmpeg -r 30 -b 1800 -i *.jpg output.mp4

I had to go back to

Quote

ffmpeg -r 30 -b 1800 -i %03d.jpg output.mp4

but change all my file names to 000.jpg, 001.jpg, etc. Do you know any way to make it work from 0.jpg to 555.jpg (for instance)?

Also, the quality seems a bit low. I see in the manual that 200kbps is the default quality, and I notice that if I leave -b 1800 off the file looks the same as when I include it and its also the same file size, so I think some formatting in that line is being done wrong, because we certainly arent getting good quality.

Thanks for your help, I have sent you an additional 0.314159 BTC and that should complete our transaction, thanks for your help.

Also, the quality seems a bit low. I see in the manual that 200kbps is the default quality, and I notice that if I leave -b 1800 off the file looks the same as when I include it and its also the same file size, so I think some formatting in that line is being done wrong, because we certainly arent getting good quality.

Thanks for your help, I have sent you an additional 0.314159 BTC and that should complete our transaction, thanks for your help.

I found the issue here, the "-b xxx" portion needs to be after the -i portion. I got it to work.