[FFmpeg-devel] [PATCH] avformat/isom: enable extended language for mov

2020-06-11 Thread Yongle Lin
Allow extended language codes using ISO designation for text tracks in mov 
format when strictness is set to experimental
---
This patch includes a support for mov format to extend language codes using ISO 
designation for text 
tracks(https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP4939-CH206-27005)
 and a FATE test associates with it.

 libavformat/isom.c   | 9 +++--
 libavformat/isom.h   | 2 +-
 libavformat/movenc.c | 6 +++---
 tests/fate/mov.mak   | 3 +++
 tests/ref/fate/mov-extended-lang | 4 
 5 files changed, 18 insertions(+), 6 deletions(-)
 create mode 100644 tests/ref/fate/mov-extended-lang

diff --git a/libavformat/isom.c b/libavformat/isom.c
index 44c7b13038..e59d085d16 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -416,7 +416,7 @@ static const char mov_mdhd_language_map[][4] = {
 "cat", "lat", "que", "grn", "aym", "tat", "uig", "dzo", "jav"
 };
 
-int ff_mov_iso639_to_lang(const char lang[4], int mp4)
+int ff_mov_iso639_to_lang(const char lang[4], int mp4, int 
strict_std_compliance)
 {
 int i, code = 0;
 
@@ -426,8 +426,13 @@ int ff_mov_iso639_to_lang(const char lang[4], int mp4)
 return i;
 }
 /* XXX:can we do that in mov too? */
