From patchwork Sat Jun 9 15:09:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramiro Polla X-Patchwork-Id: 9331 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp2131055jad; Sat, 9 Jun 2018 08:15:38 -0700 (PDT) X-Google-Smtp-Source: ADUXVKImxEAITp1iYm8h9OVwc31KZuM2gqqkkI8m2UgvIabOxi9ODiSxurS2ZJ4qZJS6fC+Ca4MM X-Received: by 2002:adf:b3d4:: with SMTP id x20-v6mr8328256wrd.272.1528557338235; Sat, 09 Jun 2018 08:15:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528557338; cv=none; d=google.com; s=arc-20160816; b=DZRRynwlS4JZlXWx1AnFMw62r92PHu6Ke0ll88hanEGiTz3OXkSK9NT1LoPtijTkoy JoeEP6jz+YMWqvar+vgs0quBHmeHOxZ6iIarAcuzaXxgLsKhBrAwxES7dejjv2/zRsmn pJXk8O0jg5Yq6eJzMPiwtgJKZxH/GTPpIPGetzW5U4xXLZUya3tgNrIzSOb3mbChmhVQ g8VPm//xDJLhGU/t9qtmQBdVqrOJfkpgMhpiknuKzAR1itqy9hL8WmDOfkJb5MkGmAFs /lTMnkKv0sXXb0XppYJOdoCfu2Jsc9kV/iFytdNE6r7OI4wyv8D3BYpd4IgL08ipJf9l Cn6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:delivered-to:arc-authentication-results; bh=M4MK6Oj+ga88UGltnaUCQ5X8aINwbfvwYD432Ex0xnU=; b=A1WqGTwKKg4ZAyMkI1aA+L27vnm0PA00CzAUbhV8ozPdSEx/kk8R0dMKvkXfmM3Bn+ sRBmLqb+d/YZjneW3JZnuPsCw7qbmhAWetl+f8xuNY2T4jMXGRP3tE0thxrZPDRjSnbY 6ocGAZ0uv0WJJ48ZknCKjaNA+Y0UBJYKTrh73KlxVBJboH/ZbhhyJNj0RLh9ceqnzsFW q85lMgfN3tBkers821IP/r5RTStY8XHfcBWD2coBxhkpK4/7gAEWvUYMKvCroQqxrIyg ekRBHq0HoL5Gqu8EDvCH59nIrsqrKo2X6y1jUCMI5CBLk6/EQpGmxqDM6gKEZY4G/Uw+ cSOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=mlTR89tD; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k7-v6si10286961wro.303.2018.06.09.08.15.37; Sat, 09 Jun 2018 08:15:38 -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=@gmail.com header.s=20161025 header.b=mlTR89tD; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3F58668A6A3; Sat, 9 Jun 2018 18:14:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf0-f68.google.com (mail-lf0-f68.google.com [209.85.215.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AB76268A69B for ; Sat, 9 Jun 2018 18:14:40 +0300 (EEST) Received: by mail-lf0-f68.google.com with SMTP id q11-v6so24355015lfc.7 for ; Sat, 09 Jun 2018 08:15:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=UcsZtMFW6f+94HCL8i5mCCnFreZVBmMEzm1HHWTYLfQ=; b=mlTR89tDpwUXLEEhTjenVendnoh8w5wtIFv1lznuNsNsH/jM3AK6bnuWjQEeXZaey4 y7NfImHIU95vER6uE31ZYS5fwtYmnYyqKwwDPbJp/QtwLElRVGRUOatZVHKhrRckLi17 cmq/09va/EhlxvmcmbrZmH4bnDKUl2qhTAtRtoovga/nNK9tHdGSggTlyKl4ikC+CADv 35eR15yIwQiT4TfHRoxl2fmwEdDMbsOHNbxBfAVMzpQ1L/cS3a3t9tfVWfu5WGvBky6B 3szoxrOUtih1N61+8rA/V5Betokmj3ppGGwC20ExxujaUmamVpEkw4eWEGFLvq9+lSgv lLyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=UcsZtMFW6f+94HCL8i5mCCnFreZVBmMEzm1HHWTYLfQ=; b=qLzdAyU2bcxf+5o006N2LcbmNAnjjj9sh++1L7bWbHOrtJfl4rqveFkcDps8ZW+XpI lPlkvWrRuI3ASmy/WOT3BfiLTGDQu3SG1yzzvtfc9r56zjwO0deGLf1XVqb27kQQvMgu 8SOCsXaN5AxqNl2pNMclUsmS87OXFelqyM/YLX/zm0E4UMwaobFt7yYFcB54OWo1haKT TDjLGWrra/9JP9PuXAs8qs6eg5tEjhiN4aD4cXcbuMyPVjUZyCgvVZ2Q4099MqVs5QK5 WPPzvDoWmAhZdJ2KPPQU9qRaSrD9NIwDZoZcr2AaPP7pq4jbw9KlBxAB8WADr1A0Ygus bPwg== X-Gm-Message-State: APt69E1ydfWQvFtWT+9BaMv07Eyqqh796axAJcflOzCwSXmzBpJJ7ZEa WafOtLPrlj6znfFaNoYSS5oWEaoxNV/zU2CZU00= X-Received: by 2002:a19:1647:: with SMTP id m68-v6mr6745491lfi.131.1528556954676; Sat, 09 Jun 2018 08:09:14 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a19:d2d1:0:0:0:0:0 with HTTP; Sat, 9 Jun 2018 08:09:13 -0700 (PDT) In-Reply-To: <20180510210159.GK20131@michaelspb> References: <20180509184425.18789-1-ramiro.polla@gmail.com> <20180510210159.GK20131@michaelspb> From: Ramiro Polla Date: Sat, 9 Jun 2018 17:09:13 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH] mpegvideo_enc: add option to disable intra mbs in p frames 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi Michael, On Thu, May 10, 2018 at 11:01 PM, Michael Niedermayer wrote: > On Wed, May 09, 2018 at 08:44:25PM +0200, Ramiro Polla wrote: >> This option prevents the mpv encoders from using intra macroblocks in >> predictive frames. >> >> It is useful for glitch artists to generate input material. This option >> allows them to split and merge two video files while maintaining fluid >> motion from the second video without having intra macroblocks restoring >> chunks of the first video. > > maybe a continuous variable like snows intra_penalty could achieve this > too but give more flexibility in doing it also just partially if wanted I like this idea better. I wanted a simple way to be able to entirely disable intra macroblocks, but "-intra_penalty max" could cause an overflow, so I set the max value to INT_MAX/2. New patch attached. From d2c1da02c28be5519f0ba84aa22f519a296a6d04 Mon Sep 17 00:00:00 2001 From: Ramiro Polla Date: Sat, 9 Jun 2018 17:00:26 +0200 Subject: [PATCH] mpegvideo_enc: add intra_penalty option for p frames This option allows more control over the use of intra macroblocks in predictive frames. By using '-intra_penalty max', intra macroblocks are never used in predictive frames. It is useful for glitch artists to generate input material. This option allows them to split and merge two video files while maintaining fluid motion from the second video without having intra macroblocks restoring chunks of the first video. --- libavcodec/motion_est.c | 10 +++++----- libavcodec/motion_est.h | 2 +- libavcodec/mpegvideo.h | 3 +++ libavcodec/mpegvideo_enc.c | 6 +++--- libavcodec/svq1enc.c | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index 8b5ce2117a..fa750e39ec 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -971,7 +971,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20; c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score); - if (vard*2 + 200*256 > varc) + if (vard*2 + 200*256 > varc && !s->intra_penalty) mb_type|= CANDIDATE_MB_TYPE_INTRA; if (varc*2 + 200*256 > vard || s->qscale > 24){ // if (varc*2 + 200*256 + 50*(s->lambda2>>FF_LAMBDA_SHIFT) > vard){ @@ -1040,7 +1040,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, intra_score= s->mecc.mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16); } - intra_score += c->mb_penalty_factor*16; + intra_score += c->mb_penalty_factor*16 + s->intra_penalty; if(intra_score < dmin){ mb_type= CANDIDATE_MB_TYPE_INTRA; @@ -1648,7 +1648,7 @@ int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type) } } -void ff_fix_long_p_mvs(MpegEncContext * s) +void ff_fix_long_p_mvs(MpegEncContext * s, int type) { MotionEstContext * const c= &s->me; const int f_code= s->f_code; @@ -1682,8 +1682,8 @@ void ff_fix_long_p_mvs(MpegEncContext * s) if( mx >=range || mx <-range || my >=range || my <-range){ s->mb_type[i] &= ~CANDIDATE_MB_TYPE_INTER4V; - s->mb_type[i] |= CANDIDATE_MB_TYPE_INTRA; - s->current_picture.mb_type[i] = CANDIDATE_MB_TYPE_INTRA; + s->mb_type[i] |= type; + s->current_picture.mb_type[i] = type; } } } diff --git a/libavcodec/motion_est.h b/libavcodec/motion_est.h index 3b3a8d7341..817220f340 100644 --- a/libavcodec/motion_est.h +++ b/libavcodec/motion_est.h @@ -127,7 +127,7 @@ int ff_get_mb_score(struct MpegEncContext *s, int mx, int my, int src_index, int ff_get_best_fcode(struct MpegEncContext *s, int16_t (*mv_table)[2], int type); -void ff_fix_long_p_mvs(struct MpegEncContext *s); +void ff_fix_long_p_mvs(struct MpegEncContext *s, int type); void ff_fix_long_mvs(struct MpegEncContext *s, uint8_t *field_select_table, int field_select, int16_t (*mv_table)[2], int f_code, int type, int truncate); diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index e16deb64e7..7eda962ba7 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -577,6 +577,8 @@ typedef struct MpegEncContext { int scenechange_threshold; int noise_reduction; + + int intra_penalty; } MpegEncContext; /* mpegvideo_enc common options */ @@ -661,6 +663,7 @@ FF_MPV_OPT_CMP_FUNC, \ {"ps", "RTP payload size in bytes", FF_MPV_OFFSET(rtp_payload_size), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"mepc", "Motion estimation bitrate penalty compensation (1.0 = 256)", FF_MPV_OFFSET(me_penalty_compensation), AV_OPT_TYPE_INT, {.i64 = 256 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"mepre", "pre motion estimation", FF_MPV_OFFSET(me_pre), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ +{"intra_penalty", "Penalty for intra blocks in block decision", FF_MPV_OFFSET(intra_penalty), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX/2, FF_MPV_OPT_FLAGS }, \ extern const AVOption ff_mpv_generic_options[]; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 9fdab31a25..94e31e01eb 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -3761,14 +3761,14 @@ static int encode_picture(MpegEncContext *s, int picture_number) s->f_code= FFMAX3(s->f_code, a, b); } - ff_fix_long_p_mvs(s); - ff_fix_long_mvs(s, NULL, 0, s->p_mv_table, s->f_code, CANDIDATE_MB_TYPE_INTER, 0); + ff_fix_long_p_mvs(s, s->intra_penalty ? CANDIDATE_MB_TYPE_INTER : CANDIDATE_MB_TYPE_INTRA); + ff_fix_long_mvs(s, NULL, 0, s->p_mv_table, s->f_code, CANDIDATE_MB_TYPE_INTER, !!s->intra_penalty); if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME) { int j; for(i=0; i<2; i++){ for(j=0; j<2; j++) ff_fix_long_mvs(s, s->p_field_select_table[i], j, - s->p_field_mv_table[i][j], s->f_code, CANDIDATE_MB_TYPE_INTER_I, 0); + s->p_field_mv_table[i][j], s->f_code, CANDIDATE_MB_TYPE_INTER_I, !!s->intra_penalty); } } } diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c index 80a8af1ef7..651013588f 100644 --- a/libavcodec/svq1enc.c +++ b/libavcodec/svq1enc.c @@ -345,7 +345,7 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane, s->m.first_slice_line = 0; } - ff_fix_long_p_mvs(&s->m); + ff_fix_long_p_mvs(&s->m, CANDIDATE_MB_TYPE_INTRA); ff_fix_long_mvs(&s->m, NULL, 0, s->m.p_mv_table, s->m.f_code, CANDIDATE_MB_TYPE_INTER, 0); } -- 2.11.0