ffmpeg-php exec not work on server - ffmpeg-php

I use FFmpeg in my local xamp and it works fine. But on my server (FFmpeg installed) exec does not work and FFmpeg does not create output file.
This is my code:
<?php
extension_loaded('ffmpeg') or die('Error in loading ffmpeg');
$vid = realpath('test.mp4');
$ffmpegInstance = new ffmpeg_movie($vid);
echo "getDuration: " . $ffmpegInstance->getDuration() . "<br />".
"getFrameCount: " . $ffmpegInstance->getFrameCount() . "<br />".
$cmd = "ffmpeg -i $vid -s 640x360 -vcodec libx264 -preset medium -crf 23 -acodec libmp3lame -ar 44100 -q:a 5 out.flv 1> block.txt 2>&1";
//$cmd = "ffmpeg -i $vid -vcodec libvpx -cpu-used -5 -deadline realtime out.mp4 1> block.txt 2>&1";
exec($cmd);
?>

I'm not sure why you are loading the extension ffmpeg but calling the shell to run ffmpeg. Perhaps you are mixing up if you want to call ffmpeg inside php or using exec/shell.
Can you first do a echo system('which ffmpeg'); to verify that ffmpeg can be found on the server?
Also check the version of ffmpeg in a similar way.
Please use the output and return value of the system and exec commands to see what the real problem is. See exec() and system() for more information.

Related

Pipe PhantomJS output to FFmpeg

