From patchwork Wed Aug 31 23:09:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chema Gonzalez X-Patchwork-Id: 37580 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp640668pzh; Wed, 31 Aug 2022 16:10:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR4x8QZru1aX75JXnUVTNNjrotGayFf+xwC5OuLiu2I7Chn19Drrtjl4KU7YNaLopkk4PRXh X-Received: by 2002:aa7:d4d8:0:b0:447:a745:4b18 with SMTP id t24-20020aa7d4d8000000b00447a7454b18mr27585645edr.174.1661987440424; Wed, 31 Aug 2022 16:10:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661987440; cv=none; d=google.com; s=arc-20160816; b=eYVhOkCQgRk9EaH4nxavWo6KtcYfBLwFnABHKc0+PhLo4Fv/L8VHiJttE3tEP/QA9r Ync7xQNzVdO/O1srwo7HC53ZI4Mcg4qN1hNymjptL+tpmfPTyKNZS9s+sz99P6qyF84i jF+jo4EXdXF2BXE00rtJpkKMNIqVsRa7bK5fy8tiq/FGk7wUmAceGXx9dd+9kIkHfuF6 aNXHoRSm9hHUGVC1Z3YX90d5sj+/C6qT1Vo6E1LjgS+oktBwhgAhbxl+t1hkYpLPZDaZ gyOT2/xwoUqFYwL6Go4ornnoAX1dERoVOFtrdvSDfRQooevxU0m+jPYv0zw6ZArkY6P+ v5oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=CvGJMGb0QJAAxnYIam350rV/EhMA2YluEaa/ISOL0SA=; b=lmuB2612hUHghA9b7YJAXT2kfMEyr1MQUXO2u2n9E495fpxXbk0mnwHOFFNFrWHWVg ZLiVMherK8G+6HRWxFxTuvuVgVfC6MLjCkEkfmwTqfW3cW5irDJxweJffLAntpEaWDCf U6TGE/uNLX0ZMitn7rRxB7GLi+9Vlhuflp3fFjx6I9hI4jQjxOVrqf8M3GquIu2A2KL9 0RYLUL7dBbv6Y4FKAMgPhfelczjkx3K5OE6SXqXxlDRvWe6JAqjTM83E8+007R9vOizk SVrubYWkE9Q4XXstT4tbw15hAoEa0pmCiZSC1LHBijmJnNeeV9wQ5yAahFz1OzM8W7Ky flVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=OPW4mY+0; 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 gb38-20020a170907962600b00715867834e3si12640424ejc.506.2022.08.31.16.10.18; Wed, 31 Aug 2022 16:10:40 -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=20210112 header.b=OPW4mY+0; 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 546F868B9CA; Thu, 1 Sep 2022 02:10:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0DE1468B97D for ; Thu, 1 Sep 2022 02:10:10 +0300 (EEST) Received: by mail-pg1-f170.google.com with SMTP id b196so5082270pga.7 for ; Wed, 31 Aug 2022 16:10:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=5uy5r/sjAtQIaAtN+LIrViV2A6k16J8uGWOYMGhji/Y=; b=OPW4mY+0pxDVT+R7PNHrNsYPfLdBhC46JwZ55kV5rRphuJPZISaOD1x6phRCJ5nvCU BRd0UoRcFbZE0CU/3mN8brmA32DlEvPPzUHXZIZ3obxyP14QOp/oDHqGd3HVk7eNJzWQ Q5JHBBPqaGoUv2duxsATAxrsLk4owX0mZJEFVJ4eE7QLkvuWqNwo0exwfwP/PLtp6jOY iOsKtQ1yVS2g3wMPieeCE1LUZOv1RA0bBNBYSjV03aU/NwzL0dlYKODEmOcS7xfa6JXw Zrr4Wz6cDlp6bhoI0VprsexGftNGgdx46jbndUiQ6lE8pbzENN1ORD6/6NRAUUclFEnq uKXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=5uy5r/sjAtQIaAtN+LIrViV2A6k16J8uGWOYMGhji/Y=; b=snMJc9TvwKby9Q/FjaGBYqqlM1VAwrvCxP7Xxjxo0/ReuWQN1fzFy+GNKYyvxycErH 080dvNkAuMR0sikIm7lHVJKGxmsVMt0y3ATqFZxZBr6ZuSws1utOfCxyha39tVb6/0j+ +wfOkeMLd+6tJII8M+edb/K9l93w9LzkZ8k37V22AhK+huSbsjXQ9aHPfa0jfiOsHjzT x4ex4FnJggtMWl/x0XAP3e9S7U100kSqWpniJ+raCc4L4XtLhFK4MhysZfQCKYLs9BTh Glp6bpZXJP6mz65fPl49QlpHYMqcckSNZ/05sQjvE5sUcqPNSMq92+5Co8GNxdPnYZte F2SQ== X-Gm-Message-State: ACgBeo23ffiHfoN8ccXbxaBYQJMqL6K37f6JzUgx23a/IxBU6JSGWI2Y YD34yytHfOauSm/X1wkQVtTuN006lgc= X-Received: by 2002:a05:6a00:1515:b0:536:c6ea:115f with SMTP id q21-20020a056a00151500b00536c6ea115fmr28165005pfu.37.1661987407796; Wed, 31 Aug 2022 16:10:07 -0700 (PDT) Received: from wilferico.thefacebook.com ([2620:10d:c090:400::5:62d5]) by smtp.gmail.com with ESMTPSA id i15-20020a17090a2a0f00b001fd84a8cfc6sm1838710pjd.39.2022.08.31.16.09.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:09:55 -0700 (PDT) From: Chema Gonzalez To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 Aug 2022 16:09:18 -0700 Message-Id: <20220831230918.1736362-2-chemag@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220831230918.1736362-1-chemag@gmail.com> References: <20220831230918.1736362-1-chemag@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/1] avcodec/mpegutils: add motion_vec debug mode X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Chema Gonzalez Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: MIeywk9MhuNL Add a new debug mode ("motion_vec") that prints the values of the motion vectors (MV). Note that, in order to give the same weight to MV from bigger blocks, we may print each MV pair more than once. Tested: ``` $ ./ffprobe -v quiet -show_frames -debug motion_vec /tmp/in.264 2>&1 >/dev/null ... [h264 @ 0x2d0d700] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2 [h264 @ 0x2d0d700] New frame, type: I [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2 [h264 @ 0x2d0d700] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0 [h264 @ 0x2d0d700] New frame, type: B [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -3 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... [h264 @ 0x2d0d700] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0 ... ``` --- libavcodec/avcodec.h | 1 + libavcodec/mpegutils.c | 45 +++++++++++++++++++++++++++++++++++++- libavcodec/options_table.h | 1 + 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 65c8535359..4287555a31 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1344,6 +1344,7 @@ typedef struct AVCodecContext { #define FF_DEBUG_THREADS 0x00010000 #define FF_DEBUG_GREEN_MD 0x00800000 #define FF_DEBUG_NOMC 0x01000000 +#define FF_DEBUG_MOTION_VEC 0x02000000 /** * Error recognition; may misdetect some more or less valid parts as errors. diff --git a/libavcodec/mpegutils.c b/libavcodec/mpegutils.c index ff9418232b..d0a94784fb 100644 --- a/libavcodec/mpegutils.c +++ b/libavcodec/mpegutils.c @@ -246,8 +246,11 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, return; - if (avctx->debug & (FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)) { + if (avctx->debug & (FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE | FF_DEBUG_MOTION_VEC)) { int x,y; + const int mv_sample_log2 = avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_SVQ3 ? 2 : 1; + const int mv_stride = (mb_width << mv_sample_log2) + + (avctx->codec->id == AV_CODEC_ID_H264 ? 0 : 1); av_log(avctx, AV_LOG_DEBUG, "New frame, type: %c\n", av_get_picture_type_char(pict->pict_type)); @@ -271,6 +274,46 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, get_segmentation_char(mb_type), get_interlacement_char(mb_type)); } + if (avctx->debug & FF_DEBUG_MOTION_VEC) { + int i, direction, mb_type = mbtype_table[x + y * mb_stride]; + if (IS_8X8(mb_type)) { + for (i = 0; i < 4; i++) { + int xy = (x * 2 + (i & 1) + + (y * 2 + (i >> 1)) * mv_stride) << (mv_sample_log2 - 1); + int mx = motion_val[direction][xy][0]; + int my = motion_val[direction][xy][1]; + av_log(avctx, AV_LOG_DEBUG, "%4d %4d", mx, my); + } + } else if (IS_16X8(mb_type)) { + for (i = 0; i < 2; i++) { + int xy = (x * 2 + (y * 2 + i) * mv_stride) << (mv_sample_log2 - 1); + int mx = motion_val[direction][xy][0]; + int my = motion_val[direction][xy][1]; + if (IS_INTERLACED(mb_type)) + my *= 2; + av_log(avctx, AV_LOG_DEBUG, "%4d %4d", mx, my); + av_log(avctx, AV_LOG_DEBUG, "%4d %4d", mx, my); + } + } else if (IS_8X16(mb_type)) { + for (i = 0; i < 2; i++) { + int xy = (x * 2 + i + y * 2 * mv_stride) << (mv_sample_log2 - 1); + int mx = motion_val[direction][xy][0]; + int my = motion_val[direction][xy][1]; + if (IS_INTERLACED(mb_type)) + my *= 2; + av_log(avctx, AV_LOG_DEBUG, "%4d %4d", mx, my); + av_log(avctx, AV_LOG_DEBUG, "%4d %4d", mx, my); + } + } else { + int xy = (x + y * mv_stride) << mv_sample_log2; + int mx = motion_val[direction][xy][0]; + int my = motion_val[direction][xy][1]; + av_log(avctx, AV_LOG_DEBUG, "%4d %4d", mx, my); + av_log(avctx, AV_LOG_DEBUG, "%4d %4d", mx, my); + av_log(avctx, AV_LOG_DEBUG, "%4d %4d", mx, my); + av_log(avctx, AV_LOG_DEBUG, "%4d %4d", mx, my); + } + } } av_log(avctx, AV_LOG_DEBUG, "\n"); } diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index cd02f5096f..0d100069e1 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -198,6 +198,7 @@ static const AVOption avcodec_options[] = { {"startcode", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_STARTCODE }, INT_MIN, INT_MAX, V|D, "debug"}, {"er", "error recognition", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_ER }, INT_MIN, INT_MAX, V|D, "debug"}, {"mmco", "memory management control operations (H.264)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_MMCO }, INT_MIN, INT_MAX, V|D, "debug"}, +{"motion_vec", "macroblock (MB) motion vector values", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_MOTION_VEC }, INT_MIN, INT_MAX, V|D, "debug"}, {"bugs", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_BUGS }, INT_MIN, INT_MAX, V|D, "debug"}, {"buffers", "picture buffer allocations", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_BUFFERS }, INT_MIN, INT_MAX, V|D, "debug"}, {"thread_ops", "threading operations", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_THREADS }, INT_MIN, INT_MAX, V|A|D, "debug"},