deansatch Posted February 14, 2013 Share Posted February 14, 2013 (edited) 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 February 14, 2013 by deansatch Quote Link to comment https://forums.phpfreaks.com/topic/274487-ffmpeg-to-convert-video-to-m4v-and-ogv/ Share on other sites More sharing options...
shlumph Posted February 14, 2013 Share Posted February 14, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274487-ffmpeg-to-convert-video-to-m4v-and-ogv/#findComment-1412458 Share on other sites More sharing options...
deansatch Posted February 14, 2013 Author Share Posted February 14, 2013 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?) Quote Link to comment https://forums.phpfreaks.com/topic/274487-ffmpeg-to-convert-video-to-m4v-and-ogv/#findComment-1412460 Share on other sites More sharing options...
Christian F. Posted February 14, 2013 Share Posted February 14, 2013 Were you running the transcoding as a background process, with a maximum execution time of 0 (infinite). Or were you trying to run the above code directly in your web page code? Quote Link to comment https://forums.phpfreaks.com/topic/274487-ffmpeg-to-convert-video-to-m4v-and-ogv/#findComment-1412478 Share on other sites More sharing options...
deansatch Posted February 15, 2013 Author Share Posted February 15, 2013 Just a short script on test.php running in the browser Quote Link to comment https://forums.phpfreaks.com/topic/274487-ffmpeg-to-convert-video-to-m4v-and-ogv/#findComment-1412577 Share on other sites More sharing options...
Christian F. Posted February 15, 2013 Share Posted February 15, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274487-ffmpeg-to-convert-video-to-m4v-and-ogv/#findComment-1412665 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.