From e0f4a99b99532d195ad40a161b633d39bcba4725 Mon Sep 17 00:00:00 2001 From: Johns Date: Wed, 22 Apr 2015 12:14:15 +0200 Subject: [PATCH] Workaround for ffmpeg 2.6 artifacts. --- ChangeLog | 1 + codec.c | 35 ++++++++++++++++++++++++++++++++++- codec.h | 9 ++++++++- softhddev.c | 5 ++++- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 679636b..a949dd8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ User johns Date: + Workaround for ffmpeg 2.6 artifacts. Fix bug: brightness and .. are calculated wrong. Add automatic frame rate detection for older ffmpeg versions. Fix bug: destroyed vdpau surfaces still used in queue. diff --git a/codec.c b/codec.c index 10011c3..cbf6f39 100644 --- a/codec.c +++ b/codec.c @@ -1,7 +1,7 @@ /// /// @file codec.c @brief Codec functions /// -/// Copyright (c) 2009 - 2014 by Johns. All Rights Reserved. +/// Copyright (c) 2009 - 2015 by Johns. All Rights Reserved. /// /// Contributor(s): /// @@ -93,6 +93,16 @@ #include "audio.h" #include "codec.h" +//---------------------------------------------------------------------------- + + // correct is AV_VERSION_INT(56,35,101) but some gentoo i* think + // they must change it. +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(56,26,100) + /// ffmpeg 2.6 started to show artifacts after channel switch + /// to SDTV channels +#define FFMPEG_WORKAROUND_ARTIFACTS 1 +#endif + //---------------------------------------------------------------------------- // Global //---------------------------------------------------------------------------- @@ -105,6 +115,9 @@ /// static pthread_mutex_t CodecLockMutex; + /// Flag prefer fast xhannel switch +char CodecUsePossibleDefectFrames; + //---------------------------------------------------------------------------- // Video //---------------------------------------------------------------------------- @@ -126,6 +139,9 @@ struct _video_decoder_ int GetFormatDone; ///< flag get format called! AVCodec *VideoCodec; ///< video codec AVCodecContext *VideoCtx; ///< video codec context +#ifdef FFMPEG_WORKAROUND_ARTIFACTS + int FirstKeyFrame; ///< flag first frame +#endif AVFrame *Frame; ///< decoded video frame }; @@ -525,6 +541,9 @@ void CodecVideoOpen(VideoDecoder * decoder, const char *name, int codec_id) } // reset buggy ffmpeg/libav flag decoder->GetFormatDone = 0; +#ifdef FFMPEG_WORKAROUND_ARTIFACTS + decoder->FirstKeyFrame = 1; +#endif } /** @@ -611,8 +630,22 @@ void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt) } if (got_frame) { // frame completed +#ifdef FFMPEG_WORKAROUND_ARTIFACTS + if (!CodecUsePossibleDefectFrames && decoder->FirstKeyFrame) { + decoder->FirstKeyFrame++; + if (frame->key_frame) { + Debug((3, "codec: key frame after %d frames\n", + decoder->FirstKeyFrame); + decoder->FirstKeyFrame = 0; + } + } else { + //DisplayPts(video_ctx, frame); + VideoRenderFrame(decoder->HwDecoder, video_ctx, frame); + } +#else //DisplayPts(video_ctx, frame); VideoRenderFrame(decoder->HwDecoder, video_ctx, frame); +#endif } else { // some frames are needed for references, interlaced frames ... // could happen with h264 dvb streams, just drop data. diff --git a/codec.h b/codec.h index 995573a..eccaf00 100644 --- a/codec.h +++ b/codec.h @@ -1,7 +1,7 @@ /// /// @file codec.h @brief Codec module headerfile /// -/// Copyright (c) 2009 - 2013 by Johns. All Rights Reserved. +/// Copyright (c) 2009 - 2013, 2015 by Johns. All Rights Reserved. /// /// Contributor(s): /// @@ -43,6 +43,13 @@ typedef struct _video_decoder_ VideoDecoder; /// Audio decoder typedef. typedef struct _audio_decoder_ AudioDecoder; +//---------------------------------------------------------------------------- +// Variables +//---------------------------------------------------------------------------- + + /// Flag prefer fast xhannel switch +extern char CodecUsePossibleDefectFrames; + //---------------------------------------------------------------------------- // Prototypes //---------------------------------------------------------------------------- diff --git a/softhddev.c b/softhddev.c index 5afe3b5..a44f020 100644 --- a/softhddev.c +++ b/softhddev.c @@ -1,7 +1,7 @@ /// /// @file softhddev.c @brief A software HD device plugin for VDR. /// -/// Copyright (c) 2011 - 2014 by Johns. All Rights Reserved. +/// Copyright (c) 2011 - 2015 by Johns. All Rights Reserved. /// /// Contributor(s): /// @@ -2905,6 +2905,7 @@ const char *CommandLineHelp(void) "\talsa-no-close-open\tdisable close open to fix alsa no sound bug\n" "\talsa-close-open-delay\tenable close open delay to fix no sound bug\n" "\tignore-repeat-pict\tdisable repeat pict message\n" + "\tuse-possible-defect-frames prefer faster channel switch\n" " -D\t\tstart in detached mode\n"; } @@ -2986,6 +2987,8 @@ int ProcessArgs(int argc, char *const argv[]) AudioAlsaCloseOpenDelay = 1; } else if (!strcasecmp("ignore-repeat-pict", optarg)) { VideoIgnoreRepeatPict = 1; + } else if (!strcasecmp("use-possible-defect-frames", optarg)) { + CodecUsePossibleDefectFrames = 1; } else { fprintf(stderr, _("Workaround '%s' unsupported\n"), optarg);