如何判断 ffmpeg 是否出错?
情况:
我正在使用 ffmpeg (通过 php)来转换视频文件。我将转换脚本配置为从 exec() 命令返回输出(作为 $error 数组)。我的假设是,如果没有发生错误,$error 将是一个空数组。
问题:
问题是,即使转换没有错误,脚本也会返回输出。 (我可以看出没有错误,因为输出了可播放的视频文件。)
问题:
ffmpeg 如何格式化其错误/输出?我希望能够解析它并确定是否发生了错误以及它是什么错误。
谢谢!
代码:
*非错误输出的示例:
FFmpeg version git-N-29201-g37c0a44, Copyright (c) 2000-2011 the FFmpeg developers| built on Sep 9 2011 23:29:21 with gcc 4.1.2 20080704 (Red Hat 4.1.2-50)| configuration: --prefix=/usr/local/hgffmpeg --enable-shared --enable-nonfree --enable-avfilter --enable-filter=movie --enable-gpl --enable-pthreads --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --extra-cflags=-I/usr/local/hgffmpeg/include/ --extra-ldflags=-L/usr/local/hgffmpeg/lib --enable-decoder=ac3 --enable-decoder=asv1 --enable-decoder=asv2 --enable-decoder=flac --enable-decoder=wmv1 --enable-decoder=wmv2 --enable-decoder=wmv3 --enable-decoder=mpeg1video --enable-decoder=mpeg2video --enable-decoder=flv --enable-decoder=fraps --enable-decoder=h263 --enable-decoder=h264 --enable-decoder=libgsm --enable-decoder=mjpeg --enable-decoder=mpeg4 --enable-decoder=mpeg4aac --enable-decoder=mpegvideo --enable-decoder=mpeg4aac --enable-decoder=msmpeg4v1 --enable-decoder=msmpeg4v2 --enable-decoder=msmpeg4v3 --enable-decoder=pcm_alaw --enable-decoder=pcm_mulaw --enable-encoder=ac3 --enable-encoder=asv1 --enable-encoder=asv2 --enable-encoder=flac --enable-encoder=h263 --enable-encoder=flashsv --enable-encoder=flv --enable-encoder=libgsm --enable-encoder=mjpeg --enable-encoder=msmpeg4v3 --enable-encoder=pcm_alaw --enable-encoder=pcm_mulaw --enable-encoder=mpeg1video --enable-encoder=mpeg2video --enable-encoder=mpeg4 --enable-encoder=msmpeg4v1 --enable-encoder=msmpeg4v2 --enable-encoder=rv10 --enable-encoder=rv20 --enable-encoder=vorbis --enable-encoder=wmav1 --enable-encoder=wmav2 --enable-encoder=wmv1 --enable-encoder=wmv2 --disable-demuxer=v4l --disable-demuxer=v4l2 --enable-version3| libavutil 50. 40. 1 / 50. 40. 1| libavcodec 52.120. 0 / 52.120. 0| libavformat 52.108. 0 / 52.108. 0| libavdevice 52. 4. 0 / 52. 4. 0| libavfilter 1. 79. 1 / 1. 79. 1| libswscale 0. 13. 0 / 0. 13. 0|[mpeg1video @ 0x1f6d030] skipped MB in I frame at 5 0|[mpeg1video @ 0x1f6d030] Warning MVs not available|[mpeg1video @ 0x1f6d030] concealing 260 DC, 260 AC, 260 MV errors|[mpegvideo @ 0x1f6a660] Estimating duration from bitrate, this may be inaccurate|Input #0, mpegvideo, from '../uploads/test_vid/unencodedVideo.mpg':| Duration: 00:00:00.01, bitrate: 104860 kb/s| Stream #0.0: Video: mpeg1video, yuv420p, 320x200 [PAR 1:1 DAR 8:5], 104857 kb/s, 23.98 fps, 23.98 tbr, 1200k tbn, 23.98 tbc|WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s|File '../uploads/test_vid/video.flv' already exists. Overwrite ? [y/N] Not overwriting - exiting
The Situation:
I'm using ffmpeg (via php) to convert video files. I configured my convert script to return the output (as the $error array) from the exec() command. My assumption was that if no error occurred, $error would be an empty array.
The Problem:
The problem is that, the script returns output even if there was no error in conversion. (I can tell that there was no error because a playable video file is output.)
The Question:
How does ffmpeg format its errors/output? I want to be able to parse this and determine if an error occurred and what error it was.
Thanks!
Code:
*An example of a non-error output:
FFmpeg version git-N-29201-g37c0a44, Copyright (c) 2000-2011 the FFmpeg developers| built on Sep 9 2011 23:29:21 with gcc 4.1.2 20080704 (Red Hat 4.1.2-50)| configuration: --prefix=/usr/local/hgffmpeg --enable-shared --enable-nonfree --enable-avfilter --enable-filter=movie --enable-gpl --enable-pthreads --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --extra-cflags=-I/usr/local/hgffmpeg/include/ --extra-ldflags=-L/usr/local/hgffmpeg/lib --enable-decoder=ac3 --enable-decoder=asv1 --enable-decoder=asv2 --enable-decoder=flac --enable-decoder=wmv1 --enable-decoder=wmv2 --enable-decoder=wmv3 --enable-decoder=mpeg1video --enable-decoder=mpeg2video --enable-decoder=flv --enable-decoder=fraps --enable-decoder=h263 --enable-decoder=h264 --enable-decoder=libgsm --enable-decoder=mjpeg --enable-decoder=mpeg4 --enable-decoder=mpeg4aac --enable-decoder=mpegvideo --enable-decoder=mpeg4aac --enable-decoder=msmpeg4v1 --enable-decoder=msmpeg4v2 --enable-decoder=msmpeg4v3 --enable-decoder=pcm_alaw --enable-decoder=pcm_mulaw --enable-encoder=ac3 --enable-encoder=asv1 --enable-encoder=asv2 --enable-encoder=flac --enable-encoder=h263 --enable-encoder=flashsv --enable-encoder=flv --enable-encoder=libgsm --enable-encoder=mjpeg --enable-encoder=msmpeg4v3 --enable-encoder=pcm_alaw --enable-encoder=pcm_mulaw --enable-encoder=mpeg1video --enable-encoder=mpeg2video --enable-encoder=mpeg4 --enable-encoder=msmpeg4v1 --enable-encoder=msmpeg4v2 --enable-encoder=rv10 --enable-encoder=rv20 --enable-encoder=vorbis --enable-encoder=wmav1 --enable-encoder=wmav2 --enable-encoder=wmv1 --enable-encoder=wmv2 --disable-demuxer=v4l --disable-demuxer=v4l2 --enable-version3| libavutil 50. 40. 1 / 50. 40. 1| libavcodec 52.120. 0 / 52.120. 0| libavformat 52.108. 0 / 52.108. 0| libavdevice 52. 4. 0 / 52. 4. 0| libavfilter 1. 79. 1 / 1. 79. 1| libswscale 0. 13. 0 / 0. 13. 0|[mpeg1video @ 0x1f6d030] skipped MB in I frame at 5 0|[mpeg1video @ 0x1f6d030] Warning MVs not available|[mpeg1video @ 0x1f6d030] concealing 260 DC, 260 AC, 260 MV errors|[mpegvideo @ 0x1f6a660] Estimating duration from bitrate, this may be inaccurate|Input #0, mpegvideo, from '../uploads/test_vid/unencodedVideo.mpg':| Duration: 00:00:00.01, bitrate: 104860 kb/s| Stream #0.0: Video: mpeg1video, yuv420p, 320x200 [PAR 1:1 DAR 8:5], 104857 kb/s, 23.98 fps, 23.98 tbr, 1200k tbn, 23.98 tbc|WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s|File '../uploads/test_vid/video.flv' already exists. Overwrite ? [y/N] Not overwriting - exiting
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您使用 exec() 来调用 ffmpeg,您需要:
Assuming you're using
exec()
to invoke ffmpeg, you'd want: