开发者

How can I know the error in command in an exec function?

开发者 https://www.devze.com 2023-01-05 18:03 出处:网络
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 er开发者_Go百科rors. I used exec as below

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 er开发者_Go百科rors. 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);
0

精彩评论

暂无评论...
验证码 换一张
取 消