I am running PhantomJS using Selenium WebDriver (C#).
I'm trying to video record my browser using FFmpeg as shown in the 2 tutorials:
https://mindthecode.com/recording-a-website-with-phantomjs-and-ffmpeg/
https://gist.github.com/phanan/e03f75082e6eb114a35c
As explained in the tutorials, I'll need to pipe output the phantomJS process to ffmpeg.
I know how to add arguments to phantomjs, like the following:
var svz = PhantomJSDriverService.CreateDefaultService();
svz.AddArgument("ffmpeg -y -c:v png -f image2pipe -r 24 -t 10 -i - -c:v libx264 -pix_fmt yuv420p -movflags +faststart output.mp4");
var driver = new PhantomJSDriver(svz);
However, I don't know how to add the argument as pipe. I have tried adding the pipe symbol before the actual argument but that doesn't seem to work.
So, my question is, how do I pipe the output of PhantomJS using selenium webdriver?

resize one video in 2 sizes in single command

When user uploads video then I make its 2 sizes. Earlier, I was doing this in two steps like following
First Size:
ffmpeg -i in.mp4 -filter:v "scale=iw*min(1170/iw\,300/ih):ih*min(1170/iw\,300/ih), pad=1170:300:(1170-iw*min(1170/iw\,300/ih))/2:(300-ih*min(1170/iw\,300/ih))/2" out.mp4
Second Size:
ffmpeg -i in.mp4 -filter:v "scale=iw*min(365/iw\,172/ih):ih*min(365/iw\,172/ih), pad=365:172:(365-iw*min(365/iw\,172/ih))/2:(172-ih*min(365/iw\,172/ih))/2" out1.mp4
But now to reduce processing time, I want to combine these 2 steps in one. I have read https://trac.ffmpeg.org/wiki/Creating%20multiple%20outputs and make following command
ffmpeg -i in.mp4 -filter:v "scale=iw*min(1170/iw\,300/ih):ih*min(1170/iw\,300/ih), pad=1170:300:(1170-iw*min(1170/iw\,300/ih))/2:(300-ih*min(1170/iw\,300/ih))/2" bigVideo.mp4 \ -filter:v "scale=iw*min(365/iw\,172/ih):ih*min(365/iw\,172/ih), pad=365:172:(365-iw*min(365/iw\,172/ih))/2:(172-ih*min(365/iw\,172/ih))/2" smallVideo.mp4
But it is giving following error
[NULL # 0xaee5440] Unable to find a suitable output format for ' -filter:v'
-filter:v: Invalid argument
so can anyone suggest me how i can solve it?
I tried to run both commands using the following script:
#!/bin/bash
for cmd in "$#"; do {
echo "Process \"$cmd\" started";
$cmd & pid=$!
PID_LIST+=" $pid";
} done
trap "kill $PID_LIST" SIGINT
echo "Parallel processes have started";
wait $PID_LIST
echo
echo "All processes have completed";
You can save it as filename.sh and make executable. after that you need to pass two of more commands as arguments, for example I ran as:
./filename.sh "ffmpeg -i input.mp4 -s 720x480 output1.mp4" "ffmpeg -i input.mp4 -s 1170x480 output2.mp4"
Your command was bit complicated for me so I try to run simple commands using parallel script.

How to capture screen and audio input and push to rtmp server?

I use avconv on ubuntu,I found this command
avconv -f alsa -i pulse -f x11grab -r 25 -s 1280x720 -i :0.0+0,0 -acodec libfaac -vcodec libx264 -pre:0 lossless_ultrafast -threads 0 video.mkv
to save as a file, and this command
avconv -i ./test.m4v -re -c copy -f flv "rtmp://localhost/livestream"
to push live stream.
How can I combine them together?
Firstly, you should ask such questions on video.stackexchange.com and not here.
Secondly, let's take apart the two commands that you have found:
-f alsa - format for the input is alsa
-i pulse - you are reading pulse (the pulseaudio driver)
-f x11grab - planning to read from the screen on x11
-r 25 -s 1280x720 - rate and size of the incoming video stream
-i :0.0+0,0 - this selects where the incoming video comes from
-acodec libfaac - here the output options start, you're setting audio code to libfaac, or at least trying to... since this option has been deprecated long time ago, currently -c:a would be used
-vcodec libx264 - setting video code, except that you should be using -c:v
-pre:0 lossless_ultrafast -threads 0 - some sort of parameters about how encoding should be done
video.mkv - this is the output file
And the second one
-i ./test.m4v - the file you're reading
-re - "Read input at native frame rate"
-c copy - do not reencode, but simply pipe as is
-f flv - the container format
"rtmp://localhost/livestream" - where you're planning to write all that.
When you understand that, it should be clear that what you are planning to do is to use the input and encoding part from the first command, and the format and output from the second one.
Here i didn't have time to check that everything that you found is working, you should do that yourself.

Wrong frame rate when saving camera feed to a file using FFMPEG

I'm trying to save the live feed from an IP camera to a file but the resulting file always plays much faster than the original speed.
I have tried with the following commands:
ffmpeg -i http://171.22.3.47/image -vcodec copy -an -t 900 c:\output.mp4
ffmpeg -i http://171.22.3.47/image -c:v libx264 -an c:\output.mp4
Does anybody know what I'm missing? Both commands create the file and I can use Windows Media Player to play them, but they run much faster.
Try forcing output framerate by adding -r key
ffmpeg -i http://171.22.3.47/image -c:v libx264 -an -r 30 c:\output.mp4
You can also try to slow down the resulting video as an option. This will make output.mp4 2 times slower:
ffmpeg -i output.mp4 -filter:v "setpts=2.0*PTS" -c:v libx264 -an output-slow.mp4

avconv: getting aac to work. -strict experimental doesn't work

I am trying to get the following screencast command to work:
avconv -f alsa -ar 44100 -ac 2 -i default -acodec aac -strict experimental -ab 320k -f x11grab -s 1024x600 -r 24 -i :0.0 -vcodec rawvideo screencast.mp4
But I still get the following error:
encoder 'aac' is experimental and might produce bad results.
Add '-strict experimental' if you want to use it
Other sites suggest making sure that the -strict experimental appears immediately after the aac parameter, which I have done, to no effect.
Move both the -acodec aac and -strict experimental to somewhere after the last -i parameter in the command line, before the output file name.
Parameters to avconv are parsed as "avconv [input1 options] -i input1 [input2 options] -i input2 [output options] outputfile", so when you added these parameters before the second -i they were interpreted as options to the second input, not to the output.