2

when i run

exec("ffmpeg -i $flv -y -f mjpeg -ss 00:00:05 -s 120x90 -vframes 1 -an thumb.jpg",$error);

$error return's empty value but when i run this command using cron job this one send a notification email to me which contain informations like

FFmpeg version 0.5.2, Copyright (c) 2000-2009 Fabrice Bellard, et al. configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC --enable-avfilter --enable-avfilter-lavf --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libx264 --enable-gpl --enable-nonfree --enable-postproc --enable-pthreads --enable-shared --enable-swscale --enable-vdpau --enable-version3 --enable-x11grab libavutil 49.15. 0 / 49.15. 0 libavcodec 52.20. 1 / 52.20. 1 libavformat 52.31. 0 / 52.31. 0 libavdevice 52. 1. 0 / 52. 1. 0 libavfilter 0. 4. 0 / 0. 4. 0 libswscale 0. 7. 1 / 0. 7. 1 libpostproc 51. 2. 0 / 51. 2. 0 built on Jun 13 2010 23:44:18, gcc: 4.1.2 20080704 (Red Hat 4.1.2-48)

I need to be able to get those errors in php so i can know if the thumb was created or not

Thanks.

1
  • how to do error handling in ffmpeg ? Commented Nov 28, 2014 at 9:47

3 Answers 3

5

Redirect the output with 2>&1

exec("ffmpeg -i $flv -y -f mjpeg -ss 00:00:05 -s 120x90 -vframes 1 -an thumb.jpg 2>&1",$error);

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

1 Comment

I know this is an old question but I always find it useful to also get the FFMPEG report when running some command. Therefor I use something like this: $cmd = 'ffmpeg -i ' . $task . $codec . $path . ' -report -hide_banner -loglevel error 2>&1'; $r = exec($cmd, $errors); where -report generates an extensive report in the root directory. For bigger projects I always throw in a logging system like: $log = file_put_contents($logFile, $cmd . PHP_EOL , FILE_APPEND | LOCK_EX); just to have everything in one place and commented nicely.
2

Building on top of Mauro's answer. A clean way to detect errors will be adding the following options -hide_banner and -loglevel error.

exec("ffmpeg -i $flv -y -f mjpeg -ss 00:00:05 -s 120x90 -vframes 1 -an thumb.jpg -hide_banner -loglevel error 2>&1", $errors);

exec() will always assign an array of strings to the second parameter in this case $errors, each element corresponding to a different error, so you can simply print or handle each error using a loop:

foreach($errors as $next) {
    //handle error
    echo $next;
}

Comments

1

This answer comes almost 6 year after question, but newer versions have an option -hide_banner.

From man page

-hide_banner

Suppress printing banner.

All FFmpeg tools will normally show a copyright notice, build options and library versions. This option can be used to suppress printing this information.

Also you can use the option -loglevel to define what kind of message (errors, warning, info, debug) would you want to show.

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.