From 0442b3eae494446aa19f68cba6817c4a4fc9b311 Mon Sep 17 00:00:00 2001 From: Alexander Reshetnikov Date: Fri, 13 Apr 2012 17:39:45 +0000 Subject: [PATCH] Updated diagnostic messages in VideoWriter (for ticket #1736) --- modules/highgui/src/cap_ffmpeg_impl.hpp | 12 +++++++++--- modules/highgui/src/cap_ffmpeg_impl_v2.hpp | 11 +++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/modules/highgui/src/cap_ffmpeg_impl.hpp b/modules/highgui/src/cap_ffmpeg_impl.hpp index aa9f8ee3a3..c27cd022c7 100644 --- a/modules/highgui/src/cap_ffmpeg_impl.hpp +++ b/modules/highgui/src/cap_ffmpeg_impl.hpp @@ -1309,15 +1309,21 @@ void CvVideoWriter_FFMPEG::close() /* find the video encoder */ codec = avcodec_find_encoder(c->codec_id); if (!codec) { + fprintf(stderr, "Could not find encoder for codec id %d: %s", c->codec_id, icvFFMPEGErrStr( + #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0) + AVERROR_ENCODER_NOT_FOUND + #else + -1 + #endif + )); return false; } c->bit_rate_tolerance = c->bit_rate; /* open the codec */ - if ( (err=avcodec_open(c, codec)) < 0) { - char errtext[256]; - sprintf(errtext, "Could not open codec '%s': %s", codec->name, icvFFMPEGErrStr(err)); + if ( (err=avcodec_open(c, codec)) < 0 ) { + fprintf(stderr, "Could not open codec '%s': %s", codec->name, icvFFMPEGErrStr(err)); return false; } diff --git a/modules/highgui/src/cap_ffmpeg_impl_v2.hpp b/modules/highgui/src/cap_ffmpeg_impl_v2.hpp index 85c024cb5c..ad5e45e10a 100755 --- a/modules/highgui/src/cap_ffmpeg_impl_v2.hpp +++ b/modules/highgui/src/cap_ffmpeg_impl_v2.hpp @@ -43,6 +43,7 @@ #include "cap_ffmpeg_api.hpp" #include #include + #include #if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( disable: 4244 4510 4512 4610 ) @@ -1454,6 +1455,13 @@ void CvVideoWriter_FFMPEG::close() /* find the video encoder */ codec = avcodec_find_encoder(c->codec_id); if (!codec) { + fprintf(stderr, "Could not find encoder for codec id %d: %s", c->codec_id, icvFFMPEGErrStr( + #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0) + AVERROR_ENCODER_NOT_FOUND + #else + -1 + #endif + )); return false; } @@ -1470,8 +1478,7 @@ void CvVideoWriter_FFMPEG::close() avcodec_open(c, codec) #endif ) < 0) { - char errtext[256]; - sprintf(errtext, "Could not open codec '%s': %s", codec->name, icvFFMPEGErrStr(err)); + fprintf(stderr, "Could not open codec '%s': %s", codec->name, icvFFMPEGErrStr(err)); return false; }