Jump to content

Recommended Posts

I am trying to write a script so that almost any video file (those supported by ffmpeg) that is uploaded is automatically:

 

a) resized to a maximum width of 480px

b ) converted to a .mv4 file

c) a second version is created as a .ogv file

d) a screenshot is taken to use as a video placeholder image.

 

This is what I came up with and it worked fine when I converted a small .mov and .mp4 file:

 

exec('/opt/local/bin/ffmpeg -i testvids/test.m4v -strict -2 -ar 22050 -vf scale=480:ih*480/iw testvids/done.m4v 2>&1', $output, $result);

exec('/opt/local/bin/ffmpeg -i testvids/test.m4v -b 1500k -vcodec libtheora -acodec libvorbis -ab 160000 -g 30 testvids/done.ogv 2>&1', $output, $result);

exec('/opt/local/bin/ffmpeg -itsoffset -4 -i testvids/test.m4v -vcodec mjpeg -vframes 1 -an -f rawvideo -vf "scale=480:-1" testvids/images/done.png', $output, $result);

 

When I tested it on a 50MB .m4v file it failed and created corrupt files instead.

 

Is there something I need to know about converting from different formats? And as a side note, how much trouble would this be for my dedicated server if it was done fairly regularly?

 

Thanks

 

 

EDIT: I am doing this in PHP but perhaps this isn't really a PHP question?

Edited by deansatch
Link to comment
https://forums.phpfreaks.com/topic/274487-ffmpeg-to-convert-video-to-m4v-and-ogv/
Share on other sites

FFMPEG is a lot of fun, isn't it?

 

When I tested it on a 50MB .m4v file it failed and created corrupt files instead.

How did it fail? Did it go over the memory limit or max execution time?

 

Is there something I need to know about converting from different formats?

Not sure, as long as your box supports it by having the proper codecs and what not.

 

And as a side note, how much trouble would this be for my dedicated server if it was done fairly regularly?

Video conversion isn't a light process. I would just monitor your server. You may have to upgrade your hardware eventually or fork this process off to a stronger machine if your current server can't handle it.

 

EDIT: I am doing this in PHP but perhaps this isn't really a PHP question?

Linux guys might be able to help you out more if the failing was caused from FFMPEG and not PHP.

FFMPEG is a lot of fun, isn't it?

Indeed!

 

How did it fail? Did it go over the memory limit or max execution time?

I didn't get any error message from php but the end of my output array said:

"time=00:03:55.53 bitrate=1475.5kbits/s" [162]=> string(82) "video:38131kB audio:4081kB subtitle:0 global headers:7kB muxing overhead 0.481304%" }"

If that makes any sense to anyone

 

Not sure, as long as your box supports it by having the proper codecs and what not.

cool

 

 

Video conversion isn't a light process. I would just monitor your server. You may have to upgrade your hardware eventually or fork this process off to a stronger machine if your current server can't handle it.

I am planning on using a quad core 2.5ghz, 8gb ram machine. Any good?

 

Linux guys might be able to help you out more if the failing was caused from FFMPEG and not PHP.

I thought it might be more of a linuxy type of problem.

 

I will have another go and set my max execution and memory limit higher (any suggestions to accommodate a maximum 50MB / 5 minute file converted as mentioned in OP?)

Then that would be your problem, as there are multiple timeouts involved in a HTTP session. Any of which would easily kill the script, and halt the transcoding in the middle of the process.

 

What you need to do is to run the transcoding as a background process, and then (on completion) either move the completed file to a "completed" folder or set a flag in the database from that process. That way the user can simply upload the video, and go do other things while waiting for the process to complete.

To run a PHP script in the background, all you need is the following:

system ("/usr/bin/php -f transcode.php $file > /dev/null 2> /dev/null &");

 

This assumes that the transcode.php file resides in the PWD of the script calling it, but you really should move it outside of the web root folder. You don't want anyone to be able to access it outside of your PHP scripts, after all.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.