2
votes

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.

3
how to do error handling in ffmpeg ?Hitesh

3 Answers

5
votes

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

2
votes

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;
}
1
votes

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.