Page 1 of 1

backend script to make ipod compatible videos using ffmpeg

Posted: Sun Feb 12, 2006 9:32 pm
by bigsexychris
First, I really appreciate the time you're taking to help me out.

The Mission: Drop video (mov, wmv, avi, etc.) files (via ssh) onto a computer on our network, have them automatically converted to ipod format using the command: ffmpeg -i "0098273.wmv" -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ar 44100 -ab 160 -s 320x240 -aspect 4:3 0098273.mp4

So Far: I can get a list of current files in the directory into a text file, have php read the list, and generate the above command with the correct file names for input and output (0098273 in this example). Issuing the above command from a ssh shell works fine.

What I Need Help With: I'm not experienced using php to execute programs on the server, so I don't know how to use exec() or shell_exec(). Would either of these be appropriate to call ffmpeg with the switches above?

What The Program Should Look Like: Ideally, I would like to drop a file/multiple files into a directory on the server, have php recognize it (just using a cron job every few minutes), execute ffmpeg, and when finished, delete the original file 0098273.wmv and move the converted file 0098273.mp4 to a different directory with all the other ipod converted videos.

Specific Questions:
Do you recommend exec() or shell_exec() or something else?
Is there a way for php to know when ffmpeg is finished encoding so the script does not try to run multiple instances of the ffmpeg?
Which functions can delete/move files?

If you've made it this far, I sincerely thank you for taking your time to read this. I am not asking for someone to write this program for me :D, but I would love if some more experienced users could point me in the right direction!

-Chris

Posted: Sun Feb 12, 2006 9:36 pm
by josh
exec() is fine for this, PHP will block while your program executes unless you tell linux to run the program in the background. unlink() and rename() will remove and move files

Posted: Sun Feb 12, 2006 9:51 pm
by bigsexychris
thanks for the very fast reply.. that info about exec() is good to hear.. but I have one more question about it:

Will the PHP script automatically resume when ffmpeg is done converting? or is this dependent on ffmpeg sending information back to the script alerting that it is done?

-Chris

Posted: Sun Feb 12, 2006 9:56 pm
by josh
PHP will resume as soon as it is done, nothing special needs to be done (unless that program automatically runs itself in the background or some odd thing like that)