I have ffmpeg installed in my xampp. I'm trying combine one image file with one audio file to produce one video file using a php script. However, no file is produced. I've tried:
<?php
$ffmpegcmd = "ffmpeg -loop 1 -i C:\xampp\htdocs\testingffmpeg\dog.png -i C:\xampp\htdocs\testingffmpeg\dog.wav -c:v libx264 -tune stillimage \ -c:a aac -strict experimental -b:a 192k -pix_fmt yuv420p -shortest C:\xampp\htdocs\testingffmpeg\dog.mp4";
shell_exec($ffmpegcmd);
?>
and
<?php
shell_exec("ffmpeg -loop 1 -i C:\xampp\htdocs\testingffmpeg\dog.png -i C:\xampp\htdocs\testingffmpeg\dog.wav -c:v libx264 -tune stillimage \ -c:a aac -strict experimental -b:a 192k -pix_fmt yuv420p -shortest C:\xampp\htdocs\testingffmpeg\dog.mp4");
?>
and
<?php
shell_exec("C:\xampp\php\ext\ffmpeg -loop 1 -i C:\xampp\htdocs\testingffmpeg\dog.png -i C:\xampp\htdocs\testingffmpeg\dog.wav -c:v libx264 -tune stillimage \ -c:a aac -strict experimental -b:a 192k -pix_fmt yuv420p -shortest C:\xampp\htdocs\testingffmpeg\dog.mp4");
?>
The problem is with slashes inside your double-quoted string. PHP threats those as command sequences (e.g. states for carriage return etc.)
You have two possibilities: either escape slashes with addslashes
:
<?php
shell_exec( addslashes( '$ffmpegcmd = "ffmpeg -loop 1 -i C:\xampp\htdocs\testingffmpeg\dog.png -i C:\xampp\htdocs\testingffmpeg\dog.wav -c:v libx264 -tune stillimage \ -c:a aac -strict experimental -b:a 192k -pix_fmt yuv420p -shortest C:\xampp\htdocs\testingffmpeg\dog.mp4'; ) );
?>
I figured out a script that works, but I'm a bit confused about what's going on. This script references the ffmpeg.exe file. But shouldn't the script be able to run on the php_ffmpeg.dll when I'm using xampp? In fact, I removed the php_ffmpeg.dll and ran the script and it still worked. What was the point then of even installing the .dll? And will this script work when I use it on a real server?
Here's the script that works, with or without the .dll:
<?php
shell_exec('C:\ffmpeg\bin\ffmpeg.exe -loop 1 -i "C:\xampp\htdocs\testingffmpeg\dog.jpg" -i "C:\xampp\htdocs\testingffmpeg\dog.wav" -shortest -acodec copy -f mov C:\xampp\htdocs\testingffmpeg\dog.mp4');
?>