From patchwork Tue Dec 4 23:31:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Steinar H. Gunderson" X-Patchwork-Id: 11279 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id E7F8D44D06E for ; Wed, 5 Dec 2018 01:35:53 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9375D68A589; Wed, 5 Dec 2018 01:35:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [193.35.52.29]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4310D689744 for ; Wed, 5 Dec 2018 01:35:39 +0200 (EET) Received: from pannekake.samfundet.no ([2001:67c:29f4::50]) by cassarossa.samfundet.no with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from <601cae2e9f78cf07557abc6a717a3f9787829061@pannekake.samfundet.no>) id 1gUKEE-0000GO-DP for ffmpeg-devel@ffmpeg.org; Wed, 05 Dec 2018 00:35:46 +0100 Received: from sesse by pannekake.samfundet.no with local (Exim 4.89) (envelope-from <601cae2e9f78cf07557abc6a717a3f9787829061@pannekake.samfundet.no>) id 1gUKEE-001Z0L-2T for ffmpeg-devel@ffmpeg.org; Wed, 05 Dec 2018 00:35:46 +0100 From: "Steinar H. Gunderson" Date: Wed, 5 Dec 2018 00:31:10 +0100 To: ffmpeg-devel@ffmpeg.org Message-Id: Subject: [FFmpeg-devel] [PATCH] avcodec/mjpeg: don't override color information from demuxer X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Some demuxers, like Matroska, allow for sending colorspace information that override MJPEG defaults when it comes to Y'CbCr coefficients or chroma location. Don't override such data if the demuxer already has set it; this allows decoding such MJPEG streams correctly. Also document in avcodec.h that these fields are actually set first by libavformat, even if libavcodec is usually the one to set them. This is not new behavior; e.g., dnxhd already works this way. --- libavcodec/avcodec.h | 10 +++++----- libavcodec/mjpegdec.c | 8 ++++++-- tests/fate/matroska.mak | 3 +++ tests/ref/fate/matroska-mjpeg-color-space | 22 ++++++++++++++++++++++ 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 tests/ref/fate/matroska-mjpeg-color-space diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 3922e89331..b7ea99d8ab 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2145,35 +2145,35 @@ typedef struct AVCodecContext { /** * Chromaticity coordinates of the source primaries. * - encoding: Set by user - * - decoding: Set by libavcodec + * - decoding: Set by libavformat and/or libavcodec */ enum AVColorPrimaries color_primaries; /** * Color Transfer Characteristic. * - encoding: Set by user - * - decoding: Set by libavcodec + * - decoding: Set by libavformat and/or libavcodec */ enum AVColorTransferCharacteristic color_trc; /** * YUV colorspace type. * - encoding: Set by user - * - decoding: Set by libavcodec + * - decoding: Set by libavformat and/or libavcodec */ enum AVColorSpace colorspace; /** * MPEG vs JPEG YUV range. * - encoding: Set by user - * - decoding: Set by libavcodec + * - decoding: Set by libavformat and/or libavcodec */ enum AVColorRange color_range; /** * This defines the location of chroma samples. * - encoding: Set by user - * - decoding: Set by libavcodec + * - decoding: Set by libavformat and/or libavcodec */ enum AVChromaLocation chroma_sample_location; diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 2f1635838a..9ee2daadf8 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -158,8 +158,12 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) s->first_picture = 1; s->got_picture = 0; s->org_height = avctx->coded_height; - avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; - avctx->colorspace = AVCOL_SPC_BT470BG; + if (avctx->chroma_sample_location == AVCHROMA_LOC_UNSPECIFIED) { + avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; + } + if (avctx->colorspace == AVCOL_SPC_UNSPECIFIED) { + avctx->colorspace = AVCOL_SPC_BT470BG; + } s->hwaccel_pix_fmt = s->hwaccel_sw_pix_fmt = AV_PIX_FMT_NONE; if ((ret = init_default_huffman_tables(s)) < 0) diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak index 2747496e1e..1768ce6ee2 100644 --- a/tests/fate/matroska.mak +++ b/tests/fate/matroska.mak @@ -9,5 +9,8 @@ fate-matroska-remux: REF = 1ed49a4f2b6790357fac268938357353 FATE_MATROSKA_FFPROBE-$(call ALLYES, MATROSKA_DEMUXER) += fate-matroska-spherical-mono fate-matroska-spherical-mono: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries stream_side_data_list -select_streams v -v 0 $(TARGET_SAMPLES)/mkv/spherical.mkv +FATE_MATROSKA_FFPROBE-$(call ALLYES, MATROSKA_DEMUXER) += fate-matroska-mjpeg-color-space +fate-matroska-mjpeg-color-space: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries frame=color_range,color_space,color_primaries,color_transfer,chroma_location $(TARGET_SAMPLES)/mkv/mjpeg-color-space.mkv + FATE_SAMPLES_AVCONV += $(FATE_MATROSKA-yes) FATE_SAMPLES_FFPROBE += $(FATE_MATROSKA_FFPROBE-yes) diff --git a/tests/ref/fate/matroska-mjpeg-color-space b/tests/ref/fate/matroska-mjpeg-color-space new file mode 100644 index 0000000000..d3cd39f967 --- /dev/null +++ b/tests/ref/fate/matroska-mjpeg-color-space @@ -0,0 +1,22 @@ +[FRAME] +color_range=tv +color_space=bt709 +color_primaries=bt709 +color_transfer=iec61966-2-1 +chroma_location=left +[SIDE_DATA] +[/SIDE_DATA] +[SIDE_DATA] +[/SIDE_DATA] +[/FRAME] +[FRAME] +color_range=tv +color_space=bt709 +color_primaries=bt709 +color_transfer=iec61966-2-1 +chroma_location=left +[SIDE_DATA] +[/SIDE_DATA] +[SIDE_DATA] +[/SIDE_DATA] +[/FRAME]