4

I am using FFMpeg to covert videos and it is working fine from the command line. I am using the following command:

ffmpeg -i input.mpg  -vcodec libx264 -b 819200 -s 100x100 -g 15 -bf 3 -b_strategy 1 -coder 1 -qmin 10 -qmax 51 -sc_threshold 40 -flags +loop -cmp +chroma -me_range 16 -me_method hex -subq 5 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -directpred 1 -flags2 +fastpskip -dts_delta_threshold 1 -acodec libfaac -ab 48000 output.m4v

However, when I run the command using PHP exec(), the output video is not encoded correctly and is distorted and cropped. I am using the following in PHP:

$output = exec($cmd . ' 2>&1', $output, $return);

The $output returns a '0' successful code.

Does any one have any suggestions?

Thank you.

3 Answers 3

8

This is unusual. It is possible that you have more than one ffmpeg binary installed, and the one that is being called by the PHP/Apache user is not the same as the one you call as your user from the command line.

Try specifying the full path to your ffmpeg binary (/usr/bin/ffmpeg or whatever) inside your exec().

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

2 Comments

You are a legend! Upvote. Thank you so much! I don't have two versions as far as I am aware but putting the absolute path sorted it straight away. Thank you again.
I just installed ffmpeg and suspect maybe restarting Apache would do it -- but this worked just the same! (only grabbing poster frames so execution time was not the issue).
1

It sounds like some command line options are getting lost/altered. I would try to split this into a 2 part process:

  1. write a shell script on-the-fly (from PHP) that has all the proper command arguments (make it executable)
  2. execute the shell script (from PHP)

2 Comments

Before you do this, make sure that replacing exec() with passthru() doesn't fix problem. This would be a faster/easier fix if it worked.
Thank you for the reply. Could you elaborate please on how I would write the shell script? I am not too familiar with this. Chris
0

I would probably try:

1) change ' 2>&1' to ' 2>&1 &'

Also, transcoding can take a while. Are you certain you are waiting long enough for the transcode to complete?

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.