From patchwork Wed May 31 16:26:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wm4 X-Patchwork-Id: 3775 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.10.2 with SMTP id 2csp366336vsk; Wed, 31 May 2017 09:26:21 -0700 (PDT) X-Received: by 10.28.137.201 with SMTP id l192mr5798322wmd.27.1496247981361; Wed, 31 May 2017 09:26:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496247981; cv=none; d=google.com; s=arc-20160816; b=UKNe6W0/q48mDt0Js/grAXvdnL/oTxSnnlVAxI56uZiVZaBeIfnMdz6ge1Q63fTYoO KiIz/BsnbkqAfR4M1ueSpYAURGFGiqMAqczYF7stUSZrDIqWNDa2V/EiolPeA5uB5nqD sLYNtAp8vK7+kgeot3NC9DHnRs7GGGmGipir1fR7cw9c01K8RqyHRaClwkIksCexuBEZ N76lL+UQ3kVHvplprRkFllWK49NFjIU2TJWqAOYtvVBv0My7XzDzdz3Dh5A12HgJTGiV T2/yvBfRjKamgXFIEzkwzyGqGfcszdlnHtZEUFqJvAttblpFvVys/opwFETZp4Kshq+5 ltnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=6lCm3mwKRuEzpB8tMptBL27FhGJw53ZqeTZxHH5yze8=; b=H2wYtexzSIPiE2AkNyu89fiVa7HZk8d/M0xDyeefU9n3Rmnv2qZiDk/0vm7/TQkVD4 81S2QQB941QF1D/8uYI5lsimtZKPPCk/N0zD7EirYoPvRjvvOLZPvGB9ZDlD8a59VMJg INlYKI8B2PinIr5VJUFYg9nlOwHV/ga7X3Pa7xfC6+byTEfanG2Fu78FeX2ruHUbtPhc q+Tts2QOfz5F2dBVc6ViBaMOGVFTig3vPUcyuZNFk5p0e42RiQlhAijbWz2mvjl0muDK 8z2rmRrmgV1sBBfJZ+IXd839zuzdDc+gmBo3uyZvlajGpSSHbniSSf3CFjYE+JP+4psI JxLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m192si19881616wmd.129.2017.05.31.09.26.20; Wed, 31 May 2017 09:26:21 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 453B8689888; Wed, 31 May 2017 19:26:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0D4C9680AB4 for ; Wed, 31 May 2017 19:26:07 +0300 (EEST) Received: by mail-wm0-f46.google.com with SMTP id b84so125572812wmh.0 for ; Wed, 31 May 2017 09:26:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=B/OevlnOWNghhcsuH3eSoe8K20hhQztXJ2flSsVElNg=; b=WwFYumq3TIHjSgT9qXaJebvGmgf5elfWbZugkAdFPmxXL+KWHtVpOIVJTpbu63ZbpG 2zx9Arg75Zt/EK6M1wtu5p5sfEOqk1fHqtKksNrbjUuv8zlFCiKpQUkV86IbaWoMrccc mogPigsflir8sx0bmpryWw78OvIdNzwOrzX07jDLI86T4cZkGjqwWha7e1evtTKjUWkb nD2h6uLdECs4jzhpSJU7sPF1FV75RTtghd0VawtDI/lU6T69m09P/gmR5WihvXJTin69 xGCHf1b9cCrdC5VKIP3tI+tfXtRid2t/LXtQV5w3pAvxVs6KxYFyq0eEY7UZPJGFOKsy MIzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=B/OevlnOWNghhcsuH3eSoe8K20hhQztXJ2flSsVElNg=; b=Yr8ucpzmJJbqFGn6k766yzvDqKEo8t5aE2iDPPQrEZ9OemeaOY+mrkf02qPNTAU+Rr rWAjCJ4sBVC7r9RIEUaljJoaN6cAPkqhrv/q6cjJFpOPtMPBmWG9YO8mrpXWwJB/sn4g ecrXp9p5tqz7hBypotPaV83Rw7BHZRiVrU3EovuJYCdDaAayNNKK0o0ZEnXrgLaN/TWC P+OoTa34vAasTL41iaeBMbl7vcrDUu0GWZjvAOEJ66Xs/kncdXcTcuiSeosgwc9zXYV3 lhsIyKO91+SdDA6pKQQwJou0BaYIp1HWdUaHwGOfnqCBvLNzI72nZ3bFnR9Y5zp9b7xV B1wg== X-Gm-Message-State: AODbwcDHlJHV9dGX8Mjj8fKBxncgeiRWpHVWxnYrev7CeQ66PHl+41s3 8aIPALVm0qS1RUoG X-Received: by 10.28.125.148 with SMTP id y142mr6159305wmc.104.1496247971155; Wed, 31 May 2017 09:26:11 -0700 (PDT) Received: from localhost.localdomain (p4FF02DB1.dip0.t-ipconnect.de. [79.240.45.177]) by smtp.googlemail.com with ESMTPSA id k53sm18443249wrc.10.2017.05.31.09.26.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 May 2017 09:26:10 -0700 (PDT) From: wm4 To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2017 18:26:01 +0200 Message-Id: <20170531162601.21287-1-nfxjfg@googlemail.com> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH] lavf: consider codec framerate for framerate detection 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 Cc: wm4 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes detection of some TV sample as 24.5 FPS. With the patch applied, it's detected as 25 FPS. This is enabled for mpegts only. --- libavformat/internal.h | 5 +++++ libavformat/mpegts.c | 2 ++ libavformat/utils.c | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/libavformat/internal.h b/libavformat/internal.h index c856945ce9..d136c79bdd 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -145,6 +145,11 @@ struct AVFormatInternal { * ID3v2 tag useful for MP3 demuxing */ AVDictionary *id3v2_meta; + + /* + * Prefer the codec framerate for avg_frame_rate computation. + */ + int prefer_codec_framerate; }; struct AVStreamInternal { diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 3eff1522bd..4d2f5c6802 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -2616,6 +2616,8 @@ static int mpegts_read_header(AVFormatContext *s) int len; int64_t pos, probesize = s->probesize; + s->internal->prefer_codec_framerate = 1; + if (ffio_ensure_seekback(pb, probesize) < 0) av_log(s, AV_LOG_WARNING, "Failed to allocate buffers for seekback\n"); diff --git a/libavformat/utils.c b/libavformat/utils.c index fbd8b58ac2..b50ca2f7ac 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3903,6 +3903,7 @@ FF_ENABLE_DEPRECATION_WARNINGS st->info->codec_info_duration) { int best_fps = 0; double best_error = 0.01; + AVRational codec_frame_rate = avctx->framerate; if (st->info->codec_info_duration >= INT64_MAX / st->time_base.num / 2|| st->info->codec_info_duration_fields >= INT64_MAX / st->time_base.den || @@ -3923,6 +3924,15 @@ FF_ENABLE_DEPRECATION_WARNINGS best_error = error; best_fps = std_fps.num; } + + if (ic->internal->prefer_codec_framerate && codec_frame_rate.num > 0 && codec_frame_rate.den > 0) { + error = fabs(av_q2d(codec_frame_rate) / + av_q2d(std_fps) - 1); + if (error < best_error) { + best_error = error; + best_fps = std_fps.num; + } + } } if (best_fps) av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,