I am trying to insert text overlay, and can do this, but I cannot add spaces to the text.
ffmpeg -i meme.mp4 -y -vf drawtext='/Users/me/Library/Fonts/Champagne & Limousines.ttf:text='testtext': fontcolor=white: fontsize=24' -codec:a copy outputtexttest.mp4 2>&1
The error when I make testtext test text is:
Unable to find a suitable output format for 'text: fontcolor=white: fontsize=24' text: fontcolor=white: fontsize=24: Invalid argument
Add double quotes around the text, not single quotes like you have:
echo shell_exec("$ffmpeg -i meme.mp4 -y -vf drawtext='/Users/me/Library/Fonts/Champagne & Limousines.ttf:text=''test + infinity spaces :) text'': fontcolor=white: fontsize=24' -codec:a copy outputtexttest.mp4 2>&1");
Related
I use ffmpeg to convert bitrate to 128 but not working in php
exec("ffmpeg -i input.mp3 -codec:a libmp3lame -b:a 128k output().mp3 2>&1",
$output, $exit_code);
if ($exit_code!= 0) {
$data['message'][] = "Error";
}
print_r($output);
print_r($exit_code);
exit;
After running this code show error code 2.
The output is an empty array and also exit_code is 2 and not create output.mp3 file.
I already study How can I find out what this ffmpeg error code means? but this isn't my problem and don't explain error code 2 or error code 2 is not defined. My problem is dont show any error and error message is empty just exit_code show 2 that means is some error happened.
syntax error near unexpected token `('
You need to escape the parentheses because they are special characters:
exec("ffmpeg -i input.mp3 -codec:a libmp3lame -b:a 128k 'output().mp3' 2>&1",
or
exec("ffmpeg -i input.mp3 -codec:a libmp3lame -b:a 128k output\(\).mp3 2>&1",
Also see FFmpeg: Quoting & Escaping.
This isn't exactly a PHP issue, so please always make sure your ffmpeg command works before you attempt to script it. (That would really reduce the number of questions here.)
I am new to ffmpeg and need some help with the correct syntax for a scale command I found here.
Below is my code:
$width=300;
$height=200;
$aspect=$width/$height;
$command = "/usr/local/bin/ffmpeg -y -i 1.mp4 -vf scale=min(1\,gt(iw\,".$width.")+gt(ih\,".$height.")) * (gte(a\,".$aspect.")*".$width." + \
lt(a\,".$aspect.")*((".$height."*iw)/ih)) + not(min(1\,gt(iw\,".$width.")+gt(ih\,".$height.")))*iw : \
min(1\,gt(iw\,".$width.")+gt(ih\,".$height.")) * (lte(a\,".$aspect.")*".$height." + \
gt(a\,".$aspect.")*((".$width."*ih)/iw)) + not(min(1\,gt(iw\,".$width.")+gt(ih\,".$height.")))*ih -b 1200k -acodec aac -strict -2 2.mp4 ";
Video is successfully converted however, the scaling does not go trough.
The code is copied word for word, I only make two changes:
removed the " before scale word and from the end
replaced the $FW with $width, $FH with $height and $FA with $aspect.
Any suggestion at what might be wrong?
I am researching over ffmpeg usage for quite a while and seemed little confusing to me. Finally I found that exec command of PHP could help in execution of ffmpeg command if ffmpeg is installed on the system . I created the php script below:
exec("ffmpeg -i C:\Users\sameeksha\Downloads\v.mp4 -ar 22050 -ab 32 -f flv -s 320x240 C:\FFMPEG\video.flv", $output, $return);
if($return) {
echo "created ".$output;
}
else
echo "not ".$output;
The same command run from command line is creating the converted video, but when I run it as a PHP script it does not. I even installed dll files for ffmpeg but still did not work for me.
Any help would be appreciated.
You need to escape the backslashes in a double quoted string.
Example: C:\FFMPEG\video.flv needs to be C:\\FFMPEG\\video.flv
Or just use slashes:
C:/FFMPEG/video.flv
You can also enclose your command in apostrophes rather than quotes, as the apostrophe inhibits escape sequences providing \ is not the last character in your input.
exec('ffmpeg -i ... ', $output, $return);
I create code for add logo to video using ffmpeg.
ffmpeg -i 1.mp4 -i a.jpg -filter_complex "overlay=main_w/2-overlay_w/2:main_h/2-overlay_h/2" outputvideo.mp4
When I use this code in windows dos there is no problem and logo is added, but it give me an error when I use this with PHP.
PHP:
<?php
echo "Starting ffmpeg...\n\n";
echo shell_exec("ffmpeg -i 1.mp4 -i a.jpg -filter_complex "overlay=main_w/2-overlay_w/2:main_h/2-overlay_h/2" outputvideo.mp4");
echo "Done.\n";
?>
Error:
Parse error: syntax error, unexpected 'overlay' (T_STRING) in C:\xampp\htdocs\tts\2.php on line 3
How to solve this?
Please help me.
Escape " like \".
echo shell_exec("ffmpeg -i 1.mp4 -i a.jpg -filter_complex \"overlay=main_w/2-overlay_w/2:main_h/2-overlay_h/2\" outputvideo.mp4");
As Glavic has pointed out, you need to escape the double quotes in the string, so your command should look like this:
echo shell_exec("ffmpeg -i 1.mp4 -i a.jpg -filter_complex \"overlay=main_w/2-overlay_w/2:main_h/2-overlay_h/2\" outputvideo.mp4");
I am using a ffmpeg command to cut a video with exec function in php. But it is not creating a video file and doesn't show any errors. I used exec as below
exec("ffmpeg -i input.flv -ss 00:00:30.0 -t 00:00:10.0 -acodec copy -vcodec copy -async 1 output.flv");
Can I get any help to know what is the error happening here?
exec("ffmpeg -i input.flv -ss 00:00:30.0 -t 00:00:10.0 -acodec copy -vcodec copy -async 1 output.flv",$output);
I tried it also. But I didn't get any error message in variable $output
As a general rule, you first need to check the return value: non-zero values indicate there has been an error (given that the author of the program you are running adheres to the standard). This value is captured in exec()'s third argument.
In second place, many programs do not send error messages to the standard output. Instead, they use the standard error. In this case, it seems safe to just redirect the latter to the former:
exec("ffmpeg -i input.flv -ss 00:00:30.0 -t 00:00:10.0 -acodec copy -vcodec copy -async 1 output.flv 2>&1", $output, $return_value);