1

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.

7
  • 2
    Try just to run this command manually in terminal and check the output. Commented Jun 12, 2019 at 16:54
  • @Alex thanks for the reply I tried but not work. Commented Jun 13, 2019 at 4:37
  • 1
    not work - what are the error messages there? Commented Jun 13, 2019 at 18:31
  • 1
    there is no such thing as empty array error message when you run ffmpeg manually in terminal Commented Jun 14, 2019 at 13:31
  • 1
    @Alex thanks for helping run original code in terminal and know what happened. syntax error near unexpected token `('. In my code output have () and in PHP show empty array after running in the terminal show above error thanks a lot. Commented Jun 14, 2019 at 16:08

1 Answer 1

2

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.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.