-if (!mp4)
+if (!mp4 && (strict_std_compliance != FF_COMPLIANCE_EXPERIMENTAL || 
!strcmp(lang, "und"))) {
+if (strcmp(lang, "und"))
+av_log(NULL, AV_LOG_WARNING, "Non macintosh language is discarded 
for mov\n");
 return -1;
+}
+if (!mp4)
+av_log(NULL, AV_LOG_WARNING, "Experimental behavior: enable extended 
language in mov\n");
 /* handle undefined as such */
 if (lang[0] == '\0')
 lang = "und";
diff --git a/libavformat/isom.h b/libavformat/isom.h
index 41a9c64c11..9d018ebf1f 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -43,7 +43,7 @@ extern const AVCodecTag ff_codec_movaudio_tags[];
 extern const AVCodecTag ff_codec_movsubtitle_tags[];
 extern const AVCodecTag ff_codec_movdata_tags[];
 
-int ff_mov_iso639_to_lang(const char lang[4], int mp4);
+int ff_mov_iso639_to_lang(const char lang[4], int mp4, int 
strict_std_compliance);
 int ff_mov_lang_to_iso639(unsigned code, char to[4]);
 
 struct AVAESCTR;
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 5d8dc4fd5d..d833eba056 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -3429,7 +3429,7 @@ static int mov_write_string_data_tag(AVIOContext *pb, 
const char *data, int lang
 return size;
 } else {
 if (!lang)
-lang = ff_mov_iso639_to_lang("und", 1);
+lang = ff_mov_iso639_to_lang("und", 1, FF_COMPLIANCE_NORMAL);
 avio_wb16(pb, strlen(data)); /* string length */
 avio_wb16(pb, lang);
 avio_write(pb, data, strlen(data));
@@ -3468,7 +3468,7 @@ static AVDictionaryEntry 
*get_metadata_lang(AVFormatContext *s,
 while ((t2 = av_dict_get(s->metadata, tag2, t2, AV_DICT_IGNORE_SUFFIX))) {
 len2 = strlen(t2->key);
 if (len2 == len + 4 && !strcmp(t->value, t2->value)
-&& (l = ff_mov_iso639_to_lang(&t2->key[len2 - 3], 1)) >= 0) {
+&& (l = ff_mov_iso639_to_lang(&t2->key[len2 - 3], 1, 
s->strict_std_compliance)) >= 0) {
 *lang = l;
 return t;
 }
@@ -6429,7 +6429,7 @@ static int mov_init(AVFormatContext *s)
 
 track->st  = st;
 track->par = st->codecpar;
-track->language = ff_mov_iso639_to_lang(lang?lang->value:"und", 
mov->mode!=MODE_MOV);
+track->language = ff_mov_iso639_to_lang(lang?lang->value:"und", 
mov->mode!=MODE_MOV, s->strict_std_compliance);
 if (track->language < 0)
 track->language = 32767;  // Unspecified Macintosh language code
 track->mode = mov->mode;
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 7a721d7c95..522011b172 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -29,6 +29,7 @@ FATE_MOV_FFPROBE = fate-mov-neg-firstpts-discard \
fate-mov-guess-delay-2 \
fate-mov-guess-delay-3 \
fate-mov-mp4-with-mov-in24-ver \
+   fate-mov-extended-lang \
 
 FATE_MOV_FASTSTART = fate-mov-faststart-4gb-overflow \
 
@@ -124,3 +125,5 @@ fate-mov-faststart-4gb-overflow: CMP = oneline
 fate-mov-faststart-4gb-overflow: REF = bc875921f151871e787c4b4023269b29
 
 fate-mov-mp4-with-mov-in24-ver: CMD = run ffprobe$(PROGSSUF)$(EXESUF) 
-show_entries stream=codec_name -select_streams 1 
$(TARGET_SAMPLES)/mov/mp4-with-mov-in24-ver.mp4
+
+fate-mov-extended-lang: CMD = ffmpeg$(PROGSSUF)$(EXESUF) -f lavfi -i 
sine=frequency=1000:duration=15 -strict experimental -metadata:s:a:0 
language=deu -y $(TARGET_PATH)/metadata.mov; run ffprobe -show_entries 
stream=index:stream_tags=language $(TARGET_PATH)/metadata.mov; rm metadata.mov
diff --git a/tests/ref/fate/mov-extended-lang b/test

Re: [FFmpeg-devel] [PATCH] avformat/isom: enable extended language for mov

2020-06-17 Thread Yongle Lin
Dear FFmpeg Development Team,

I am an intern at Google working on FFmpeg open source project this summer.
I sent a patch in my previous email last week. Could you please take a look
at it and review the patch? I really appreciate it.

Best,
Yongle

On Thu, Jun 11, 2020 at 11:35 PM Yongle Lin  wrote:

> Allow extended language codes using ISO designation for text tracks in mov
> format when strictness is set to experimental
> ---
> This patch includes a support for mov format to extend language codes
> using ISO designation for text tracks(
> https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP4939-CH206-27005)
> and a FATE test associates with it.
>
>  libavformat/isom.c   | 9 +++--
>  libavformat/isom.h   | 2 +-
>  libavformat/movenc.c | 6 +++---
>  tests/fate/mov.mak   | 3 +++
>  tests/ref/fate/mov-extended-lang | 4 
>  5 files changed, 18 insertions(+), 6 deletions(-)
>  create mode 100644 tests/ref/fate/mov-extended-lang
>
> diff --git a/libavformat/isom.c b/libavformat/isom.c
> index 44c7b13038..e59d085d16 100644
> --- a/libavformat/isom.c
> +++ b/libavformat/isom.c
> @@ -416,7 +416,7 @@ static const char mov_mdhd_language_map[][4] = {
>  "cat", "lat", "que", "grn", "aym", "tat", "uig", "dzo", "jav"
>  };
>
> -int ff_mov_iso639_to_lang(const char lang[4], int mp4)
> +int ff_mov_iso639_to_lang(const char lang[4], int mp4, int
> strict_std_compliance)
>  {
>  int i, code = 0;
>
> @@ -426,8 +426,13 @@ int ff_mov_iso639_to_lang(const char lang[4], int mp4)
>  return i;
>  }
>  /* XXX:can we do that in mov too? */
> -if (!mp4)
> +if (!mp4 && (strict_std_compliance != FF_COMPLIANCE_EXPERIMENTAL ||
> !strcmp(lang, "und"))) {
> +if (strcmp(lang, "und"))
> +av_log(NULL, AV_LOG_WARNING, "Non macintosh language is
> discarded for mov\n");
>  return -1;
> +}
> +if (!mp4)
> +av_log(NULL, AV_LOG_WARNING, "Experimental behavior: enable
> extended language in mov\n");
>  /* handle undefined as such */
>  if (lang[0] == '\0')
>  lang = "und";
> diff --git a/libavformat/isom.h b/libavformat/isom.h
> index 41a9c64c11..9d018ebf1f 100644
> --- a/libavformat/isom.h
> +++ b/libavformat/isom.h
> @@ -43,7 +43,7 @@ extern const AVCodecTag ff_codec_movaudio_tags[];
>  extern const AVCodecTag ff_codec_movsubtitle_tags[];
>  extern const AVCodecTag ff_codec_movdata_tags[];
>
> -int ff_mov_iso639_to_lang(const char lang[4], int mp4);
> +int ff_mov_iso639_to_lang(const char lang[4], int mp4, int
> strict_std_compliance);
>  int ff_mov_lang_to_iso639(unsigned code, char to[4]);
>
>  struct AVAESCTR;
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 5d8dc4fd5d..d833eba056 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -3429,7 +3429,7 @@ static int mov_write_string_data_tag(AVIOContext
> *pb, const char *data, int lang
>  return size;
>  } else {
>  if (!lang)
> -lang = ff_mov_iso639_to_lang("und", 1);
> +lang = ff_mov_iso639_to_lang("und", 1, FF_COMPLIANCE_NORMAL);
>  avio_wb16(pb, strlen(data)); /* string length */
>  avio_wb16(pb, lang);
>  avio_write(pb, data, strlen(data));
> @@ -3468,7 +3468,7 @@ static AVDictionaryEntry
> *get_metadata_lang(AVFormatContext *s,
>  while ((t2 = av_dict_get(s->metadata, tag2, t2,
> AV_DICT_IGNORE_SUFFIX))) {
>  len2 = strlen(t2->key);
>  if (len2 == len + 4 && !strcmp(t->value, t2->value)
> -&& (l = ff_mov_iso639_to_lang(&t2->key[len2 - 3], 1)) >= 0) {
> +&& (l = ff_mov_iso639_to_lang(&t2->key[len2 - 3], 1,
> s->strict_std_compliance)) >= 0) {
>  *lang = l;
>  return t;
>  }
> @@ -6429,7 +6429,7 @@ static int mov_init(AVFormatContext *s)
>
>  track->st  = st;
>  track->par = st->codecpar;
> -track->language = ff_mov_iso639_to_lang(lang?lang->value:"und",
> mov->mode!=MODE_MOV);
> +track->language = ff_mov_iso639_to_lang(lang?lang->value:"und",
> mov->mode!=MODE_MOV, s->strict_std_compliance);
>  if (track->language < 0)
>  track->language = 32767;  // Unspecified Macintosh language
> code
>  track->mode = mov->mode;
> diff --git a/tests/fate/mo

Re: [FFmpeg-devel] [PATCH] avformat/isom: enable extended language for mov

2020-06-19 Thread Yongle Lin
Hi Derek,

Thank you for your email. I'm sorry for the misunderstanding.

Basically, ISO language can be used only for user data text in a QuickTime
file. All other elements including text tracks must be
specified using Macintosh language codes. But it's valid to have ISO codes
for text tracks of mov. So this patch allows ISO 639 codes for mov files.
For example, "-metadata language:s:0 language=deu" currently drops the
language information. I also added a sample FATE test you can check.

I see it's inappropriate to say "extended", I will correct the description
of the patch and resent it to you.

Best,
Yongle

On Thu, Jun 18, 2020 at 3:55 AM Derek Buitenhuis 
wrote:

> On 12/06/2020 00:35, Yongle Lin wrote:
> > Allow extended language codes using ISO designation for text tracks in
> mov format when strictness is set to experimental
> > ---
> > This patch includes a support for mov format to extend language codes
> using ISO designation for text tracks(
> https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP4939-CH206-27005)
> and a FATE test associates with it.
> >
> >  libavformat/isom.c   | 9 +++--
> >  libavformat/isom.h   | 2 +-
> >  libavformat/movenc.c | 6 +++---
> >  tests/fate/mov.mak   | 3 +++
> >  tests/ref/fate/mov-extended-lang | 4 
> >  5 files changed, 18 insertions(+), 6 deletions(-)
> >  create mode 100644 tests/ref/fate/mov-extended-lang
>
> The document you've linked seems to imply you should be using the elng
> atom?
>
> Perhaps I have misread, or lack context here...
>
> - Derek
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avformat/isom: allow ISO 639 codes for mov

2020-06-19 Thread Yongle Lin
Allow ISO 639 language codes for text tracks in mov format when
strictness is set to experimental
---
 libavformat/isom.c | 9 +++--
 libavformat/isom.h | 2 +-
 libavformat/movenc.c   | 6 +++---
 tests/fate/mov.mak | 3 +++
 tests/ref/fate/mov-iso639-lang | 4 
 5 files changed, 18 insertions(+), 6 deletions(-)
 create mode 100644 tests/ref/fate/mov-iso639-lang

diff --git a/libavformat/isom.c b/libavformat/isom.c
index 44c7b13038..de20ea8d8b 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -416,7 +416,7 @@ static const char mov_mdhd_language_map[][4] = {
 "cat", "lat", "que", "grn", "aym", "tat", "uig", "dzo", "jav"
 };
 
-int ff_mov_iso639_to_lang(const char lang[4], int mp4)
+int ff_mov_iso639_to_lang(const char lang[4], int mp4, int 
strict_std_compliance)
 {
 int i, code = 0;
 
@@ -426,8 +426,13 @@ int ff_mov_iso639_to_lang(const char lang[4], int mp4)
 return i;
 }
 /* XXX:can we do that in mov too? */
-if (!mp4)
+if (!mp4 && (strict_std_compliance != FF_COMPLIANCE_EXPERIMENTAL || 
!strcmp(lang, "und"))) {
+if (strcmp(lang, "und"))
+av_log(NULL, AV_LOG_WARNING, "Non macintosh language is discarded 
for mov\n");
 return -1;
+}
+if (!mp4)
+av_log(NULL, AV_LOG_WARNING, "Experimental behavior: enable iso 639 
language in mov\n");
 /* handle undefined as such */
 if (lang[0] == '\0')
 lang = "und";
diff --git a/libavformat/isom.h b/libavformat/isom.h
index 41a9c64c11..9d018ebf1f 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -43,7 +43,7 @@ extern const AVCodecTag ff_codec_movaudio_tags[];
 extern const AVCodecTag ff_codec_movsubtitle_tags[];
 extern const AVCodecTag ff_codec_movdata_tags[];
 
-int ff_mov_iso639_to_lang(const char lang[4], int mp4);
+int ff_mov_iso639_to_lang(const char lang[4], int mp4, int 
strict_std_compliance);
 int ff_mov_lang_to_iso639(unsigned code, char to[4]);
 
 struct AVAESCTR;
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 520aaafb74..4d7a98245e 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -3429,7 +3429,7 @@ static int mov_write_string_data_tag(AVIOContext *pb, 
const char *data, int lang
 return size;
 } else {
 if (!lang)
-lang = ff_mov_iso639_to_lang("und", 1);
+lang = ff_mov_iso639_to_lang("und", 1, FF_COMPLIANCE_NORMAL);
 avio_wb16(pb, strlen(data)); /* string length */
 avio_wb16(pb, lang);
 avio_write(pb, data, strlen(data));
@@ -3468,7 +3468,7 @@ static AVDictionaryEntry 
*get_metadata_lang(AVFormatContext *s,
 while ((t2 = av_dict_get(s->metadata, tag2, t2, AV_DICT_IGNORE_SUFFIX))) {
 len2 = strlen(t2->key);
 if (len2 == len + 4 && !strcmp(t->value, t2->value)
-&& (l = ff_mov_iso639_to_lang(&t2->key[len2 - 3], 1)) >= 0) {
+&& (l = ff_mov_iso639_to_lang(&t2->key[len2 - 3], 1, 
s->strict_std_compliance)) >= 0) {
 *lang = l;
 return t;
 }
@@ -6445,7 +6445,7 @@ static int mov_init(AVFormatContext *s)
 
 track->st  = st;
 track->par = st->codecpar;
-track->language = ff_mov_iso639_to_lang(lang?lang->value:"und", 
mov->mode!=MODE_MOV);
+track->language = ff_mov_iso639_to_lang(lang?lang->value:"und", 
mov->mode!=MODE_MOV, s->strict_std_compliance);
 if (track->language < 0)
 track->language = 32767;  // Unspecified Macintosh language code
 track->mode = mov->mode;
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 7a721d7c95..a85cc1a07d 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -29,6 +29,7 @@ FATE_MOV_FFPROBE = fate-mov-neg-firstpts-discard \
fate-mov-guess-delay-2 \
fate-mov-guess-delay-3 \
fate-mov-mp4-with-mov-in24-ver \
+   fate-mov-iso639-lang \
 
 FATE_MOV_FASTSTART = fate-mov-faststart-4gb-overflow \
 
@@ -124,3 +125,5 @@ fate-mov-faststart-4gb-overflow: CMP = oneline
 fate-mov-faststart-4gb-overflow: REF = bc875921f151871e787c4b4023269b29
 
 fate-mov-mp4-with-mov-in24-ver: CMD = run ffprobe$(PROGSSUF)$(EXESUF) 
-show_entries stream=codec_name -select_streams 1 
$(TARGET_SAMPLES)/mov/mp4-with-mov-in24-ver.mp4
+
+fate-mov-iso639-lang: CMD = ffmpeg$(PROGSSUF)$(EXESUF) -f lavfi -i 
sine=frequency=1000:duration=15 -strict experimental -metadata:s:a:0 
language=deu -y $(TARGET_PATH)/metadata.mov; run ffprobe -show_entries 
stream=index:stream_tags=language $(TARGET_PATH)/metadata.mov; rm metadata.mov
diff --git a/tests/ref/fate/mov-iso639-lang b/tests/ref/fate/mov-iso639-lang
new file mode 100644
index 00..6d1f61169d
--- /dev/null
+++ b/tests/ref/fate/mov-iso639-lang
@@ -0,0 +1,4 @@
+[STREAM]
+index=0
+TAG:language=deu
+[/STREAM]
-- 
2.27.0.111.gc72c7da667-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https:

[FFmpeg-devel] [PATCH] libavfilter/vf_codecview: enable qp visualization for H264 and VP9

2020-06-25 Thread Yongle Lin
Add qp visualization in codecview filter which supports H264 and VP9 codecs. 
Add options for luma/chroma qp and AC/DC qp as well. There is a old way to 
visualize it but it's deprecated since version 58.
example command line to visualize qp:
./ffmpeg -export_side_data +venc_params -i input.mp4 -vf codecview=qp=true 
output.mp4
---
 doc/filters.texi   |  6 
 libavfilter/vf_codecview.c | 69 +-
 2 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 84567dec16..f4a57e993f 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -7285,6 +7285,12 @@ backward predicted MVs of B-frames
 @item qp
 Display quantization parameters using the chroma planes.
 
+@item chroma_qp
+Display chroma quantization parameters (default luma qp) using the chroma 
planes. Should use with qp option. (e.g. codecview=qp=true:chroma_qp=true)
+
+@item dc_qp
+Display DC quantization parameters (default AC qp) using the chroma planes. 
Should use with qp option. (e.g. codecview=qp=true:dc_qp=true)
+
 @item mv_type, mvt
 Set motion vectors type to visualize. Includes MVs from all frames unless 
specified by @var{frame_type} option.
 
diff --git a/libavfilter/vf_codecview.c b/libavfilter/vf_codecview.c
index 331bfba777..f585dfe28e 100644
--- a/libavfilter/vf_codecview.c
+++ b/libavfilter/vf_codecview.c
@@ -34,6 +34,7 @@
 #include "libavutil/opt.h"
 #include "avfilter.h"
 #include "internal.h"
+#include "libavutil/video_enc_params.h"
 
 #define MV_P_FOR  (1<<0)
 #define MV_B_FOR  (1<<1)
@@ -51,6 +52,8 @@ typedef struct CodecViewContext {
 unsigned mv_type;
 int hsub, vsub;
 int qp;
+int chroma_qp;
+int dc_qp;
 } CodecViewContext;
 
 #define OFFSET(x) offsetof(CodecViewContext, x)
@@ -63,6 +66,8 @@ static const AVOption codecview_options[] = {
 CONST("bf", "forward predicted MVs of B-frames",  MV_B_FOR,  "mv"),
 CONST("bb", "backward predicted MVs of B-frames", MV_B_BACK, "mv"),
 { "qp", NULL, OFFSET(qp), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags = FLAGS 
},
+{ "chroma_qp", NULL, OFFSET(chroma_qp), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, 
.flags = FLAGS },
+{ "dc_qp", NULL, OFFSET(dc_qp), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags = 
FLAGS },
 { "mv_type", "set motion vectors type", OFFSET(mv_type), 
AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "mv_type" },
 { "mvt", "set motion vectors type", OFFSET(mv_type), 
AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "mv_type" },
 CONST("fp", "forward predicted MVs",  MV_TYPE_FOR,  "mv_type"),
@@ -212,6 +217,52 @@ static void draw_arrow(uint8_t *buf, int sx, int sy, int 
ex,
 draw_line(buf, sx, sy, ex, ey, w, h, stride, color);
 }
 
+static int qp_color_calculate(int qp, enum AVVideoEncParamsType type) {
+return type == AV_VIDEO_ENC_PARAMS_H264 ? qp * 128 / 31 : qp;
+}
+
+static void get_block_color(AVVideoEncParams *par, AVVideoBlockParams *b, 
CodecViewContext *s, enum AVColorRange color_range, int *cu, int *cv)
+{
+const int plane_qp_cu_index = s->chroma_qp ? 1 : 0;
+const int plane_qp_cv_index = s->chroma_qp ? 2 : 0;
+const int ac_dc_index = s->dc_qp ? 0 : 1;
+*cu = qp_color_calculate(par->qp + 
par->delta_qp[plane_qp_cu_index][ac_dc_index] + b->delta_qp, par->type);
+*cv = qp_color_calculate(par->qp + 
par->delta_qp[plane_qp_cv_index][ac_dc_index] + b->delta_qp, par->type);
+if (color_range == AVCOL_RANGE_MPEG) {
+// map jpeg color range(0-255) to mpeg color range(16-235)
+*cu = av_rescale(*cu, 73, 85) + 16;
+*cv = av_rescale(*cv, 73, 85) + 16;
+}
+}
+
+static void color_block(AVFrame *frame, CodecViewContext *s, const int src_x, 
const int src_y, const int b_w, const int b_h, const int cu, const int cv)
+{
+const int w = AV_CEIL_RSHIFT(frame->width,  s->hsub);
+const int h = AV_CEIL_RSHIFT(frame->height, s->vsub);
+const int lzu = frame->linesize[1];
+const int lzv = frame->linesize[2];
+
+const int plane_src_x = src_x >> s->hsub;
+const int plane_src_y = src_y >> s->vsub;
+const int plane_b_w = b_w >> s->hsub;
+const int plane_b_h = b_h >> s->vsub;
+uint8_t *pu = frame->data[1] + plane_src_y * lzu;
+uint8_t *pv = frame->data[2] + plane_src_y * lzv;
+
+for (int y = plane_src_y; y < plane_src_y + plane_b_h; y++) {
+for (int x = plane_src_x; x < plane_src_x + plane_b_w; x++) {
+if (x >= w)
+break;
+pu[x] = cu;
+pv[x] = cv;
+}
+if (y >= h)
+break;
+pu += lzu;
+pv += lzv;
+}
+}
+
 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
 {
 AVFilterContext *ctx = inlink->dst;
@@ -240,8 +291,24 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
 pv += lzv;
 }
 }
-}
 
+AVFrameSideData *sd = av_frame_get_side_data(frame, 
AV_FRAME_DATA_VIDEO_ENC_PARAMS);
+if 

[FFmpeg-devel] [PATCH] libavfilter/vf_codecview: add block structure visualization

2020-07-01 Thread Yongle Lin
example command line to visualize block decomposition:
./ffmpeg -export_side_data +venc_params -i input.webm -vf
codecview=bs=true output.webm
---
 doc/filters.texi   |  3 +++
 libavcodec/vp9.c   |  8 +++-
 libavfilter/vf_codecview.c | 41 ++
 3 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 84567dec16..db2c80b1e9 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -7285,6 +7285,9 @@ backward predicted MVs of B-frames
 @item qp
 Display quantization parameters using the chroma planes.
 
+@item bs
+Display block structure using the luma plane.
+
 @item mv_type, mvt
 Set motion vectors type to visualize. Includes MVs from all frames unless 
specified by @var{frame_type} option.
 
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index fd0bab14a2..e700def70e 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -1501,10 +1501,8 @@ static int vp9_export_enc_params(VP9Context *s, VP9Frame 
*frame)
 AVVideoEncParams *par;
 unsigned int tile, nb_blocks = 0;
 
-if (s->s.h.segmentation.enabled) {
-for (tile = 0; tile < s->active_tile_cols; tile++)
-nb_blocks += s->td[tile].nb_block_structure;
-}
+for (tile = 0; tile < s->active_tile_cols; tile++)
+nb_blocks += s->td[tile].nb_block_structure;
 
 par = av_video_enc_params_create_side_data(frame->tf.f,
 AV_VIDEO_ENC_PARAMS_VP9, nb_blocks);
@@ -1536,7 +1534,7 @@ static int vp9_export_enc_params(VP9Context *s, VP9Frame 
*frame)
 b->w = 1 << (3 + 
td->block_structure[block_tile].block_size_idx_x);
 b->h = 1 << (3 + 
td->block_structure[block_tile].block_size_idx_y);
 
-if (s->s.h.segmentation.feat[seg_id].q_enabled) {
+if (s->s.h.segmentation.enabled && 
s->s.h.segmentation.feat[seg_id].q_enabled) {
 b->delta_qp = s->s.h.segmentation.feat[seg_id].q_val;
 if (s->s.h.segmentation.absolute_vals)
 b->delta_qp -= par->qp;
diff --git a/libavfilter/vf_codecview.c b/libavfilter/vf_codecview.c
index 331bfba777..db06625d70 100644
--- a/libavfilter/vf_codecview.c
+++ b/libavfilter/vf_codecview.c
@@ -34,6 +34,7 @@
 #include "libavutil/opt.h"
 #include "avfilter.h"
 #include "internal.h"
+#include "libavutil/video_enc_params.h"
 
 #define MV_P_FOR  (1<<0)
 #define MV_B_FOR  (1<<1)
@@ -51,6 +52,7 @@ typedef struct CodecViewContext {
 unsigned mv_type;
 int hsub, vsub;
 int qp;
+int bs;
 } CodecViewContext;
 
 #define OFFSET(x) offsetof(CodecViewContext, x)
@@ -63,6 +65,7 @@ static const AVOption codecview_options[] = {
 CONST("bf", "forward predicted MVs of B-frames",  MV_B_FOR,  "mv"),
 CONST("bb", "backward predicted MVs of B-frames", MV_B_BACK, "mv"),
 { "qp", NULL, OFFSET(qp), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags = FLAGS 
},
+{ "bs", "set block structure to visualize", OFFSET(bs), AV_OPT_TYPE_BOOL, 
{.i64=0}, 0, 1, .flags = FLAGS },
 { "mv_type", "set motion vectors type", OFFSET(mv_type), 
AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "mv_type" },
 { "mvt", "set motion vectors type", OFFSET(mv_type), 
AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "mv_type" },
 CONST("fp", "forward predicted MVs",  MV_TYPE_FOR,  "mv_type"),
@@ -212,6 +215,30 @@ static void draw_arrow(uint8_t *buf, int sx, int sy, int 
ex,
 draw_line(buf, sx, sy, ex, ey, w, h, stride, color);
 }
 
+static void draw_block_border(AVFrame *frame, AVVideoBlockParams *b)
+{
+const int lzy = frame->linesize[0];
+uint8_t *py = frame->data[0] + b->src_y * lzy;
+
+for (int x = b->src_x; x < b->src_x + b->w; x++) {
+if (x >= frame->width)
+break;
+py[x] = py[x] * 3 / 4;
+}
+for (int y = b->src_y; y < b->src_y + b->h; y++) {
+if (y >= frame->height)
+break;
+py[b->src_x] = py[b->src_x] * 3 / 4;
+py[b->src_x + b->w - 1] = py[b->src_x + b->w - 1] * 3 / 4;
+py += lzy;
+}
+for (int x = b->src_x; x < b->src_x + b->w; x++) {
+if (x >= frame->width)
+break;
+py[x] = py[x] * 3 / 4;
+}
+}
+
 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
 {
 AVFilterContext *ctx = inlink->dst;
@@ -242,6 +269,20 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
 }
 }
 
+if (s->bs) {
+AVFrameSideData *sd = av_frame_get_side_data(frame, 
AV_FRAME_DATA_VIDEO_ENC_PARAMS);
+if (sd) {
+AVVideoEncParams *par = (AVVideoEncParams*)sd->data;
+
+if (par->nb_blocks) {
+for (int i = 0; i < par->nb_blocks; i++) {
+AVVideoBlockParams *b = av_video_enc_params_block(par, i);
+draw_block_border(frame, b);
+}
+}
+}
+}
+
 if (s->mv || s->mv_type) {
 AVFrameSideData *sd 

Re: [FFmpeg-devel] [PATCH] avformat/isom: allow ISO 639 codes for mov

2020-07-06 Thread Yongle Lin
On Fri, Jun 19, 2020 at 5:11 PM Yongle Lin  wrote:

> Allow ISO 639 language codes for text tracks in mov format when
> strictness is set to experimental
> ---
>  libavformat/isom.c | 9 +++--
>  libavformat/isom.h | 2 +-
>  libavformat/movenc.c   | 6 +++---
>  tests/fate/mov.mak | 3 +++
>  tests/ref/fate/mov-iso639-lang | 4 
>  5 files changed, 18 insertions(+), 6 deletions(-)
>  create mode 100644 tests/ref/fate/mov-iso639-lang
>
> diff --git a/libavformat/isom.c b/libavformat/isom.c
> index 44c7b13038..de20ea8d8b 100644
> --- a/libavformat/isom.c
> +++ b/libavformat/isom.c
> @@ -416,7 +416,7 @@ static const char mov_mdhd_language_map[][4] = {
>  "cat", "lat", "que", "grn", "aym", "tat", "uig", "dzo", "jav"
>  };
>
> -int ff_mov_iso639_to_lang(const char lang[4], int mp4)
> +int ff_mov_iso639_to_lang(const char lang[4], int mp4, int
> strict_std_compliance)
>  {
>  int i, code = 0;
>
> @@ -426,8 +426,13 @@ int ff_mov_iso639_to_lang(const char lang[4], int mp4)
>  return i;
>  }
>  /* XXX:can we do that in mov too? */
> -if (!mp4)
> +if (!mp4 && (strict_std_compliance != FF_COMPLIANCE_EXPERIMENTAL ||
> !strcmp(lang, "und"))) {
> +if (strcmp(lang, "und"))
> +av_log(NULL, AV_LOG_WARNING, "Non macintosh language is
> discarded for mov\n");
>  return -1;
> +}
> +if (!mp4)
> +av_log(NULL, AV_LOG_WARNING, "Experimental behavior: enable iso
> 639 language in mov\n");
>  /* handle undefined as such */
>  if (lang[0] == '\0')
>  lang = "und";
> diff --git a/libavformat/isom.h b/libavformat/isom.h
> index 41a9c64c11..9d018ebf1f 100644
> --- a/libavformat/isom.h
> +++ b/libavformat/isom.h
> @@ -43,7 +43,7 @@ extern const AVCodecTag ff_codec_movaudio_tags[];
>  extern const AVCodecTag ff_codec_movsubtitle_tags[];
>  extern const AVCodecTag ff_codec_movdata_tags[];
>
> -int ff_mov_iso639_to_lang(const char lang[4], int mp4);
> +int ff_mov_iso639_to_lang(const char lang[4], int mp4, int
> strict_std_compliance);
>  int ff_mov_lang_to_iso639(unsigned code, char to[4]);
>
>  struct AVAESCTR;
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 520aaafb74..4d7a98245e 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -3429,7 +3429,7 @@ static int mov_write_string_data_tag(AVIOContext
> *pb, const char *data, int lang
>  return size;
>  } else {
>  if (!lang)
> -lang = ff_mov_iso639_to_lang("und", 1);
> +lang = ff_mov_iso639_to_lang("und", 1, FF_COMPLIANCE_NORMAL);
>  avio_wb16(pb, strlen(data)); /* string length */
>  avio_wb16(pb, lang);
>  avio_write(pb, data, strlen(data));
> @@ -3468,7 +3468,7 @@ static AVDictionaryEntry
> *get_metadata_lang(AVFormatContext *s,
>  while ((t2 = av_dict_get(s->metadata, tag2, t2,
> AV_DICT_IGNORE_SUFFIX))) {
>  len2 = strlen(t2->key);
>  if (len2 == len + 4 && !strcmp(t->value, t2->value)
> -&& (l = ff_mov_iso639_to_lang(&t2->key[len2 - 3], 1)) >= 0) {
> +&& (l = ff_mov_iso639_to_lang(&t2->key[len2 - 3], 1,
> s->strict_std_compliance)) >= 0) {
>  *lang = l;
>  return t;
>  }
> @@ -6445,7 +6445,7 @@ static int mov_init(AVFormatContext *s)
>
>  track->st  = st;
>  track->par = st->codecpar;
> -track->language = ff_mov_iso639_to_lang(lang?lang->value:"und",
> mov->mode!=MODE_MOV);
> +track->language = ff_mov_iso639_to_lang(lang?lang->value:"und",
> mov->mode!=MODE_MOV, s->strict_std_compliance);
>  if (track->language < 0)
>  track->language = 32767;  // Unspecified Macintosh language
> code
>  track->mode = mov->mode;
> diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
> index 7a721d7c95..a85cc1a07d 100644
> --- a/tests/fate/mov.mak
> +++ b/tests/fate/mov.mak
> @@ -29,6 +29,7 @@ FATE_MOV_FFPROBE = fate-mov-neg-firstpts-discard \
> fate-mov-guess-delay-2 \
> fate-mov-guess-delay-3 \
> fate-mov-mp4-with-mov-in24-ver \
> +   fate-mov-iso639-lang \
>
>  FATE_MOV_FASTSTART = fate-mov-faststart-4gb-overflow \
>
> @@ -124,3 +125,5 @@ fate-mov-faststart-4gb-overflow: CMP = oneline
>  fate-mov-faststart-4gb-overflow:

Re: [FFmpeg-devel] [PATCH] libavfilter/vf_codecview: add block structure visualization

2020-07-06 Thread Yongle Lin
On Thu, Jul 2, 2020 at 8:09 AM Michael Niedermayer 
wrote:

> On Wed, Jul 01, 2020 at 05:42:48PM +0000, Yongle Lin wrote:
> > example command line to visualize block decomposition:
> > ./ffmpeg -export_side_data +venc_params -i input.webm -vf
> > codecview=bs=true output.webm
> > ---
>
> >  doc/filters.texi   |  3 +++
> >  libavcodec/vp9.c   |  8 +++-
> >  libavfilter/vf_codecview.c | 41 ++
>
> the vp9 and vf_codecview changes belong in seperate patches, these are 2
> seperate libs
>
> thx
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> In a rich man's house there is no place to spit but his face.
> -- Diogenes of Sinope
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Hi Michael,

I will separate it into two patches and re-sent to you. Thanks

Best,
Yongle
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] libavfilter/vf_codecview: enable qp visualization for H264 and VP9

2020-07-06 Thread Yongle Lin
On Thu, Jun 25, 2020 at 12:09 PM Yongle Lin  wrote:

> Add qp visualization in codecview filter which supports H264 and VP9
> codecs. Add options for luma/chroma qp and AC/DC qp as well. There is a old
> way to visualize it but it's deprecated since version 58.
> example command line to visualize qp:
> ./ffmpeg -export_side_data +venc_params -i input.mp4 -vf codecview=qp=true
> output.mp4
> ---
>  doc/filters.texi   |  6 
>  libavfilter/vf_codecview.c | 69 +-
>  2 files changed, 74 insertions(+), 1 deletion(-)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 84567dec16..f4a57e993f 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -7285,6 +7285,12 @@ backward predicted MVs of B-frames
>  @item qp
>  Display quantization parameters using the chroma planes.
>
> +@item chroma_qp
> +Display chroma quantization parameters (default luma qp) using the chroma
> planes. Should use with qp option. (e.g. codecview=qp=true:chroma_qp=true)
> +
> +@item dc_qp
> +Display DC quantization parameters (default AC qp) using the chroma
> planes. Should use with qp option. (e.g. codecview=qp=true:dc_qp=true)
> +
>  @item mv_type, mvt
>  Set motion vectors type to visualize. Includes MVs from all frames unless
> specified by @var{frame_type} option.
>
> diff --git a/libavfilter/vf_codecview.c b/libavfilter/vf_codecview.c
> index 331bfba777..f585dfe28e 100644
> --- a/libavfilter/vf_codecview.c
> +++ b/libavfilter/vf_codecview.c
> @@ -34,6 +34,7 @@
>  #include "libavutil/opt.h"
>  #include "avfilter.h"
>  #include "internal.h"
> +#include "libavutil/video_enc_params.h"
>
>  #define MV_P_FOR  (1<<0)
>  #define MV_B_FOR  (1<<1)
> @@ -51,6 +52,8 @@ typedef struct CodecViewContext {
>  unsigned mv_type;
>  int hsub, vsub;
>  int qp;
> +int chroma_qp;
> +int dc_qp;
>  } CodecViewContext;
>
>  #define OFFSET(x) offsetof(CodecViewContext, x)
> @@ -63,6 +66,8 @@ static const AVOption codecview_options[] = {
>  CONST("bf", "forward predicted MVs of B-frames",  MV_B_FOR,
> "mv"),
>  CONST("bb", "backward predicted MVs of B-frames", MV_B_BACK,
> "mv"),
>  { "qp", NULL, OFFSET(qp), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags =
> FLAGS },
> +{ "chroma_qp", NULL, OFFSET(chroma_qp), AV_OPT_TYPE_BOOL, {.i64=0},
> 0, 1, .flags = FLAGS },
> +{ "dc_qp", NULL, OFFSET(dc_qp), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1,
> .flags = FLAGS },
>  { "mv_type", "set motion vectors type", OFFSET(mv_type),
> AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "mv_type" },
>  { "mvt", "set motion vectors type", OFFSET(mv_type),
> AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "mv_type" },
>  CONST("fp", "forward predicted MVs",  MV_TYPE_FOR,  "mv_type"),
> @@ -212,6 +217,52 @@ static void draw_arrow(uint8_t *buf, int sx, int sy,
> int ex,
>  draw_line(buf, sx, sy, ex, ey, w, h, stride, color);
>  }
>
> +static int qp_color_calculate(int qp, enum AVVideoEncParamsType type) {
> +return type == AV_VIDEO_ENC_PARAMS_H264 ? qp * 128 / 31 : qp;
> +}
> +
> +static void get_block_color(AVVideoEncParams *par, AVVideoBlockParams *b,
> CodecViewContext *s, enum AVColorRange color_range, int *cu, int *cv)
> +{
> +const int plane_qp_cu_index = s->chroma_qp ? 1 : 0;
> +const int plane_qp_cv_index = s->chroma_qp ? 2 : 0;
> +const int ac_dc_index = s->dc_qp ? 0 : 1;
> +*cu = qp_color_calculate(par->qp +
> par->delta_qp[plane_qp_cu_index][ac_dc_index] + b->delta_qp, par->type);
> +*cv = qp_color_calculate(par->qp +
> par->delta_qp[plane_qp_cv_index][ac_dc_index] + b->delta_qp, par->type);
> +if (color_range == AVCOL_RANGE_MPEG) {
> +// map jpeg color range(0-255) to mpeg color range(16-235)
> +*cu = av_rescale(*cu, 73, 85) + 16;
> +*cv = av_rescale(*cv, 73, 85) + 16;
> +}
> +}
> +
> +static void color_block(AVFrame *frame, CodecViewContext *s, const int
> src_x, const int src_y, const int b_w, const int b_h, const int cu, const
> int cv)
> +{
> +const int w = AV_CEIL_RSHIFT(frame->width,  s->hsub);
> +const int h = AV_CEIL_RSHIFT(frame->height, s->vsub);
> +const int lzu = frame->linesize[1];
> +const int lzv = frame->linesize[2];
> +
> +const int plane_src_x = src_x >> s->hsub;
> +const int plane_src_y = src_y >> s->vsub;
> +const int

[FFmpeg-devel] [PATCH] libavcodec/vp9: export block structure when segmentation isn't enable

2020-07-06 Thread Yongle Lin
it makes sense to export block structure like src_x, src_y, width and
height when segmentation isn't enable so we could visualize and see the
structure of the block.
---
 libavcodec/vp9.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index fd0bab14a2..e700def70e 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -1501,10 +1501,8 @@ static int vp9_export_enc_params(VP9Context *s, VP9Frame 
*frame)
 AVVideoEncParams *par;
 unsigned int tile, nb_blocks = 0;
 
-if (s->s.h.segmentation.enabled) {
-for (tile = 0; tile < s->active_tile_cols; tile++)
-nb_blocks += s->td[tile].nb_block_structure;
-}
+for (tile = 0; tile < s->active_tile_cols; tile++)
+nb_blocks += s->td[tile].nb_block_structure;
 
 par = av_video_enc_params_create_side_data(frame->tf.f,
 AV_VIDEO_ENC_PARAMS_VP9, nb_blocks);
@@ -1536,7 +1534,7 @@ static int vp9_export_enc_params(VP9Context *s, VP9Frame 
*frame)
 b->w = 1 << (3 + 
td->block_structure[block_tile].block_size_idx_x);
 b->h = 1 << (3 + 
td->block_structure[block_tile].block_size_idx_y);
 
-if (s->s.h.segmentation.feat[seg_id].q_enabled) {
+if (s->s.h.segmentation.enabled && 
s->s.h.segmentation.feat[seg_id].q_enabled) {
 b->delta_qp = s->s.h.segmentation.feat[seg_id].q_val;
 if (s->s.h.segmentation.absolute_vals)
 b->delta_qp -= par->qp;
-- 
2.27.0.383.g050319c2ae-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] libavfilter/vf_codecview: add block structure visualization

2020-07-06 Thread Yongle Lin
example command line to visualize block decomposition:
./ffmpeg -export_side_data +venc_params -i input.webm -vf
codecview=bs=true output.webm
---
 doc/filters.texi   |  3 +++
 libavfilter/vf_codecview.c | 41 ++
 2 files changed, 44 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index 84567dec16..db2c80b1e9 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -7285,6 +7285,9 @@ backward predicted MVs of B-frames
 @item qp
 Display quantization parameters using the chroma planes.
 
+@item bs
+Display block structure using the luma plane.
+
 @item mv_type, mvt
 Set motion vectors type to visualize. Includes MVs from all frames unless 
specified by @var{frame_type} option.
 
diff --git a/libavfilter/vf_codecview.c b/libavfilter/vf_codecview.c
index 331bfba777..db06625d70 100644
--- a/libavfilter/vf_codecview.c
+++ b/libavfilter/vf_codecview.c
@@ -34,6 +34,7 @@
 #include "libavutil/opt.h"
 #include "avfilter.h"
 #include "internal.h"
+#include "libavutil/video_enc_params.h"
 
 #define MV_P_FOR  (1<<0)
 #define MV_B_FOR  (1<<1)
@@ -51,6 +52,7 @@ typedef struct CodecViewContext {
 unsigned mv_type;
 int hsub, vsub;
 int qp;
+int bs;
 } CodecViewContext;
 
 #define OFFSET(x) offsetof(CodecViewContext, x)
@@ -63,6 +65,7 @@ static const AVOption codecview_options[] = {
 CONST("bf", "forward predicted MVs of B-frames",  MV_B_FOR,  "mv"),
 CONST("bb", "backward predicted MVs of B-frames", MV_B_BACK, "mv"),
 { "qp", NULL, OFFSET(qp), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags = FLAGS 
},
+{ "bs", "set block structure to visualize", OFFSET(bs), AV_OPT_TYPE_BOOL, 
{.i64=0}, 0, 1, .flags = FLAGS },
 { "mv_type", "set motion vectors type", OFFSET(mv_type), 
AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "mv_type" },
 { "mvt", "set motion vectors type", OFFSET(mv_type), 
AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "mv_type" },
 CONST("fp", "forward predicted MVs",  MV_TYPE_FOR,  "mv_type"),
@@ -212,6 +215,30 @@ static void draw_arrow(uint8_t *buf, int sx, int sy, int 
ex,
 draw_line(buf, sx, sy, ex, ey, w, h, stride, color);
 }
 
+static void draw_block_border(AVFrame *frame, AVVideoBlockParams *b)
+{
+const int lzy = frame->linesize[0];
+uint8_t *py = frame->data[0] + b->src_y * lzy;
+
+for (int x = b->src_x; x < b->src_x + b->w; x++) {
+if (x >= frame->width)
+break;
+py[x] = py[x] * 3 / 4;
+}
+for (int y = b->src_y; y < b->src_y + b->h; y++) {
+if (y >= frame->height)
+break;
+py[b->src_x] = py[b->src_x] * 3 / 4;
+py[b->src_x + b->w - 1] = py[b->src_x + b->w - 1] * 3 / 4;
+py += lzy;
+}
+for (int x = b->src_x; x < b->src_x + b->w; x++) {
+if (x >= frame->width)
+break;
+py[x] = py[x] * 3 / 4;
+}
+}
+
 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
 {
 AVFilterContext *ctx = inlink->dst;
@@ -242,6 +269,20 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
 }
 }
 
+if (s->bs) {
+AVFrameSideData *sd = av_frame_get_side_data(frame, 
AV_FRAME_DATA_VIDEO_ENC_PARAMS);
+if (sd) {
+AVVideoEncParams *par = (AVVideoEncParams*)sd->data;
+
+if (par->nb_blocks) {
+for (int i = 0; i < par->nb_blocks; i++) {
+AVVideoBlockParams *b = av_video_enc_params_block(par, i);
+draw_block_border(frame, b);
+}
+}
+}
+}
+
 if (s->mv || s->mv_type) {
 AVFrameSideData *sd = av_frame_get_side_data(frame, 
AV_FRAME_DATA_MOTION_VECTORS);
 if (sd) {
-- 
2.27.0.383.g050319c2ae-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-06 Thread Yongle Lin
add block type field to AVVideoBlockParams so we could either export or 
visualize it later.
---
 libavutil/video_enc_params.h | 20 
 1 file changed, 20 insertions(+)

diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
index 43fa443154..55b9fc4031 100644
--- a/libavutil/video_enc_params.h
+++ b/libavutil/video_enc_params.h
@@ -101,6 +101,21 @@ typedef struct AVVideoEncParams {
 int32_t delta_qp[4][2];
 } AVVideoEncParams;
 
+typedef struct MacroBlockType {
+/**
+ * Is intra prediction
+ */
+int intra;
+/**
+ * Skip flag
+ */
+int skip;
+/**
+ * Reference to the past or future
+ */
+int ref[2];
+} MacroBlockType;
+
 /**
  * Data structure for storing block-level encoding information.
  * It is allocated as a part of AVVideoEncParams and should be retrieved with
@@ -126,6 +141,11 @@ typedef struct AVVideoBlockParams {
  * corresponding per-frame value.
  */
 int32_t delta_qp;
+
+/**
+ * Type of block
+ */
+MacroBlockType mb_type;
 } AVVideoBlockParams;
 
 /*
-- 
2.27.0.383.g050319c2ae-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/isom: allow ISO 639 codes for mov

2020-07-07 Thread Yongle Lin
On Mon, Jul 6, 2020 at 3:23 PM Baptiste Coudurier <
baptiste.coudur...@gmail.com> wrote:

> Hi Yongle, I hope you are doing well
>
> > On Jul 6, 2020, at 11:04 AM, Yongle Lin  wrote:
> >
> > On Fri, Jun 19, 2020 at 5:11 PM Yongle Lin  <mailto:yongle.lin...@gmail.com>> wrote:
> >
> >> Allow ISO 639 language codes for text tracks in mov format when
> >> strictness is set to experimental
> >> ---
> >> libavformat/isom.c | 9 +++--
> >> libavformat/isom.h | 2 +-
> >> libavformat/movenc.c   | 6 +++---
> >> tests/fate/mov.mak | 3 +++
> >> tests/ref/fate/mov-iso639-lang | 4 
> >> 5 files changed, 18 insertions(+), 6 deletions(-)
> >> create mode 100644 tests/ref/fate/mov-iso639-lang
> >>
> >> diff --git a/libavformat/isom.c b/libavformat/isom.c
> >> index 44c7b13038..de20ea8d8b 100644
> >> --- a/libavformat/isom.c
> >> +++ b/libavformat/isom.c
> >> @@ -416,7 +416,7 @@ static const char mov_mdhd_language_map[][4] = {
> >> "cat", "lat", "que", "grn", "aym", "tat", "uig", "dzo", "jav"
> >> };
> >>
> >> -int ff_mov_iso639_to_lang(const char lang[4], int mp4)
> >> +int ff_mov_iso639_to_lang(const char lang[4], int mp4, int
> >> strict_std_compliance)
> >> {
> >> int i, code = 0;
> >>
> >> @@ -426,8 +426,13 @@ int ff_mov_iso639_to_lang(const char lang[4], int
> mp4)
> >> return i;
> >> }
> >> /* XXX:can we do that in mov too? */
> >> -if (!mp4)
> >> +if (!mp4 && (strict_std_compliance != FF_COMPLIANCE_EXPERIMENTAL ||
> >> !strcmp(lang, "und"))) {
> >> +if (strcmp(lang, "und"))
> >> +av_log(NULL, AV_LOG_WARNING, "Non macintosh language is
> >> discarded for mov\n");
> >> return -1;
> >> +}
> >> +if (!mp4)
> >> +av_log(NULL, AV_LOG_WARNING, "Experimental behavior: enable iso
> >> 639 language in mov\n");
> >> /* handle undefined as such */
> >> if (lang[0] == '\0')
> >> lang = "und";
> >> diff --git a/libavformat/isom.h b/libavformat/isom.h
> >> index 41a9c64c11..9d018ebf1f 100644
> >> --- a/libavformat/isom.h
> >> +++ b/libavformat/isom.h
> >> @@ -43,7 +43,7 @@ extern const AVCodecTag ff_codec_movaudio_tags[];
> >> extern const AVCodecTag ff_codec_movsubtitle_tags[];
> >> extern const AVCodecTag ff_codec_movdata_tags[];
> >>
> >> -int ff_mov_iso639_to_lang(const char lang[4], int mp4);
> >> +int ff_mov_iso639_to_lang(const char lang[4], int mp4, int
> >> strict_std_compliance);
> >> int ff_mov_lang_to_iso639(unsigned code, char to[4]);
> >>
> >> struct AVAESCTR;
> >> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> >> index 520aaafb74..4d7a98245e 100644
> >> --- a/libavformat/movenc.c
> >> +++ b/libavformat/movenc.c
> >> @@ -3429,7 +3429,7 @@ static int mov_write_string_data_tag(AVIOContext
> >> *pb, const char *data, int lang
> >> return size;
> >> } else {
> >> if (!lang)
> >> -lang = ff_mov_iso639_to_lang("und", 1);
> >> +lang = ff_mov_iso639_to_lang("und", 1,
> FF_COMPLIANCE_NORMAL);
> >> avio_wb16(pb, strlen(data)); /* string length */
> >> avio_wb16(pb, lang);
> >> avio_write(pb, data, strlen(data));
> >> @@ -3468,7 +3468,7 @@ static AVDictionaryEntry
> >> *get_metadata_lang(AVFormatContext *s,
> >> while ((t2 = av_dict_get(s->metadata, tag2, t2,
> >> AV_DICT_IGNORE_SUFFIX))) {
> >> len2 = strlen(t2->key);
> >> if (len2 == len + 4 && !strcmp(t->value, t2->value)
> >> -&& (l = ff_mov_iso639_to_lang(&t2->key[len2 - 3], 1)) >=
> 0) {
> >> +&& (l = ff_mov_iso639_to_lang(&t2->key[len2 - 3], 1,
> >> s->strict_std_compliance)) >= 0) {
> >> *lang = l;
> >> return t;
> >> }
> >> @@ -6445,7 +6445,7 @@ static int mov_init(AVFormatContext *s)
> >>
> >> track->st  = st;
> >> track->par = st->codecpar;
> >> -track->language = ff_mo

Re: [FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-07 Thread Yongle Lin
On Mon, Jul 6, 2020 at 3:08 PM Mark Thompson  wrote:

> On 06/07/2020 22:08, Yongle Lin wrote:
> > add block type field to AVVideoBlockParams so we could either export or
> visualize it later.
> > ---
> >   libavutil/video_enc_params.h | 20 
> >   1 file changed, 20 insertions(+)
> >
> > diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
> > index 43fa443154..55b9fc4031 100644
> > --- a/libavutil/video_enc_params.h
> > +++ b/libavutil/video_enc_params.h
> > @@ -101,6 +101,21 @@ typedef struct AVVideoEncParams {
> >   int32_t delta_qp[4][2];
> >   } AVVideoEncParams;
> >
> > +typedef struct MacroBlockType {
> > +/**
> > + * Is intra prediction
> > + */
> > +int intra;
> > +/**
> > + * Skip flag
> > + */
> > +int skip;
> > +/**
> > + * Reference to the past or future
> > + */
> > +int ref[2];
>
> Please can you define carefully in the documentation exactly what each of
> these fields mean, as is done for the QP values above?
>
> (That is, there should be enough information to determine what exactly is
> meant if I am given one of these structures with, say, intra = 3, skip = 7,
> ref = { 5, 1 }.)
>
I will add more detailed explanation to the comment. These fields are all
boolean and I will add bit fields to minimize the size.

>
> > +} MacroBlockType;
>
> Structures in the public API need to carry the "AV" namespace prefix.
>
> I'm not sure that "macroblock" is a good word to use here: many codecs
> have no concept called a "macroblock", and invoking a word with a specific
> definition in only some contexts seems unhelpful.
>
I will change the name to make it more meaningful.

>
> > +
> >   /**
> >* Data structure for storing block-level encoding information.
> >* It is allocated as a part of AVVideoEncParams and should be
> retrieved with
> > @@ -126,6 +141,11 @@ typedef struct AVVideoBlockParams {
> >* corresponding per-frame value.
> >*/
> >   int32_t delta_qp;
> > +
> > +/**
> > + * Type of block
> > + */
> > +MacroBlockType mb_type;
> >   } AVVideoBlockParams;
> >
> >   /*
> >
>
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-07 Thread Yongle Lin
On Tue, Jul 7, 2020 at 12:59 AM Anton Khirnov  wrote:

> Quoting Yongle Lin (2020-07-06 23:08:17)
> > add block type field to AVVideoBlockParams so we could either export or
> visualize it later.
> > ---
> >  libavutil/video_enc_params.h | 20 
> >  1 file changed, 20 insertions(+)
>
> We generally require new APIs to be immediately useful. So in this case,
> there should also be a patch that makes some decoder export those
> fields.
>
> >
> > diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
> > index 43fa443154..55b9fc4031 100644
> > --- a/libavutil/video_enc_params.h
> > +++ b/libavutil/video_enc_params.h
> > @@ -101,6 +101,21 @@ typedef struct AVVideoEncParams {
> >  int32_t delta_qp[4][2];
> >  } AVVideoEncParams;
> >
> > +typedef struct MacroBlockType {
> > +/**
> > + * Is intra prediction
> > + */
> > +int intra;
> > +/**
> > + * Skip flag
> > + */
> > +int skip;
>
> These structures are stored per-block, so it seems pretty wasteful to
> spend a whole int (4 bytes) when only one bit is used.
>
You are right. I should add bit fields to restrict the size. Do you think
it makes more sense to unwrap the fields and put them all in
AVVideoBlockParams or pack them in a struct like this? Thanks.

>
> --
> Anton Khirnov
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-07 Thread Yongle Lin
add block type field to AVVideoBlockParams so we could either export or 
visualize it later.
---
 libavutil/video_enc_params.h | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
index 43fa443154..bff5354a8d 100644
--- a/libavutil/video_enc_params.h
+++ b/libavutil/video_enc_params.h
@@ -126,6 +126,21 @@ typedef struct AVVideoBlockParams {
  * corresponding per-frame value.
  */
 int32_t delta_qp;
+
+/**
+ * Type of block
+ * Each bit field indicates a type flag:
+ * - (1 << 0) Intra prediction flag for the block
+ *   1 indicates that prediction type is intra, otherwise inter
+ * - (1 << 1) Skip flag for the block
+ *   1 indicates that a block has no residual coefficients, 0 otherwise
+ */
+ uint64_t type;
+
+/**
+ * Reference frames used for prediction
+ */
+ uint8_t ref[8];
 } AVVideoBlockParams;
 
 /*
-- 
2.27.0.383.g050319c2ae-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-07 Thread Yongle Lin
On Tue, Jul 7, 2020 at 2:09 PM Lynne  wrote:

> Jul 7, 2020, 21:25 by yongle.lin...@gmail.com:
>
> > add block type field to AVVideoBlockParams so we could either export or
> visualize it later.
> > ---
> >  libavutil/video_enc_params.h | 15 +++
> >  1 file changed, 15 insertions(+)
> >
> > diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
> > index 43fa443154..bff5354a8d 100644
> > --- a/libavutil/video_enc_params.h
> > +++ b/libavutil/video_enc_params.h
> > @@ -126,6 +126,21 @@ typedef struct AVVideoBlockParams {
> >  * corresponding per-frame value.
> >  */
> >  int32_t delta_qp;
> > +
> > +/**
> > + * Type of block
> > + * Each bit field indicates a type flag:
> > + * - (1 << 0) Intra prediction flag for the block
> > + *   1 indicates that prediction type is intra, otherwise inter
> > + * - (1 << 1) Skip flag for the block
> > + *   1 indicates that a block has no residual coefficients, 0
> otherwise
> > + */
> > + uint64_t type;
> >
>
> You also need to define the flags by an enum or a define.
>
> enum AVVideoBlockFlags {
> AV_VIDEO_ENC_BLOCK_INTRA = 1ULL <<  0, /* Indicates block uses
> intraprediction */
> AV_VIDEO_ENC_BLOCK_SKIP = 1ULL <<  1, /* Indicates block is not coded
> (skipped) */
> };
>
> Using 1ULL forces the enum to be 64-bit unsigned, so you can specify it in
> the struct like:
> enum AVVideoBlockFlags flags;
> Rather than just a uint64_t.
>
Thank you so much for the suggestion. It makes much more sense. I will
change the patch accordingly.

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-07 Thread Yongle Lin
add block type field to AVVideoBlockParams so we could either export or 
visualize it later.
---
 libavutil/video_enc_params.h | 16 
 1 file changed, 16 insertions(+)

diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
index 43fa443154..c18dba7879 100644
--- a/libavutil/video_enc_params.h
+++ b/libavutil/video_enc_params.h
@@ -57,6 +57,11 @@ enum AVVideoEncParamsType {
 AV_VIDEO_ENC_PARAMS_H264,
 };
 
+enum AVVideoBlockType {
+AV_VIDEO_ENC_BLOCK_INTRA = 1ULL <<  0,  /* Indicates block uses intra 
prediction */
+AV_VIDEO_ENC_BLOCK_SKIP = 1ULL <<  1,   /* Indicates block is not coded 
(skipped) */
+};
+
 /**
  * Video encoding parameters for a given frame. This struct is allocated along
  * with an optional array of per-block AVVideoBlockParams descriptors.
@@ -126,6 +131,17 @@ typedef struct AVVideoBlockParams {
  * corresponding per-frame value.
  */
 int32_t delta_qp;
+
+/**
+ * Type of block
+ * Each bit field indicates a type flag
+ */
+enum AVVideoBlockType type;
+
+/**
+ * Reference frames used for prediction
+ */
+uint8_t ref[8];
 } AVVideoBlockParams;
 
 /*
-- 
2.27.0.383.g050319c2ae-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-07 Thread Yongle Lin
On Tue, Jul 7, 2020 at 3:33 PM Lynne  wrote:

> Jul 7, 2020, 23:11 by yongle.lin...@gmail.com:
>
> > add block type field to AVVideoBlockParams so we could either export or
> visualize it later.
> > ---
> >  libavutil/video_enc_params.h | 16 
> >  1 file changed, 16 insertions(+)
> >
> > diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
> > index 43fa443154..c18dba7879 100644
> > --- a/libavutil/video_enc_params.h
> > +++ b/libavutil/video_enc_params.h
> > @@ -57,6 +57,11 @@ enum AVVideoEncParamsType {
> >  AV_VIDEO_ENC_PARAMS_H264,
> >  };
> >
> > +enum AVVideoBlockType {
> > +AV_VIDEO_ENC_BLOCK_INTRA = 1ULL <<  0,  /* Indicates block uses
> intra prediction */
> > +AV_VIDEO_ENC_BLOCK_SKIP = 1ULL <<  1,   /* Indicates block is not
> coded (skipped) */
> > +};
> > +
> >  /**
> >  * Video encoding parameters for a given frame. This struct is allocated
> along
> >  * with an optional array of per-block AVVideoBlockParams descriptors.
> > @@ -126,6 +131,17 @@ typedef struct AVVideoBlockParams {
> >  * corresponding per-frame value.
> >  */
> >  int32_t delta_qp;
> > +
> > +/**
> > + * Type of block
> > + * Each bit field indicates a type flag
> > + */
> > +enum AVVideoBlockType type;
> >
>
> I would like to have the name "type" reserved for the future when we might
> have to
> specify a block type using a specific type rather than using flags.
> So could you rename this to "flags" instead?


> Apart from that, this looks fine to me.
>
I see.
Sure. I will change it to flags. Thanks.

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-07 Thread Yongle Lin
add block type field to AVVideoBlockParams so we could either export or 
visualize it later.
---
 libavutil/video_enc_params.h | 16 
 1 file changed, 16 insertions(+)

diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
index 43fa443154..52c0058f5b 100644
--- a/libavutil/video_enc_params.h
+++ b/libavutil/video_enc_params.h
@@ -57,6 +57,11 @@ enum AVVideoEncParamsType {
 AV_VIDEO_ENC_PARAMS_H264,
 };
 
+enum AVVideoBlockFlags {
+AV_VIDEO_ENC_BLOCK_INTRA = 1ULL <<  0,  /* Indicates block uses intra 
prediction */
+AV_VIDEO_ENC_BLOCK_SKIP = 1ULL <<  1,   /* Indicates block is not coded 
(skipped) */
+};
+
 /**
  * Video encoding parameters for a given frame. This struct is allocated along
  * with an optional array of per-block AVVideoBlockParams descriptors.
@@ -126,6 +131,17 @@ typedef struct AVVideoBlockParams {
  * corresponding per-frame value.
  */
 int32_t delta_qp;
+
+/**
+ * Type flag of the block
+ * Each bit field indicates a type flag
+ */
+enum AVVideoBlockFlags flags;
+
+/**
+ * Reference frames used for prediction
+ */
+uint8_t ref[8];
 } AVVideoBlockParams;
 
 /*
-- 
2.27.0.383.g050319c2ae-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-07 Thread Yongle Lin
On Tue, Jul 7, 2020 at 10:54 PM Lynne  wrote:

> Jul 7, 2020, 23:47 by yongle.lin...@gmail.com:
>
> > add block type field to AVVideoBlockParams so we could either export or
> visualize it later.
> > ---
> >  libavutil/video_enc_params.h | 16 
> >  1 file changed, 16 insertions(+)
> >
> > diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
> > index 43fa443154..52c0058f5b 100644
> > --- a/libavutil/video_enc_params.h
> > +++ b/libavutil/video_enc_params.h
> > @@ -57,6 +57,11 @@ enum AVVideoEncParamsType {
> >  AV_VIDEO_ENC_PARAMS_H264,
> >  };
> >
> > +enum AVVideoBlockFlags {
> > +AV_VIDEO_ENC_BLOCK_INTRA = 1ULL <<  0,  /* Indicates block uses
> intra prediction */
> > +AV_VIDEO_ENC_BLOCK_SKIP = 1ULL <<  1,   /* Indicates block is not
> coded (skipped) */
> > +};
> > +
> >  /**
> >  * Video encoding parameters for a given frame. This struct is allocated
> along
> >  * with an optional array of per-block AVVideoBlockParams descriptors.
> > @@ -126,6 +131,17 @@ typedef struct AVVideoBlockParams {
> >  * corresponding per-frame value.
> >  */
> >  int32_t delta_qp;
> > +
> > +/**
> > + * Type flag of the block
> > + * Each bit field indicates a type flag
> > + */
> > +enum AVVideoBlockFlags flags;
> > +
> > +/**
> > + * Reference frames used for prediction
> > + */
> > +uint8_t ref[8];
> >  } AVVideoBlockParams;
> >
>
> After some discussion on IRC, could you clarify the ref array description
> to this:
>
> > Each entry specifies the first/second/third/etc. reference frame the
> current frame uses.
> > The value at each entry specifies the index inside the reference frame
> array for that current frame.
>
> E.g. your current frame has 6 valid possible references, and your frame
> header specifies you
> can use ref_frame[3] and ref_frame[5] as a reference.
> So the values of ref[] for each block must be either 3 or 5.
> Its convoluted because the array maps indices to indices but it makes
> sense.
>
Yes. That makes sense to me. So the ref array stores the index of reference
frame in the ref_frame[]

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-07 Thread Yongle Lin
add block type field to AVVideoBlockParams so we could either export or 
visualize it later.
---
 libavutil/video_enc_params.h | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
index 43fa443154..8bf5f240c9 100644
--- a/libavutil/video_enc_params.h
+++ b/libavutil/video_enc_params.h
@@ -57,6 +57,11 @@ enum AVVideoEncParamsType {
 AV_VIDEO_ENC_PARAMS_H264,
 };
 
+enum AVVideoBlockFlags {
+AV_VIDEO_ENC_BLOCK_INTRA = 1ULL <<  0,  /* Indicates block uses intra 
prediction */
+AV_VIDEO_ENC_BLOCK_SKIP = 1ULL <<  1,   /* Indicates block is not coded 
(skipped) */
+};
+
 /**
  * Video encoding parameters for a given frame. This struct is allocated along
  * with an optional array of per-block AVVideoBlockParams descriptors.
@@ -126,6 +131,20 @@ typedef struct AVVideoBlockParams {
  * corresponding per-frame value.
  */
 int32_t delta_qp;
+
+/**
+ * Type flag of the block
+ * Each bit field indicates a type flag
+ */
+enum AVVideoBlockFlags flags;
+
+/**
+ * Reference frames used for prediction
+ * Each entry specifies the first/second/third/etc. reference frame the 
current frame uses.
+ * The value at each entry specifies the index inside the reference frame 
array for that current frame.
+ * Any entry that is unused will be set to -1
+ */
+int8_t ref[8];
 } AVVideoBlockParams;
 
 /*
-- 
2.27.0.383.g050319c2ae-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-07 Thread Yongle Lin
On Tue, Jul 7, 2020 at 4:08 PM Mark Thompson  wrote:

> On 07/07/2020 23:54, Lynne wrote:
> > Jul 7, 2020, 23:47 by yongle.lin...@gmail.com:
> >
> >> add block type field to AVVideoBlockParams so we could either export or
> visualize it later.
> >> ---
> >>   libavutil/video_enc_params.h | 16 
> >>   1 file changed, 16 insertions(+)
> >>
> >> diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
> >> index 43fa443154..52c0058f5b 100644
> >> --- a/libavutil/video_enc_params.h
> >> +++ b/libavutil/video_enc_params.h
> >> @@ -57,6 +57,11 @@ enum AVVideoEncParamsType {
> >>   AV_VIDEO_ENC_PARAMS_H264,
> >>   };
> >>
> >> +enum AVVideoBlockFlags {
> >> +AV_VIDEO_ENC_BLOCK_INTRA = 1ULL <<  0,  /* Indicates block uses
> intra prediction */
> >> +AV_VIDEO_ENC_BLOCK_SKIP = 1ULL <<  1,   /* Indicates block is not
> coded (skipped) */
> >> +};
> >> +
> >>   /**
> >>   * Video encoding parameters for a given frame. This struct is
> allocated along
> >>   * with an optional array of per-block AVVideoBlockParams descriptors.
> >> @@ -126,6 +131,17 @@ typedef struct AVVideoBlockParams {
> >>   * corresponding per-frame value.
> >>   */
> >>   int32_t delta_qp;
> >> +
> >> +/**
> >> + * Type flag of the block
> >> + * Each bit field indicates a type flag
> >> + */
> >> +enum AVVideoBlockFlags flags;
> >> +
> >> +/**
> >> + * Reference frames used for prediction
> >> + */
> >> +uint8_t ref[8];
> >>   } AVVideoBlockParams;
> >>
> >
> > After some discussion on IRC, could you clarify the ref array
> description to this:
> >
> >> Each entry specifies the first/second/third/etc. reference frame the
> current frame uses.
> >> The value at each entry specifies the index inside the reference frame
> array for that current frame.
> >
> > E.g. your current frame has 6 valid possible references, and your frame
> header specifies you
> > can use ref_frame[3] and ref_frame[5] as a reference.
> > So the values of ref[] for each block must be either 3 or 5.
> > Its convoluted because the array maps indices to indices but it makes
> sense.
>
> Please also define it precisely for H.264, the other supported codec.
>
> I came up with:
>
> """
> For H.264, the values in this array are indices into the default
> RefPicList0 as constructed by 8.2.4.2 (before ref pic list modification has
> run and without any truncation).
> If the block is intra-coded, no entries are valid.
> If the block in inter-coded with reference to a single picture, ref[0]
> containes the index of that picture (which might have come from L0 or L1
> list).
> If the block is inter-coded using biprediction, ref[0] contains the index
> of the L0 picture and ref[1] contains the index of the L1 picture.
> """
>
> Not sure if that's doing exactly the right thing or matches what you
> intended, but this is tricky so it needs that level of detail.
>
> 8 distinct reference pictures also seems slightly ambitious for a single
> lowest-level block, but I guess the future is always about
> ever-more-complex coding tools...
>


That's a good approach. I think currently we only support H.264 and VP9
codecs for block data. For VP9, we might use the same logic.

>
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-08 Thread Yongle Lin
On Tue, Jul 7, 2020 at 12:59 AM Anton Khirnov  wrote:

> Quoting Yongle Lin (2020-07-06 23:08:17)
> > add block type field to AVVideoBlockParams so we could either export or
> visualize it later.
> > ---
> >  libavutil/video_enc_params.h | 20 
> >  1 file changed, 20 insertions(+)
>
> We generally require new APIs to be immediately useful. So in this case,
> there should also be a patch that makes some decoder export those
> fields.
>

I plan to send separate patches for H264 and VP9 to export type data and
another patch to visualize the block type in codecview filter when I get
approved for this patch.
Do you want me to add the "decoder export" code to this patch so that it
will be immediately useful? Thanks


> >
> > diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
> > index 43fa443154..55b9fc4031 100644
> > --- a/libavutil/video_enc_params.h
> > +++ b/libavutil/video_enc_params.h
> > @@ -101,6 +101,21 @@ typedef struct AVVideoEncParams {
> >  int32_t delta_qp[4][2];
> >  } AVVideoEncParams;
> >
> > +typedef struct MacroBlockType {
> > +/**
> > + * Is intra prediction
> > + */
> > +int intra;
> > +/**
> > + * Skip flag
> > + */
> > +int skip;
>
> These structures are stored per-block, so it seems pretty wasteful to
> spend a whole int (4 bytes) when only one bit is used.
>
> --
> Anton Khirnov
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] libavfilter/vf_codecview: enable qp visualization for H264 and VP9

2020-07-09 Thread Yongle Lin
On Mon, Jul 6, 2020 at 10:56 AM Yongle Lin  wrote:

>
>
> On Thu, Jun 25, 2020 at 12:09 PM Yongle Lin 
> wrote:
>
>> Add qp visualization in codecview filter which supports H264 and VP9
>> codecs. Add options for luma/chroma qp and AC/DC qp as well. There is a old
>> way to visualize it but it's deprecated since version 58.
>> example command line to visualize qp:
>> ./ffmpeg -export_side_data +venc_params -i input.mp4 -vf
>> codecview=qp=true output.mp4
>> ---
>>  doc/filters.texi   |  6 
>>  libavfilter/vf_codecview.c | 69 +-
>>  2 files changed, 74 insertions(+), 1 deletion(-)
>>
>> diff --git a/doc/filters.texi b/doc/filters.texi
>> index 84567dec16..f4a57e993f 100644
>> --- a/doc/filters.texi
>> +++ b/doc/filters.texi
>> @@ -7285,6 +7285,12 @@ backward predicted MVs of B-frames
>>  @item qp
>>  Display quantization parameters using the chroma planes.
>>
>> +@item chroma_qp
>> +Display chroma quantization parameters (default luma qp) using the
>> chroma planes. Should use with qp option. (e.g.
>> codecview=qp=true:chroma_qp=true)
>> +
>> +@item dc_qp
>> +Display DC quantization parameters (default AC qp) using the chroma
>> planes. Should use with qp option. (e.g. codecview=qp=true:dc_qp=true)
>> +
>>  @item mv_type, mvt
>>  Set motion vectors type to visualize. Includes MVs from all frames
>> unless specified by @var{frame_type} option.
>>
>> diff --git a/libavfilter/vf_codecview.c b/libavfilter/vf_codecview.c
>> index 331bfba777..f585dfe28e 100644
>> --- a/libavfilter/vf_codecview.c
>> +++ b/libavfilter/vf_codecview.c
>> @@ -34,6 +34,7 @@
>>  #include "libavutil/opt.h"
>>  #include "avfilter.h"
>>  #include "internal.h"
>> +#include "libavutil/video_enc_params.h"
>>
>>  #define MV_P_FOR  (1<<0)
>>  #define MV_B_FOR  (1<<1)
>> @@ -51,6 +52,8 @@ typedef struct CodecViewContext {
>>  unsigned mv_type;
>>  int hsub, vsub;
>>  int qp;
>> +int chroma_qp;
>> +int dc_qp;
>>  } CodecViewContext;
>>
>>  #define OFFSET(x) offsetof(CodecViewContext, x)
>> @@ -63,6 +66,8 @@ static const AVOption codecview_options[] = {
>>  CONST("bf", "forward predicted MVs of B-frames",  MV_B_FOR,
>> "mv"),
>>  CONST("bb", "backward predicted MVs of B-frames", MV_B_BACK,
>> "mv"),
>>  { "qp", NULL, OFFSET(qp), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags =
>> FLAGS },
>> +{ "chroma_qp", NULL, OFFSET(chroma_qp), AV_OPT_TYPE_BOOL, {.i64=0},
>> 0, 1, .flags = FLAGS },
>> +{ "dc_qp", NULL, OFFSET(dc_qp), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1,
>> .flags = FLAGS },
>>  { "mv_type", "set motion vectors type", OFFSET(mv_type),
>> AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "mv_type" },
>>  { "mvt", "set motion vectors type", OFFSET(mv_type),
>> AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "mv_type" },
>>  CONST("fp", "forward predicted MVs",  MV_TYPE_FOR,  "mv_type"),
>> @@ -212,6 +217,52 @@ static void draw_arrow(uint8_t *buf, int sx, int sy,
>> int ex,
>>  draw_line(buf, sx, sy, ex, ey, w, h, stride, color);
>>  }
>>
>> +static int qp_color_calculate(int qp, enum AVVideoEncParamsType type) {
>> +return type == AV_VIDEO_ENC_PARAMS_H264 ? qp * 128 / 31 : qp;
>> +}
>> +
>> +static void get_block_color(AVVideoEncParams *par, AVVideoBlockParams
>> *b, CodecViewContext *s, enum AVColorRange color_range, int *cu, int *cv)
>> +{
>> +const int plane_qp_cu_index = s->chroma_qp ? 1 : 0;
>> +const int plane_qp_cv_index = s->chroma_qp ? 2 : 0;
>> +const int ac_dc_index = s->dc_qp ? 0 : 1;
>> +*cu = qp_color_calculate(par->qp +
>> par->delta_qp[plane_qp_cu_index][ac_dc_index] + b->delta_qp, par->type);
>> +*cv = qp_color_calculate(par->qp +
>> par->delta_qp[plane_qp_cv_index][ac_dc_index] + b->delta_qp, par->type);
>> +if (color_range == AVCOL_RANGE_MPEG) {
>> +// map jpeg color range(0-255) to mpeg color range(16-235)
>> +*cu = av_rescale(*cu, 73, 85) + 16;
>> +*cv = av_rescale(*cv, 73, 85) + 16;
>> +}
>> +}
>> +
>> +static void color_block(AVFrame *frame, CodecViewContext *s, const int
>> src_x, 

Re: [FFmpeg-devel] [PATCH] libavcodec/vp9: export block structure when segmentation isn't enable

2020-07-09 Thread Yongle Lin
On Mon, Jul 6, 2020 at 11:31 AM Yongle Lin  wrote:

> it makes sense to export block structure like src_x, src_y, width and
> height when segmentation isn't enable so we could visualize and see the
> structure of the block.
> ---
>  libavcodec/vp9.c | 8 +++-
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
> index fd0bab14a2..e700def70e 100644
> --- a/libavcodec/vp9.c
> +++ b/libavcodec/vp9.c
> @@ -1501,10 +1501,8 @@ static int vp9_export_enc_params(VP9Context *s,
> VP9Frame *frame)
>  AVVideoEncParams *par;
>  unsigned int tile, nb_blocks = 0;
>
> -if (s->s.h.segmentation.enabled) {
> -for (tile = 0; tile < s->active_tile_cols; tile++)
> -nb_blocks += s->td[tile].nb_block_structure;
> -}
> +for (tile = 0; tile < s->active_tile_cols; tile++)
> +nb_blocks += s->td[tile].nb_block_structure;
>
>  par = av_video_enc_params_create_side_data(frame->tf.f,
>  AV_VIDEO_ENC_PARAMS_VP9, nb_blocks);
> @@ -1536,7 +1534,7 @@ static int vp9_export_enc_params(VP9Context *s,
> VP9Frame *frame)
>  b->w = 1 << (3 +
> td->block_structure[block_tile].block_size_idx_x);
>  b->h = 1 << (3 +
> td->block_structure[block_tile].block_size_idx_y);
>
> -if (s->s.h.segmentation.feat[seg_id].q_enabled) {
> +if (s->s.h.segmentation.enabled &&
> s->s.h.segmentation.feat[seg_id].q_enabled) {
>  b->delta_qp = s->s.h.segmentation.feat[seg_id].q_val;
>  if (s->s.h.segmentation.absolute_vals)
>  b->delta_qp -= par->qp;
> --
> 2.27.0.383.g050319c2ae-goog
>
>
Dear FFmpeg Developers,

Currently ffmpeg doesn't export the block data for VP9 if there is no
segmentation. Because it's only used to export QP value. I think it makes
more sense to export the block information without segmentation so we could
visualize the block structure for VP9 video.

Could you please review and merge this patch? Thanks.

Best,
Yongle
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] libavfilter/vf_codecview: add block structure visualization

2020-07-09 Thread Yongle Lin
On Thu, Jul 2, 2020 at 8:09 AM Michael Niedermayer 
wrote:

> On Wed, Jul 01, 2020 at 05:42:48PM +0000, Yongle Lin wrote:
> > example command line to visualize block decomposition:
> > ./ffmpeg -export_side_data +venc_params -i input.webm -vf
> > codecview=bs=true output.webm
> > ---
>
> >  doc/filters.texi   |  3 +++
> >  libavcodec/vp9.c   |  8 +++-
> >  libavfilter/vf_codecview.c | 41 ++
>
> the vp9 and vf_codecview changes belong in seperate patches, these are 2
> seperate libs
>
> thx
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> In a rich man's house there is no place to spit but his face.
> -- Diogenes of Sinope
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Hey Michael,

I have splitted the patches and sent it to you. Do you have any other
suggestions on this patch? Thanks

Best Regards,
Yongle
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] libavfilter/vf_codecview: enable qp visualization for H264 and VP9

2020-07-13 Thread Yongle Lin
On Thu, Jul 9, 2020 at 2:18 PM Yongle Lin  wrote:

>
>
> On Mon, Jul 6, 2020 at 10:56 AM Yongle Lin 
> wrote:
>
>>
>>
>> On Thu, Jun 25, 2020 at 12:09 PM Yongle Lin 
>> wrote:
>>
>>> Add qp visualization in codecview filter which supports H264 and VP9
>>> codecs. Add options for luma/chroma qp and AC/DC qp as well. There is a old
>>> way to visualize it but it's deprecated since version 58.
>>> example command line to visualize qp:
>>> ./ffmpeg -export_side_data +venc_params -i input.mp4 -vf
>>> codecview=qp=true output.mp4
>>> ---
>>>  doc/filters.texi   |  6 
>>>  libavfilter/vf_codecview.c | 69 +-
>>>  2 files changed, 74 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/doc/filters.texi b/doc/filters.texi
>>> index 84567dec16..f4a57e993f 100644
>>> --- a/doc/filters.texi
>>> +++ b/doc/filters.texi
>>> @@ -7285,6 +7285,12 @@ backward predicted MVs of B-frames
>>>  @item qp
>>>  Display quantization parameters using the chroma planes.
>>>
>>> +@item chroma_qp
>>> +Display chroma quantization parameters (default luma qp) using the
>>> chroma planes. Should use with qp option. (e.g.
>>> codecview=qp=true:chroma_qp=true)
>>> +
>>> +@item dc_qp
>>> +Display DC quantization parameters (default AC qp) using the chroma
>>> planes. Should use with qp option. (e.g. codecview=qp=true:dc_qp=true)
>>> +
>>>  @item mv_type, mvt
>>>  Set motion vectors type to visualize. Includes MVs from all frames
>>> unless specified by @var{frame_type} option.
>>>
>>> diff --git a/libavfilter/vf_codecview.c b/libavfilter/vf_codecview.c
>>> index 331bfba777..f585dfe28e 100644
>>> --- a/libavfilter/vf_codecview.c
>>> +++ b/libavfilter/vf_codecview.c
>>> @@ -34,6 +34,7 @@
>>>  #include "libavutil/opt.h"
>>>  #include "avfilter.h"
>>>  #include "internal.h"
>>> +#include "libavutil/video_enc_params.h"
>>>
>>>  #define MV_P_FOR  (1<<0)
>>>  #define MV_B_FOR  (1<<1)
>>> @@ -51,6 +52,8 @@ typedef struct CodecViewContext {
>>>  unsigned mv_type;
>>>  int hsub, vsub;
>>>  int qp;
>>> +int chroma_qp;
>>> +int dc_qp;
>>>  } CodecViewContext;
>>>
>>>  #define OFFSET(x) offsetof(CodecViewContext, x)
>>> @@ -63,6 +66,8 @@ static const AVOption codecview_options[] = {
>>>  CONST("bf", "forward predicted MVs of B-frames",  MV_B_FOR,
>>> "mv"),
>>>  CONST("bb", "backward predicted MVs of B-frames", MV_B_BACK,
>>> "mv"),
>>>  { "qp", NULL, OFFSET(qp), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags
>>> = FLAGS },
>>> +{ "chroma_qp", NULL, OFFSET(chroma_qp), AV_OPT_TYPE_BOOL, {.i64=0},
>>> 0, 1, .flags = FLAGS },
>>> +{ "dc_qp", NULL, OFFSET(dc_qp), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1,
>>> .flags = FLAGS },
>>>  { "mv_type", "set motion vectors type", OFFSET(mv_type),
>>> AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "mv_type" },
>>>  { "mvt", "set motion vectors type", OFFSET(mv_type),
>>> AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "mv_type" },
>>>  CONST("fp", "forward predicted MVs",  MV_TYPE_FOR,  "mv_type"),
>>> @@ -212,6 +217,52 @@ static void draw_arrow(uint8_t *buf, int sx, int
>>> sy, int ex,
>>>  draw_line(buf, sx, sy, ex, ey, w, h, stride, color);
>>>  }
>>>
>>> +static int qp_color_calculate(int qp, enum AVVideoEncParamsType type) {
>>> +return type == AV_VIDEO_ENC_PARAMS_H264 ? qp * 128 / 31 : qp;
>>> +}
>>> +
>>> +static void get_block_color(AVVideoEncParams *par, AVVideoBlockParams
>>> *b, CodecViewContext *s, enum AVColorRange color_range, int *cu, int *cv)
>>> +{
>>> +const int plane_qp_cu_index = s->chroma_qp ? 1 : 0;
>>> +const int plane_qp_cv_index = s->chroma_qp ? 2 : 0;
>>> +const int ac_dc_index = s->dc_qp ? 0 : 1;
>>> +*cu = qp_color_calculate(par->qp +
>>> par->delta_qp[plane_qp_cu_index][ac_dc_index] + b->delta_qp, par->type);
>>> +*cv = qp_color_calculate(par->qp +
>>> par->delta_qp[plane_qp_

Re: [FFmpeg-devel] [PATCH] libavfilter/vf_codecview: add block structure visualization

2020-07-13 Thread Yongle Lin
On Thu, Jul 2, 2020 at 8:09 AM Michael Niedermayer 
wrote:

> On Wed, Jul 01, 2020 at 05:42:48PM +0000, Yongle Lin wrote:
> > example command line to visualize block decomposition:
> > ./ffmpeg -export_side_data +venc_params -i input.webm -vf
> > codecview=bs=true output.webm
> > ---
>
> >  doc/filters.texi   |  3 +++
> >  libavcodec/vp9.c   |  8 +++-
> >  libavfilter/vf_codecview.c | 41 ++
>
> the vp9 and vf_codecview changes belong in seperate patches, these are 2
> seperate libs
>
> thx
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>

Hey Michael,

I have splitted the patches and sent it to you. Do you have any other
suggestions on this patch? Thanks

Best Regards,
Yongle


>
> In a rich man's house there is no place to spit but his face.
> -- Diogenes of Sinope
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] libavcodec/vp9: export block structure when segmentation isn't enable

2020-07-13 Thread Yongle Lin
On Thu, Jul 9, 2020 at 2:23 PM Yongle Lin  wrote:

>
>
> On Mon, Jul 6, 2020 at 11:31 AM Yongle Lin 
> wrote:
>
>> it makes sense to export block structure like src_x, src_y, width and
>> height when segmentation isn't enable so we could visualize and see the
>> structure of the block.
>> ---
>>  libavcodec/vp9.c | 8 +++-
>>  1 file changed, 3 insertions(+), 5 deletions(-)
>>
>> diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
>> index fd0bab14a2..e700def70e 100644
>> --- a/libavcodec/vp9.c
>> +++ b/libavcodec/vp9.c
>> @@ -1501,10 +1501,8 @@ static int vp9_export_enc_params(VP9Context *s,
>> VP9Frame *frame)
>>  AVVideoEncParams *par;
>>  unsigned int tile, nb_blocks = 0;
>>
>> -if (s->s.h.segmentation.enabled) {
>> -for (tile = 0; tile < s->active_tile_cols; tile++)
>> -nb_blocks += s->td[tile].nb_block_structure;
>> -}
>> +for (tile = 0; tile < s->active_tile_cols; tile++)
>> +nb_blocks += s->td[tile].nb_block_structure;
>>
>>  par = av_video_enc_params_create_side_data(frame->tf.f,
>>  AV_VIDEO_ENC_PARAMS_VP9, nb_blocks);
>> @@ -1536,7 +1534,7 @@ static int vp9_export_enc_params(VP9Context *s,
>> VP9Frame *frame)
>>  b->w = 1 << (3 +
>> td->block_structure[block_tile].block_size_idx_x);
>>  b->h = 1 << (3 +
>> td->block_structure[block_tile].block_size_idx_y);
>>
>> -if (s->s.h.segmentation.feat[seg_id].q_enabled) {
>> +if (s->s.h.segmentation.enabled &&
>> s->s.h.segmentation.feat[seg_id].q_enabled) {
>>  b->delta_qp = s->s.h.segmentation.feat[seg_id].q_val;
>>  if (s->s.h.segmentation.absolute_vals)
>>  b->delta_qp -= par->qp;
>> --
>> 2.27.0.383.g050319c2ae-goog
>>
>>
> Dear FFmpeg Developers,
>
> Currently ffmpeg doesn't export the block data for VP9 if there is no
> segmentation. Because it's only used to export QP value. I think it makes
> more sense to export the block information without segmentation so we could
> visualize the block structure for VP9 video.
>
> Could you please review and merge this patch? Thanks.
>
> Best,
> Yongle
>

Dear FFmpeg Developers,

Currently ffmpeg doesn't export the block data for VP9 if there is no
segmentation. Because it's only used to export QP value. I think it makes
more sense to export the block information without segmentation so we could
visualize the block structure for VP9 video.

Could you please review and merge this patch? Thanks.

Best,
Yongle
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-15 Thread Yongle Lin
add block type field to AVVideoBlockParams so we could either export or 
visualize it later.
---
 libavutil/video_enc_params.h | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
index 43fa443154..8bf5f240c9 100644
--- a/libavutil/video_enc_params.h
+++ b/libavutil/video_enc_params.h
@@ -57,6 +57,11 @@ enum AVVideoEncParamsType {
 AV_VIDEO_ENC_PARAMS_H264,
 };
 
+enum AVVideoBlockFlags {
+AV_VIDEO_ENC_BLOCK_INTRA = 1ULL <<  0,  /* Indicates block uses intra 
prediction */
+AV_VIDEO_ENC_BLOCK_SKIP = 1ULL <<  1,   /* Indicates block is not coded 
(skipped) */
+};
+
 /**
  * Video encoding parameters for a given frame. This struct is allocated along
  * with an optional array of per-block AVVideoBlockParams descriptors.
@@ -126,6 +131,20 @@ typedef struct AVVideoBlockParams {
  * corresponding per-frame value.
  */
 int32_t delta_qp;
+
+/**
+ * Type flag of the block
+ * Each bit field indicates a type flag
+ */
+enum AVVideoBlockFlags flags;
+
+/**
+ * Reference frames used for prediction
+ * Each entry specifies the first/second/third/etc. reference frame the 
current frame uses.
+ * The value at each entry specifies the index inside the reference frame 
array for that current frame.
+ * Any entry that is unused will be set to -1
+ */
+int8_t ref[8];
 } AVVideoBlockParams;
 
 /*
-- 
2.27.0.383.g050319c2ae-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] libavcodec/h264dec: export block type in H.264

2020-07-15 Thread Yongle Lin
---
 libavcodec/h264dec.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 1e2ca68449..b3de5290d0 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -816,6 +816,20 @@ static int h264_export_enc_params(AVFrame *f, H264Picture 
*p)
 b->h = 16;
 
 b->delta_qp = p->qscale_table[mb_xy] - par->qp;
+
+int mb_type = p->mb_type[mb_xy];
+if (IS_PCM(mb_type))
+b->flags |= AV_VIDEO_ENC_BLOCK_INTRA;
+if (IS_SKIP(mb_type))
+b->flags |= AV_VIDEO_ENC_BLOCK_SKIP;
+if (!USES_LIST(mb_type, 1))
+b->ref[0] = p->ref_index[0];
+else if (!USES_LIST(mb_type, 0))
+b->ref[0] = p->ref_index[1];
+else {
+b->ref[0] = p->ref_index[0];
+b->ref[1] = p->ref_index[1];
+}
 }
 
 return 0;
-- 
2.27.0.389.gc38d7665816-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] libavcodec/vp9: export block type in VP9

2020-07-15 Thread Yongle Lin
---
 libavcodec/vp9.c  | 10 ++
 libavcodec/vp9block.c |  6 ++
 libavcodec/vp9dec.h   |  4 
 3 files changed, 20 insertions(+)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index fd0bab14a2..6bd6bd4fa9 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -1541,6 +1541,16 @@ static int vp9_export_enc_params(VP9Context *s, VP9Frame 
*frame)
 if (s->s.h.segmentation.absolute_vals)
 b->delta_qp -= par->qp;
 }
+
+if (td->block_structure[block_tile].skip)
+b->flags |= AV_VIDEO_ENC_BLOCK_SKIP;
+if (td->block_structure[block_tile].intra) {
+b->flags |= AV_VIDEO_ENC_BLOCK_INTRA;
+} else {
+b->ref[0] = td->block_structure[block_tile].ref[0];
+if (td->block_structure[block_tile].comp)
+b->ref[1] = td->block_structure[block_tile].ref[1];
+}
 }
 }
 }
diff --git a/libavcodec/vp9block.c b/libavcodec/vp9block.c
index ec16e26c69..3b500c8259 100644
--- a/libavcodec/vp9block.c
+++ b/libavcodec/vp9block.c
@@ -1295,6 +1295,12 @@ void ff_vp9_decode_block(VP9TileData *td, int row, int 
col,
 td->block_structure[td->nb_block_structure].col = col;
 td->block_structure[td->nb_block_structure].block_size_idx_x = 
av_log2(w4);
 td->block_structure[td->nb_block_structure].block_size_idx_y = 
av_log2(h4);
+
+td->block_structure[td->nb_block_structure].intra = b->intra;
+td->block_structure[td->nb_block_structure].skip = b->skip;
+td->block_structure[td->nb_block_structure].comp = b->comp;
+td->block_structure[td->nb_block_structure].ref[0] = b->ref[0];
+td->block_structure[td->nb_block_structure].ref[1] = b->ref[1];
 td->nb_block_structure++;
 }
 
diff --git a/libavcodec/vp9dec.h b/libavcodec/vp9dec.h
index cc2440b854..6ecb544274 100644
--- a/libavcodec/vp9dec.h
+++ b/libavcodec/vp9dec.h
@@ -231,6 +231,10 @@ struct VP9TileData {
 unsigned int col:13;
 unsigned int block_size_idx_x:2;
 unsigned int block_size_idx_y:2;
+unsigned int intra:1;
+unsigned int skip:1;
+unsigned int comp:1;
+uint8_t ref[2];
 } *block_structure;
 unsigned int nb_block_structure;
 };
-- 
2.27.0.389.gc38d7665816-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] libavcodec/h264dec: export block type in H.264

2020-07-16 Thread Yongle Lin
On Wed, Jul 15, 2020 at 4:37 PM Mark Thompson  wrote:

> On 15/07/2020 22:05, Yongle Lin wrote:
> > ---
> >   libavcodec/h264dec.c | 14 ++
> >   1 file changed, 14 insertions(+)
> >
> > diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
> > index 1e2ca68449..b3de5290d0 100644
> > --- a/libavcodec/h264dec.c
> > +++ b/libavcodec/h264dec.c
> > @@ -816,6 +816,20 @@ static int h264_export_enc_params(AVFrame *f,
> H264Picture *p)
> >   b->h = 16;
> >
> >   b->delta_qp = p->qscale_table[mb_xy] - par->qp;
> > +
> > +int mb_type = p->mb_type[mb_xy];
> > +if (IS_PCM(mb_type))
> > +b->flags |= AV_VIDEO_ENC_BLOCK_INTRA;
>
> Can you explain your definition of what makes a block "intra"?  If you
> really do mean to only include PCM blocks then maybe it should have a
> different name, because that isn't what I would expect.
>

I think intra is the block that uses no reference frame to predict? The
purpose of exporting this data is to enable visualization of block type
which has been deprecated since version 58. And previously it only
supported MPEG video and I want to make it more general to other codecs as
well.
Probably I should include  IS_PCM, IS_INTRA
&& IS_ACPRED(mb_type), IS_INTRA16x16, IS_INTRA4x4 as "intra" type for H.264?


> > +if (IS_SKIP(mb_type))
> > +b->flags |= AV_VIDEO_ENC_BLOCK_SKIP; > +if
> (!USES_LIST(mb_type, 1))
> > +b->ref[0] = p->ref_index[0];
> > +else if (!USES_LIST(mb_type, 0))
> > +b->ref[0] = p->ref_index[1];
> > +else {
> > +b->ref[0] = p->ref_index[0];
> > +b->ref[1] = p->ref_index[1];
>
> I don't think ref_index is anything to do with what you think it is.
>
> Also note that code of this form must be insufficient due to the lack
> dependence on both the slice and the block.  (Slice headers define the two
> reference picture lists, and blocks within a slice
> choose pictures from those lists.)
>

I am not good at H.264. I read the source code and because there isn't too
much comments I thought ref_index is the thing I want. I will try to
correct it to be the index of the L0, L1 picture.


> > +}
> >   }
> >
> >   return 0;
> >
>
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Best,
Yongle
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-17 Thread Yongle Lin
On Wed, Jul 15, 2020 at 4:13 PM Mark Thompson  wrote:

> On 15/07/2020 18:43, Yongle Lin wrote:
> > add block type field to AVVideoBlockParams so we could either export or
> visualize it later.
> > ---
> >   libavutil/video_enc_params.h | 19 +++
> >   1 file changed, 19 insertions(+)
> >
> > diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
> > index 43fa443154..8bf5f240c9 100644
> > --- a/libavutil/video_enc_params.h
> > +++ b/libavutil/video_enc_params.h
> > @@ -57,6 +57,11 @@ enum AVVideoEncParamsType {
> >   AV_VIDEO_ENC_PARAMS_H264,
> >   };
> >
> > +enum AVVideoBlockFlags {
> > +AV_VIDEO_ENC_BLOCK_INTRA = 1ULL <<  0,  /* Indicates block uses
> intra prediction */
>
> The ULL is only confusing matters here - standard-conforming enum values
> have type int.  Some compilers allow it to be a larger integer type, but I
> don't think we can rely on that extension.
>

I am thinking of defining a bit field struct to for type flags like what we
did in other places:
struct AVVideoBlockFlags {
unsigned int intra:1;
unsigned int skip:1;
}

Or we could use the same way of mb_type defined in H.264 like
#define AV_VIDEO_ENC_BLOCK_INTRA 1ULL << 0
#define AV_VIDEO_ENC_BLOCK_SKIP 1ULL << 1

uint64_t b_type


> > +AV_VIDEO_ENC_BLOCK_SKIP = 1ULL <<  1,   /* Indicates block is not
> coded (skipped) */
>
> Can you define more precisely what you mean by "not coded"?  Is that just
> that it has no residuals, or does it also indicate no motion vector, or no
> coded motion vector relative to prediction?
>

 I want to make it more general which can be applied to more codec. So in
VP9, there is a skip flag to indicate if the block has residual
coefficients. As for H.264 you mentioned there are P_Skip and B_Skip, I
think both of them should be considered as skip.

>
> > +};
> > +
> >   /**
> >* Video encoding parameters for a given frame. This struct is
> allocated along
> >* with an optional array of per-block AVVideoBlockParams descriptors.
> > @@ -126,6 +131,20 @@ typedef struct AVVideoBlockParams {
> >* corresponding per-frame value.
> >*/
> >   int32_t delta_qp;
> > +
> > +/**
> > + * Type flag of the block
> > + * Each bit field indicates a type flag
> > + */
> > +enum AVVideoBlockFlags flags;
>
> Don't make this an enum, since you aren't using it as an enum - you're
> going to assign combinations of flags.  (Also, the size of the field may
> change as more flags are added.)
>
> > +
> > +/**
> > + * Reference frames used for prediction
> > + * Each entry specifies the first/second/third/etc. reference frame
> the current frame uses.
> > + * The value at each entry specifies the index inside the reference
> frame array for that current frame.
>
> You'll need to define more carefully what "the reference frame array"
> means.  I can guess that it's the ref_frame_idx[] number for VP9, but it's
> not at all obvious what it would mean for H.264.
>

Previously I planned to store if the block uses previous or future ref
frames for this field. I don't fully understand how H,264 stores the
reference frame. Perhaps we could change the definition of ref so that it
can be applied to both vp9 and h264.


> > + * Any entry that is unused will be set to -1
> > + */
> > +int8_t ref[8];
> >   } AVVideoBlockParams;
> >
> >   /*
> >
>
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Best,
Yongle
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] fftools/ffprobe: export venc params side data

2020-08-13 Thread Yongle Lin
Printing venc params in ffprobe makes it easier for program to parse the data 
via
ffprobe json output
---
 fftools/ffprobe.c | 33 +
 1 file changed, 33 insertions(+)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 5515e1b31b..b20bddc897 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -47,6 +47,7 @@
 #include "libavutil/parseutils.h"
 #include "libavutil/timecode.h"
 #include "libavutil/timestamp.h"
+#include "libavutil/video_enc_params.h"
 #include "libavdevice/avdevice.h"
 #include "libswscale/swscale.h"
 #include "libswresample/swresample.h"
@@ -166,6 +167,8 @@ typedef enum {
 SECTION_ID_FRAME_TAGS,
 SECTION_ID_FRAME_SIDE_DATA_LIST,
 SECTION_ID_FRAME_SIDE_DATA,
+SECTION_ID_FRAME_VENC_PARAMS_BLOCK_DATA_LIST,
+SECTION_ID_FRAME_VENC_PARAMS_BLOCK_DATA,
 SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST,
 SECTION_ID_FRAME_SIDE_DATA_TIMECODE,
 SECTION_ID_FRAME_LOG,
@@ -213,6 +216,8 @@ static struct section sections[] = {
 [SECTION_ID_FRAME_TAGS] = { SECTION_ID_FRAME_TAGS, "tags", 
SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = 
"frame_tags" },
 [SECTION_ID_FRAME_SIDE_DATA_LIST] ={ SECTION_ID_FRAME_SIDE_DATA_LIST, 
"side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA, -1 }, 
.element_name = "side_data", .unique_name = "frame_side_data_list" },
 [SECTION_ID_FRAME_SIDE_DATA] = { SECTION_ID_FRAME_SIDE_DATA, 
"side_data", 0, { SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST, -1 } },
+[SECTION_ID_FRAME_VENC_PARAMS_BLOCK_DATA_LIST] ={ 
SECTION_ID_FRAME_VENC_PARAMS_BLOCK_DATA_LIST, "block_data_list", 
SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_VENC_PARAMS_BLOCK_DATA, -1 }, 
.element_name = "block_data", .unique_name = "frame_block_data_list"},
+[SECTION_ID_FRAME_VENC_PARAMS_BLOCK_DATA] = { 
SECTION_ID_FRAME_VENC_PARAMS_BLOCK_DATA, "block_data", 0, { -1 }, 
.show_all_entries = 1 },
 [SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST] = { 
SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST, "timecodes", SECTION_FLAG_IS_ARRAY, { 
SECTION_ID_FRAME_SIDE_DATA_TIMECODE, -1 } },
 [SECTION_ID_FRAME_SIDE_DATA_TIMECODE] = { 
SECTION_ID_FRAME_SIDE_DATA_TIMECODE, "timecode", 0, { -1 } },
 [SECTION_ID_FRAME_LOGS] = { SECTION_ID_FRAME_LOGS, "logs", 
SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_LOG, -1 } },
@@ -2259,6 +2264,34 @@ static void show_frame(WriterContext *w, AVFrame *frame, 
AVStream *stream,
 if (tag)
 print_str(tag->key, tag->value);
 print_int("size", sd->size);
+} else if (sd->type == AV_FRAME_DATA_VIDEO_ENC_PARAMS) {
+AVVideoEncParams *par = (AVVideoEncParams *) sd->data;
+print_int("type", par->type);
+print_int("qp", par->qp);
+for (int plane = 0; plane < FF_ARRAY_ELEMS(par->delta_qp); 
plane++)
+for (int acdc = 0; acdc < 
FF_ARRAY_ELEMS(par->delta_qp[plane]); acdc++) {
+int delta_qp = par->delta_qp[plane][acdc];
+if (delta_qp) {
+char buf[16];
+snprintf(buf, sizeof(buf), "delta_qp[%d][%d]", 
plane, acdc);
+print_int(buf, delta_qp);
+}
+}
+if (par->nb_blocks) {
+print_int("nb_blocks", par->nb_blocks);
+writer_print_section_header(w, 
SECTION_ID_FRAME_VENC_PARAMS_BLOCK_DATA_LIST);
+for (int i = 0; i < par->nb_blocks; i++) {
+AVVideoBlockParams *b = av_video_enc_params_block(par, 
i);
+writer_print_section_header(w, 
SECTION_ID_FRAME_VENC_PARAMS_BLOCK_DATA);
+print_int("src_x", b->src_x);
+print_int("src_y", b->src_y);
+print_int("width", b->w);
+print_int("height", b->h);
+print_int("delta_qp", b->delta_qp);
+writer_print_section_footer(w);
+}
+writer_print_section_footer(w);
+}
 }
 writer_print_section_footer(w);
 }
-- 
2.28.0.220.ged08abb693-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] libavcodec/vp9: export motion vector to side data in vp9

2020-08-13 Thread Yongle Lin
---
 libavcodec/vp9.c  | 102 ++
 libavcodec/vp9block.c |   2 +
 libavcodec/vp9dec.h   |   3 ++
 3 files changed, 107 insertions(+)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index fd0bab14a2..5289fb3099 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -35,6 +35,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/video_enc_params.h"
+#include "libavutil/motion_vector.h"
 
 #define VP9_SYNCCODE 0x498342
 
@@ -99,6 +100,7 @@ static void vp9_tile_data_free(VP9TileData *td)
 av_freep(&td->b_base);
 av_freep(&td->block_base);
 av_freep(&td->block_structure);
+av_freep(&td->block_motion_vectors);
 }
 
 static void vp9_frame_unref(AVCodecContext *avctx, VP9Frame *f)
@@ -334,6 +336,11 @@ static int update_block_buffers(AVCodecContext *avctx)
 if (!td->block_structure)
 return AVERROR(ENOMEM);
 }
+if (avctx->export_side_data & AV_CODEC_EXPORT_DATA_MVS) {
+td->block_motion_vectors = av_malloc_array(s->cols * s->rows, 
sizeof(*td->block_motion_vectors));
+if (!td->block_motion_vectors)
+return AVERROR(ENOMEM);
+}
 } else {
 for (i = 1; i < s->active_tile_cols; i++)
 vp9_tile_data_free(&s->td[i]);
@@ -355,6 +362,11 @@ static int update_block_buffers(AVCodecContext *avctx)
 if (!s->td[i].block_structure)
 return AVERROR(ENOMEM);
 }
+if (avctx->export_side_data & AV_CODEC_EXPORT_DATA_MVS) {
+td->block_motion_vectors = av_malloc_array(s->cols * s->rows, 
sizeof(*td->block_motion_vectors));
+if (!td->block_motion_vectors)
+return AVERROR(ENOMEM);
+}
 }
 }
 s->block_alloc_using_2pass = s->s.frames[CUR_FRAME].uses_2pass;
@@ -1548,6 +1560,92 @@ static int vp9_export_enc_params(VP9Context *s, VP9Frame 
*frame)
 return 0;
 }
 
+static int add_mv(AVMotionVector *mb, int w, int h,
+  int dst_x, int dst_y,
+  int motion_x, int motion_y, int motion_scale,
+  int direction)
+{
+mb->w = w;
+mb->h = h;
+mb->motion_x = motion_x;
+mb->motion_y = motion_y;
+mb->motion_scale = motion_scale;
+mb->dst_x = dst_x;
+mb->dst_y = dst_y;
+mb->src_x = dst_x + motion_x / motion_scale;
+mb->src_y = dst_y + motion_y / motion_scale;
+mb->source = direction ? 1 : -1;
+mb->flags = 0; // XXX: does mb_type contain extra information that could 
be exported here?
+return 1;
+}
+
+static int vp9_export_mv(AVCodecContext *avctx, AVFrame *frame)
+{
+VP9Context *s = avctx->priv_data;
+AVMotionVector *mvs = av_malloc_array(frame->width * frame->height, 2 * 4 
* sizeof(AVMotionVector));
+if (!mvs)
+return AVERROR(ENOMEM);
+
+unsigned int tile, nb_blocks = 0;
+for (tile = 0; tile < s->active_tile_cols; tile++) {
+nb_blocks += s->td[tile].nb_block_structure;
+}
+
+if (nb_blocks) {
+unsigned int block = 0;
+unsigned int tile, block_tile;
+
+for (tile = 0; tile < s->active_tile_cols; tile++) {
+VP9TileData *td = &s->td[tile];
+
+for (block_tile = 0; block_tile < td->nb_block_structure; 
block_tile++) {
+unsigned int row = td->block_structure[block_tile].row;
+unsigned int col = td->block_structure[block_tile].col;
+int w = 1 << (3 + 
td->block_structure[block_tile].block_size_idx_x);
+int h = 1 << (3 + 
td->block_structure[block_tile].block_size_idx_y);
+int src_x = col * 8;
+int src_y = row * 8;
+int motion_x, motion_y, dst_x, dst_y;
+if (w >= 8 && h >= 8) {
+for (int ref = 0; ref < 2; ref++) {
+motion_x = 
td->block_motion_vectors[block_tile].mv[0][ref].x;
+motion_y = 
td->block_motion_vectors[block_tile].mv[0][ref].y;
+dst_x = src_x + w / 2;
+dst_y = src_y + w / 2;
+add_mv(mvs + block, w, h, dst_x, dst_y, motion_x, 
motion_y, 16, ref);
+block++;
+}
+} else {
+for (int b_idx = 0; b_idx < 4; b_idx++) {
+for (int ref = 0; ref < 2; ref++) {
+motion_x = 
td->block_motion_vectors[block_tile].mv[b_idx][ref].x;
+motion_y = 
td->block_motion_vectors[block_tile].mv[b_idx][ref].y;
+dst_x = src_x + (b_idx % 2 + 1) * w / 4;
+dst_y = src_y + (b_idx / 2 + 1) * w / 4;
+add_mv(mvs + block, w, h, dst_x, dst_y, motion_x, 
motion_y, 16, ref);
+block++;
+}
+}
+ 

Re: [FFmpeg-devel] [PATCH] libavcodec/vp9: export block structure when segmentation isn't enable

2020-08-26 Thread Yongle Lin
On Mon, Jul 13, 2020 at 2:57 PM Yongle Lin  wrote:

>
> On Thu, Jul 9, 2020 at 2:23 PM Yongle Lin  wrote:
>
>>
>>
>> On Mon, Jul 6, 2020 at 11:31 AM Yongle Lin 
>> wrote:
>>
>>> it makes sense to export block structure like src_x, src_y, width and
>>> height when segmentation isn't enable so we could visualize and see the
>>> structure of the block.
>>> ---
>>>  libavcodec/vp9.c | 8 +++-
>>>  1 file changed, 3 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
>>> index fd0bab14a2..e700def70e 100644
>>> --- a/libavcodec/vp9.c
>>> +++ b/libavcodec/vp9.c
>>> @@ -1501,10 +1501,8 @@ static int vp9_export_enc_params(VP9Context *s,
>>> VP9Frame *frame)
>>>  AVVideoEncParams *par;
>>>  unsigned int tile, nb_blocks = 0;
>>>
>>> -if (s->s.h.segmentation.enabled) {
>>> -for (tile = 0; tile < s->active_tile_cols; tile++)
>>> -nb_blocks += s->td[tile].nb_block_structure;
>>> -}
>>> +for (tile = 0; tile < s->active_tile_cols; tile++)
>>> +nb_blocks += s->td[tile].nb_block_structure;
>>>
>>>  par = av_video_enc_params_create_side_data(frame->tf.f,
>>>  AV_VIDEO_ENC_PARAMS_VP9, nb_blocks);
>>> @@ -1536,7 +1534,7 @@ static int vp9_export_enc_params(VP9Context *s,
>>> VP9Frame *frame)
>>>  b->w = 1 << (3 +
>>> td->block_structure[block_tile].block_size_idx_x);
>>>  b->h = 1 << (3 +
>>> td->block_structure[block_tile].block_size_idx_y);
>>>
>>> -if (s->s.h.segmentation.feat[seg_id].q_enabled) {
>>> +if (s->s.h.segmentation.enabled &&
>>> s->s.h.segmentation.feat[seg_id].q_enabled) {
>>>  b->delta_qp =
>>> s->s.h.segmentation.feat[seg_id].q_val;
>>>  if (s->s.h.segmentation.absolute_vals)
>>>  b->delta_qp -= par->qp;
>>> --
>>> 2.27.0.383.g050319c2ae-goog
>>>
>>>
>> Dear FFmpeg Developers,
>>
>> Currently ffmpeg doesn't export the block data for VP9 if there is no
>> segmentation. Because it's only used to export QP value. I think it makes
>> more sense to export the block information without segmentation so we could
>> visualize the block structure for VP9 video.
>>
>> Could you please review and merge this patch? Thanks.
>>
>> Best,
>> Yongle
>>
>
> Dear FFmpeg Developers,
>
> Currently ffmpeg doesn't export the block data for VP9 if there is no
> segmentation. Because it's only used to export QP value. I think it makes
> more sense to export the block information without segmentation so we could
> visualize the block structure for VP9 video.
>
> Could you please review and merge this patch? Thanks.
>
> Best,
> Yongle
>

Hi FFmpeg Developers,

I noticed that this patch hasn't been reviewed yet.  Could someone help me
review it and merge this patch? Thanks.

Best,
Yongle
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".