4

I am trying to upload a movie onto a site and then automatically convert it into .mp4 format from the .mov iPhone format. Is there a php conversion library or tool that would help me do this?

Thanks.

5
  • 1
    While you could start the conversion process with PHP, you probably wouldn't want to actually convert movies with PHP.
    – tplaner
    Jun 24, 2011 at 20:15
  • What @evolve said. You'd be far better of with a service like Zencoder for this.
    – ceejayoz
    Jun 24, 2011 at 20:20
  • handbrake.fr CLI (Command Line Interface), Docs: trac.handbrake.fr/wiki/CLIGuide, just use PHP to kick it off Jun 24, 2011 at 20:23
  • I've tried the handbrake CLI, but you can't rotate videos 90 degrees clockwise.
    – willpots
    Jun 27, 2011 at 17:44
  • Zencoder looks nice, but unfortunately its not in my budget!
    – willpots
    Jun 27, 2011 at 17:44

5 Answers 5

5

Well I know this is an alternative solution:

PHP:

$cmd = './HandBrakeCLI -i /path/to/source.MOV -o movie.mp4 --preset="iPhone & iPod Touch"';
echo exec($cmd);

Note: You will need to install Handbrake on your server

3

You could try the ffmpeg extension: http://ffmpeg-php.sourceforge.net/

Edit:

It turns out that the ffmpeg extension probably won't help you, but you could still use ffmpeg to do the conversion. You are probably better off having a cron job or something similar do the conversions in the background. Just let the user upload the mov file, and then add it to a queue and convert it to mp4 in another process.

3
  • I don't believe ffmpeg does file conversion.
    – tplaner
    Jun 24, 2011 at 20:14
  • It looks like you're right. I assumed that the extension wrapped all of ffmpeg's functions. It looks like it is mainly useful for generating thumbnails.
    – jncraton
    Jun 24, 2011 at 20:18
  • This does look useful and I will certainly implement it, but unfortunately I still need to find another solution.
    – willpots
    Jun 27, 2011 at 17:45
3

The Apple mov files are in fact MP4 containers - so .mov == .m4v == .mp4 == .m4a. It will be ok to just rename the file. Or do you want a specific codec?

0
2

Not really unfortunately.

I've been doing this exact thing for the past 4 years, if you want to take a crack at writing it yourself, your best bet is to fork an exec to ffmpeg in your upload script eg.

exec('ffmpeg ... &');

note the ampersand at the end, this allows your php script to complete while allowing the encode to happen in the background, also CHECK YOUR INPUT VARS as there is the chance of shell injection using this method.

or the alternative:

use a system like beanstalkd as a message queue between your php upload script and a worker process (I use a custom multithreaded perl script) on the backend that takes in new encodes and processes them (I'm using ffmpeg, mencoder, or quicktime using qt_tools, depending on input video format), using memcached as temp storage for encoding status.

sorry I can't be more specific right now, I may update this tomorrow with a bit more, but I've been up all night, and need SLEEP. hopefully this gets you moving in the right direction till then.

0

Try command :

 ffmpeg -i movie.mov -vcodec copy -acodec copy out.mp4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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