From: Chema Gonzalez <chemag@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Chema Gonzalez <chemag@gmail.com>
Subject: [FFmpeg-devel] [PATCH 1/1] avcodec/mpegutils: add motion_vec debug mode
Date: Wed, 31 Aug 2022 16:09:18 -0700
Message-ID: <20220831230918.1736362-2-chemag@gmail.com> (raw)
In-Reply-To: <20220831230918.1736362-1-chemag@gmail.com>
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"},
--
2.37.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-08-31 23:10 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-31 23:09 [FFmpeg-devel] [PATCH 0/1] add motion_vec (motion vector) " Chema Gonzalez
2022-08-31 23:09 ` Chema Gonzalez [this message]
2022-09-01 13:30 ` [FFmpeg-devel] [PATCH 1/1] avcodec/mpegutils: add motion_vec " Ronald S. Bultje
2022-09-01 15:05 ` Chema Gonzalez
2022-09-01 17:55 ` Paul B Mahol
2022-09-01 18:43 ` Chema Gonzalez
2022-09-02 7:59 ` Paul B Mahol
2022-09-02 15:12 ` Chema Gonzalez
2022-09-02 16:13 ` Paul B Mahol
2022-09-02 18:03 ` Chema Gonzalez
2022-09-02 21:08 ` Paul B Mahol
2022-09-03 0:46 ` Chema Gonzalez
2022-09-03 9:15 ` Paul B Mahol
2022-09-03 12:07 ` Ronald S. Bultje
2022-09-12 23:49 ` Chema Gonzalez
2022-09-01 0:21 Chema Gonzalez
2022-09-01 0:22 Chema Gonzalez
2022-09-01 0:26 Chema Gonzalez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220831230918.1736362-2-chemag@gmail.com \
--to=chemag@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git