Re: [FFmpeg-devel] [PATCH] avcodec/libaomdec: fix pix_fmt w/AVCOL_SPC_RGB

2022-10-25 Thread James Zern
On Tue, Oct 25, 2022 at 11:28 AM James Zern  wrote:
>
> Signed-off-by: James Zern 
> ---
>  libavcodec/libaomdec.c | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>

I was reminded that there was an earlier patch [1], which I had an
open comment on. I think it's better to be consistent with the
libdav1d wrapper and ffvp9/libvpx for now.

[1] 
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210606051612.89211-1-val.zapod...@gmail.com/
___
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 v3] lavc/hevc_ps: fix process failed when SPS before VPS in hvcC

2022-10-25 Thread 1035567130
From: Wang Yaqiang 

In some videos, SPS will be stored before VPS in hvcC box,
parse SPS does not depend on VPS, so the video is expected to be processed 
normally.
Added "parsed_vps" parameter to indicate whether VPS have been parsed.
Only VPS have been parsed can be verified during SPS parsing.

Signed-off-by: Wang Yaqiang 
---
 libavcodec/hevc_parser.c | 8 
 libavcodec/hevc_ps.c | 3 +--
 libavcodec/hevcdec.c | 9 -
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c
index 59f9a0ff3e..be4aa55e51 100644
--- a/libavcodec/hevc_parser.c
+++ b/libavcodec/hevc_parser.c
@@ -85,8 +85,16 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, 
H2645NAL *nal,
 }
 if (ps->sps != (HEVCSPS*)ps->sps_list[ps->pps->sps_id]->data) {
 ps->sps = (HEVCSPS*)ps->sps_list[ps->pps->sps_id]->data;
+if (ps->sps->vps_id >= HEVC_MAX_VPS_COUNT || 
!ps->vps_list[ps->sps->vps_id]) {
+av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", 
ps->sps->vps_id);
+return AVERROR_INVALIDDATA;
+}
 ps->vps = (HEVCVPS*)ps->vps_list[ps->sps->vps_id]->data;
 }
+if (!ps->vps) {
+av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n", 
ps->sps->vps_id);
+return AVERROR_INVALIDDATA;
+}
 ow  = >sps->output_window;
 
 s->coded_width  = ps->sps->width;
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index f665d8053c..9abee8bd90 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -916,9 +916,8 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, 
unsigned int *sps_id,
 sps->vps_id = get_bits(gb, 4);
 
 if (vps_list && !vps_list[sps->vps_id]) {
-av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n",
+av_log(avctx, AV_LOG_WARNING, "VPS %d does not exist\n",
sps->vps_id);
-return AVERROR_INVALIDDATA;
 }
 
 sps->max_sub_layers = get_bits(gb, 3) + 1;
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index fb44d8d3f2..03942a150d 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -327,6 +327,10 @@ static void export_stream_params(HEVCContext *s, const 
HEVCSPS *sps)
 {
 AVCodecContext *avctx = s->avctx;
 const HEVCParamSets *ps = >ps;
+if (!s->ps.vps_list[sps->vps_id]) {
+av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", sps->vps_id);
+return;
+}
 const HEVCVPS *vps = (const HEVCVPS*)ps->vps_list[sps->vps_id]->data;
 const HEVCWindow *ow = >output_window;
 unsigned int num = 0, den = 0;
@@ -520,7 +524,10 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps,
 ret = pic_arrays_init(s, sps);
 if (ret < 0)
 goto fail;
-
+if (!s->ps.vps_list[sps->vps_id]) {
+ret = AVERROR_INVALIDDATA;
+goto fail;
+}
 export_stream_params(s, sps);
 
 s->avctx->pix_fmt = pix_fmt;
-- 
2.33.0

___
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 7/7] avcodec/mpegvideo: Remove incorrect comment

2022-10-25 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 99b2d8f6de..9a58d68524 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -786,7 +786,6 @@ void ff_mpv_free_context_frame(MpegEncContext *s)
 s->linesize = s->uvlinesize = 0;
 }
 
-/* init common structure for both encoder and decoder */
 void ff_mpv_common_end(MpegEncContext *s)
 {
 ff_mpv_free_context_frame(s);
-- 
2.34.1

___
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 6/7] avcodec/mpegvideo: Remove always-false check

2022-10-25 Thread Andreas Rheinhardt
This basically reverts cc0380222add8df8ff9b3bd95eaf2b9d8c4c0d11.
At the time of said commit, cleanup on init failure was very
buggy. For codecs with the INIT_CLEANUP cap, the close function
could be called on error even before the private data has been
allocated; and when using frame threading the same could also
happen even without said flag. Some mpegvideo decoders were
affected by the latter.

Yet both of these issues have been fixed long ago, the latter
in commit e9b66175793e5c2af19beefe8e143f6e4901b5df. Therefore
the workaround in ff_mpv_common_end() can be removed.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index a04d519ccc..99b2d8f6de 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -789,9 +789,6 @@ void ff_mpv_free_context_frame(MpegEncContext *s)
 /* init common structure for both encoder and decoder */
 void ff_mpv_common_end(MpegEncContext *s)
 {
-if (!s)
-return;
-
 ff_mpv_free_context_frame(s);
 if (s->slice_context_count > 1)
 s->slice_context_count = 1;
-- 
2.34.1

___
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 5/7] avcodec/msmpeg4dec: Move setting decode_mb for WMV2 to wmv2dec.c

2022-10-25 Thread Andreas Rheinhardt
It avoids checks and allows to make ff_wmv2_decode_mb() static;
furthermore, it allows to avoid a config_components.h inclusion.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/msmpeg4dec.c | 6 +-
 libavcodec/wmv2dec.c| 4 +++-
 libavcodec/wmv2dec.h| 1 -
 3 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index 8e12e1aab2..bc554ed2eb 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -22,8 +22,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "config_components.h"
-
 #include "libavutil/thread.h"
 
 #include "avcodec.h"
@@ -38,7 +36,6 @@
 #include "h263dec.h"
 #include "mpeg4videodec.h"
 #include "msmpeg4data.h"
-#include "wmv2dec.h"
 
 #define DC_VLC_BITS 9
 #define V2_INTRA_CBPC_VLC_BITS 3
@@ -391,8 +388,7 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
 s->decode_mb= msmpeg4v34_decode_mb;
 break;
 case 5:
-if (CONFIG_WMV2_DECODER)
-s->decode_mb= ff_wmv2_decode_mb;
+break;
 case 6:
 //FIXME + TODO VC1 decode mb
 break;
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index a70913134c..2daf6c70e8 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -445,7 +445,7 @@ static inline int wmv2_decode_inter_block(WMV2DecContext 
*w, int16_t *block,
 }
 }
 
-int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
+static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
 {
 /* The following is only allowed because this encoder
  * does not use slice threading. */
@@ -573,6 +573,8 @@ static av_cold int wmv2_decode_init(AVCodecContext *avctx)
 if ((ret = ff_msmpeg4_decode_init(avctx)) < 0)
 return ret;
 
+s->decode_mb = wmv2_decode_mb;
+
 ff_wmv2_common_init(s);
 
 return ff_intrax8_common_init(avctx, >x8,
diff --git a/libavcodec/wmv2dec.h b/libavcodec/wmv2dec.h
index cc410afe17..bc8745bf6f 100644
--- a/libavcodec/wmv2dec.h
+++ b/libavcodec/wmv2dec.h
@@ -23,7 +23,6 @@
 
 #include "mpegvideo.h"
 
-int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]);
 int ff_wmv2_decode_picture_header(MpegEncContext * s);
 int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s);
 void ff_wmv2_add_mb(MpegEncContext *s, int16_t block[6][64],
-- 
2.34.1

___
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 4/7] avcodec/mpegvideo: Allocate map and score_map buffers jointly

2022-10-25 Thread Andreas Rheinhardt
Reduces the amounts of allocs, frees and allocation checks.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.c | 7 ---
 libavcodec/snow.c  | 1 -
 libavcodec/snowenc.c   | 6 +++---
 libavcodec/svq1enc.c   | 8 +++-
 4 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 0cd7c86ff6..a04d519ccc 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -373,9 +373,10 @@ static int init_duplicate_context(MpegEncContext *s)
 yc_size += 2*s->b8_stride + 2*s->mb_stride;
 
 if (s->encoding) {
-if (!FF_ALLOCZ_TYPED_ARRAY(s->me.map,   ME_MAP_SIZE) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->me.score_map, ME_MAP_SIZE))
+s->me.map = av_mallocz(2 * ME_MAP_SIZE * sizeof(*s->me.map));
+if (!s->me.map)
 return AVERROR(ENOMEM);
+s->me.score_map = s->me.map + ME_MAP_SIZE;
 
 if (s->noise_reduction) {
 if (!FF_ALLOCZ_TYPED_ARRAY(s->dct_error_sum,  2))
@@ -445,7 +446,7 @@ static void free_duplicate_context(MpegEncContext *s)
 
 av_freep(>dct_error_sum);
 av_freep(>me.map);
-av_freep(>me.score_map);
+s->me.score_map = NULL;
 av_freep(>blocks);
 av_freep(>ac_val_base);
 s->block = NULL;
diff --git a/libavcodec/snow.c b/libavcodec/snow.c
index cde09902c3..b6c8d5e256 100644
--- a/libavcodec/snow.c
+++ b/libavcodec/snow.c
@@ -635,7 +635,6 @@ av_cold void ff_snow_common_end(SnowContext *s)
 s->m.me.temp= NULL;
 av_freep(>m.me.scratchpad);
 av_freep(>m.me.map);
-av_freep(>m.me.score_map);
 av_freep(>m.sc.obmc_scratchpad);
 
 av_freep(>block);
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index ada24f7895..7fad95b69a 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -82,11 +82,11 @@ static av_cold int encode_init(AVCodecContext *avctx)
 
 s->m.me.temp  =
 s->m.me.scratchpad = av_calloc(avctx->width + 64, 2*16*2*sizeof(uint8_t));
-s->m.me.map   = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t));
-s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t));
 s->m.sc.obmc_scratchpad= av_mallocz(MB_SIZE*MB_SIZE*12*sizeof(uint32_t));
-if (!s->m.me.scratchpad || !s->m.me.map || !s->m.me.score_map || 
!s->m.sc.obmc_scratchpad)
+s->m.me.map   = av_mallocz(2 * ME_MAP_SIZE * sizeof(*s->m.me.map));
+if (!s->m.me.scratchpad || !s->m.me.map || !s->m.sc.obmc_scratchpad)
 return AVERROR(ENOMEM);
+s->m.me.score_map = s->m.me.map + ME_MAP_SIZE;
 
 ff_h263_encode_init(>m); //mv_penalty
 
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 7c9430a137..92f91aeebd 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -552,7 +552,6 @@ static av_cold int svq1_encode_end(AVCodecContext *avctx)
 
 av_freep(>m.me.scratchpad);
 av_freep(>m.me.map);
-av_freep(>m.me.score_map);
 av_freep(>mb_type);
 av_freep(>dummy);
 av_freep(>scratchbuf);
@@ -608,18 +607,17 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
 s->m.me.temp   =
 s->m.me.scratchpad = av_mallocz((avctx->width + 64) *
 2 * 16 * 2 * sizeof(uint8_t));
-s->m.me.map= av_mallocz(ME_MAP_SIZE * sizeof(uint32_t));
-s->m.me.score_map  = av_mallocz(ME_MAP_SIZE * sizeof(uint32_t));
 s->mb_type = av_mallocz((s->y_block_width + 1) *
 s->y_block_height * sizeof(int16_t));
 s->dummy   = av_mallocz((s->y_block_width + 1) *
 s->y_block_height * sizeof(int32_t));
+s->m.me.map= av_mallocz(2 * ME_MAP_SIZE * 
sizeof(*s->m.me.map));
 s->svq1encdsp.ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
 
 if (!s->m.me.temp || !s->m.me.scratchpad || !s->m.me.map ||
-!s->m.me.score_map || !s->mb_type || !s->dummy) {
+!s->mb_type || !s->dummy)
 return AVERROR(ENOMEM);
-}
+s->m.me.score_map = s->m.me.map + ME_MAP_SIZE;
 
 #if ARCH_PPC
 ff_svq1enc_init_ppc(>svq1encdsp);
-- 
2.34.1

___
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 3/7] avcodec/mpegvideo: Don't overallocate buffer

2022-10-25 Thread Andreas Rheinhardt
Only encoders need two sets of int16_t [12][64]
(one to save the current best state and one for the current
working state); decoders need only one. This saves 1.5KiB
per slice context for a decoder.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 697438fa6f..0cd7c86ff6 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -382,7 +382,7 @@ static int init_duplicate_context(MpegEncContext *s)
 return AVERROR(ENOMEM);
 }
 }
-if (!FF_ALLOCZ_TYPED_ARRAY(s->blocks,  2))
+if (!FF_ALLOCZ_TYPED_ARRAY(s->blocks,  1 + s->encoding))
 return AVERROR(ENOMEM);
 s->block = s->blocks[0];
 
-- 
2.34.1

___
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/matroska: Support HDR10+ metadata in Matroska.

2022-10-25 Thread Andreas Rheinhardt
Mohammad Izadi:
> The fate test file can be found here: 
> https://drive.google.com/file/d/1jGW3f94rglLfr5WGmMQe3SEnp1YkbMRy/view?usp=drivesdk
> The video file needs to be copied to fate-suite/mkv/

This does not describe the patch at all and should therefore not be part
of the commit message.

> ---

Instead put it here.

>  libavcodec/dynamic_hdr10_plus.c | 269 +---

The changes to libavcodec and Matroska need to be in separate patches.

>  libavcodec/dynamic_hdr10_plus.h |  26 +-

This is a private header and therefore must not be used for public symbols.

>  libavformat/matroska.h  |   5 +
>  libavformat/matroskadec.c   |  30 ++-
>  libavformat/matroskaenc.c   |  44 +++-
>  tests/fate/matroska.mak |   6 +
>  tests/ref/fate/matroska-hdr10-plus-metadata |  74 ++
>  7 files changed, 397 insertions(+), 57 deletions(-)
>  create mode 100644 tests/ref/fate/matroska-hdr10-plus-metadata
> 
> diff --git a/libavcodec/dynamic_hdr10_plus.c b/libavcodec/dynamic_hdr10_plus.c
> index 34a44aac65..d05f211c94 100644
> --- a/libavcodec/dynamic_hdr10_plus.c
> +++ b/libavcodec/dynamic_hdr10_plus.c
> @@ -18,6 +18,12 @@
>  
>  #include "dynamic_hdr10_plus.h"
>  #include "get_bits.h"
> +#include "put_bits.h"
> +
> +static const uint8_t usa_country_code = 0xB5;
> +static const uint16_t smpte_provider_code = 0x003C;
> +static const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
> +static const uint16_t smpte2094_40_application_identifier = 0x04;
>  

We typically use defines or enums for such things; C does not have
constexpr.

>  static const int64_t luminance_den = 1;
>  static const int32_t peak_luminance_den = 15;
> @@ -27,8 +33,8 @@ static const int32_t knee_point_den = 4095;
>  static const int32_t bezier_anchor_den = 1023;
>  static const int32_t saturation_weight_den = 8;
>  
> -int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const 
> uint8_t *data,
> - int size)
> +int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus* s, const 
> uint8_t* data,
> +  int size)
>  {
>  GetBitContext gbc, *gb = 
>  int ret;
> @@ -40,10 +46,12 @@ int 
> ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
>  if (ret < 0)
>  return ret;
>  
> -if (get_bits_left(gb) < 10)
> +if (get_bits_left(gb) < 8)
>  return AVERROR_INVALIDDATA;
> + s->application_version = get_bits(gb, 8);
>  
> -s->application_version = get_bits(gb, 8);
> +if (get_bits_left(gb) < 2)
> +return AVERROR_INVALIDDATA;

These changes add an unnecessary branch.

>  s->num_windows = get_bits(gb, 2);
>  
>  if (s->num_windows < 1 || s->num_windows > 3) {
> @@ -56,15 +64,11 @@ int 
> ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
>  for (int w = 1; w < s->num_windows; w++) {
>  // The corners are set to absolute coordinates here. They should be
>  // converted to the relative coordinates (in [0, 1]) in the decoder.

All the following changes to this functions are cosmetic and should be
removed. Mixing cosmetic and non-cosmetic changes make patches harder to
review.

> -AVHDRPlusColorTransformParams *params = >params[w];
> -params->window_upper_left_corner_x =
> -(AVRational){get_bits(gb, 16), 1};
> -params->window_upper_left_corner_y =
> -(AVRational){get_bits(gb, 16), 1};
> -params->window_lower_right_corner_x =
> -(AVRational){get_bits(gb, 16), 1};
> -params->window_lower_right_corner_y =
> -(AVRational){get_bits(gb, 16), 1};
> +AVHDRPlusColorTransformParams* params = >params[w];
> +params->window_upper_left_corner_x = (AVRational) { get_bits(gb, 
> 16), 1 };
> +params->window_upper_left_corner_y = (AVRational) { get_bits(gb, 
> 16), 1 };
> +params->window_lower_right_corner_x = (AVRational) { get_bits(gb, 
> 16), 1 };
> +params->window_lower_right_corner_y = (AVRational) { get_bits(gb, 
> 16), 1 };
>  
>  params->center_of_ellipse_x = get_bits(gb, 16);
>  params->center_of_ellipse_y = get_bits(gb, 16);
> @@ -78,8 +82,7 @@ int 
> ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
>  if (get_bits_left(gb) < 28)
>  return AVERROR_INVALIDDATA;
>  
> -s->targeted_system_display_maximum_luminance =
> -(AVRational){get_bits_long(gb, 27), luminance_den};
> +s->targeted_system_display_maximum_luminance = (AVRational) { 
> get_bits_long(gb, 27), luminance_den };
>  s->targeted_system_display_actual_peak_luminance_flag = get_bits1(gb);
>  
>  if (s->targeted_system_display_actual_peak_luminance_flag) {
> @@ -99,22 +102,19 @@ int 
> ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
>  
>  

Re: [FFmpeg-devel] [PATCH] avformat/matroska: Support HDR10+ metadata in Matroska.

2022-10-25 Thread Mohammad Izadi
Michael, I appreciate it if you can take a look and give me your feedback.

Thanks,
Mohammad


On Thu, Sep 8, 2022 at 10:03 AM Mohammad Izadi  wrote:

> Michael, I appreciate it if you can take a look and give me your feedback.
>
>
> On Thu, Sep 8, 2022 at 9:31 AM Michael Niedermayer 
> wrote:
>
>> On Wed, Sep 07, 2022 at 02:12:46PM +0100, Derek Buitenhuis wrote:
>> > On 9/6/2022 10:47 PM, Mohammad Izadi wrote:
>> > > +if (side_data && side_data_size > 0)
>> > > +
>> ff_write_dynamic_hdr10_plus_to_full_itu_t_t35((AVDynamicHDRPlus*)side_data,
>> _plus_itu_t_t35, _plus_itu_t_t35_size);
>> >
>> > You can't use ff_-prefixed functions across library boundaries.
>> >
>> > It nees to be either public (av*) or avpriv. I suspect people won't
>> want it to
>> > be avpriv.
>> >
>> > Personally, I think having serialization as a public API is useful, but
>> YMMV. Mostly
>> > because I was just writing my own serialization to make use of the
>> exported side data :P.
>>
>> I agree
>>
>> on a related subject, side data serialization should be moved to a common
>> API
>> We have common APIs for parsers, decoder, bitstream filters but for
>> parsing/decoding side data this is heading toward something less
>> structured
>>
>> Above is not a comment on this patch, the patch is fine. I just want to
>> point
>> to this before we have several dozen such functions which need to be
>> deprecated and supported when a more structured system is introduced
>>
>> thx
>>
>>
>> [...]
>> --
>> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>>
>> Into a blind darkness they enter who follow after the Ignorance,
>> they as if into a greater darkness enter who devote themselves
>> to the Knowledge alone. -- Isha Upanishad
>> ___
>> 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 01/17] avcodec/mpeg12dec: Remove redundant function call

2022-10-25 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Redundant since dcb29d37d4ffedc84e44df99f8d22ecf27e0f2cd.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
> It is of course only redundant if avctx->codec_tag is not allowed
> to change after avcodec_open2(); the corresponding option is not
> marked with the AV_OPT_FLAG_RUNTIME_PARAM and the above mentioned
> commit also relies on this, so I do, too.
> Btw: I wonder whether vcr2_init_sequence() should not simply be called
> during init.
> 
>  libavcodec/mpeg12dec.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
> index 56bf73df11..c942be158e 100644
> --- a/libavcodec/mpeg12dec.c
> +++ b/libavcodec/mpeg12dec.c
> @@ -2797,7 +2797,6 @@ static int mpeg_decode_frame(AVCodecContext *avctx, 
> AVFrame *picture,
>  }
>  #endif
>  
> -s2->codec_tag = ff_toupper4(avctx->codec_tag);
>  if (s->mpeg_enc_ctx_allocated == 0 && (   s2->codec_tag == 
> AV_RL32("VCR2")
> || s2->codec_tag == 
> AV_RL32("BW10")
>))

Will apply this patchset tomorrow unless there are objections.

- Andreas

___
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] avcodec/libaomdec: fix pix_fmt w/AVCOL_SPC_RGB

2022-10-25 Thread Vignesh Venkatasubramanian
On Tue, Oct 25, 2022 at 11:28 AM James Zern
 wrote:
>
> Signed-off-by: James Zern 
> ---
>  libavcodec/libaomdec.c | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/libaomdec.c b/libavcodec/libaomdec.c
> index 378d638a89..53982559d9 100644
> --- a/libavcodec/libaomdec.c
> +++ b/libavcodec/libaomdec.c
> @@ -113,15 +113,19 @@ static int set_pix_fmt(AVCodecContext *avctx, struct 
> aom_image *img)
>  case AOM_IMG_FMT_I444:
>  case AOM_IMG_FMT_I44416:
>  if (img->bit_depth == 8) {
> -avctx->pix_fmt = AV_PIX_FMT_YUV444P;
> +avctx->pix_fmt = avctx->colorspace == AVCOL_SPC_RGB ?
> + AV_PIX_FMT_GBRP : AV_PIX_FMT_YUV444P;
>  avctx->profile = FF_PROFILE_AV1_HIGH;
>  return 0;
>  } else if (img->bit_depth == 10) {
>  avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
> +avctx->pix_fmt = avctx->colorspace == AVCOL_SPC_RGB ?
> + AV_PIX_FMT_GBRP10 : AV_PIX_FMT_YUV444P10;
>  avctx->profile = FF_PROFILE_AV1_HIGH;
>  return 0;
>  } else if (img->bit_depth == 12) {
> -avctx->pix_fmt = AV_PIX_FMT_YUV444P12;
> +avctx->pix_fmt = avctx->colorspace == AVCOL_SPC_RGB ?
> + AV_PIX_FMT_GBRP12 : AV_PIX_FMT_YUV444P12;
>  avctx->profile = FF_PROFILE_AV1_PROFESSIONAL;
>  return 0;
>  } else {
> --
> 2.38.0.135.g90850a2211-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".

lgtm.

I can confirm that AV1 files with gbrp pixel format play back properly
with ffplay with this patch (without this patch it does not look
right).


--
Vignesh
___
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] FFV1 slicecrc: "hashxx" instead of "CRC" for speed?

2022-10-25 Thread Andreas Rheinhardt
Peter B.:
> Hi everyone :)
> 
> This is merely a question of interest. Not a request, complaint or
> trolling of any kind :)
> I'm happy about any answer. I'm curious.
> 
> Would it possibly have a significant impact on coding speed of FFV1's
> slicecrc option (Where a CRC is calculated for each frame slice), to use
> a faster algorithm instead (if one exists)?
> I'm wondering if, for example something like "xxHash" may warrant a try?
> (Haven't found CRC vs xxHash benchmarks yet, but I'm still looking)
> 

The format of the checksum is determined by the FFV1 specification and
not by the decoder/encoder implementation.

- Andreas

___
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] FFV1 slicecrc: "hashxx" instead of "CRC" for speed?

2022-10-25 Thread Peter B.

Hi everyone :)

This is merely a question of interest. Not a request, complaint or 
trolling of any kind :)

I'm happy about any answer. I'm curious.

Would it possibly have a significant impact on coding speed of FFV1's 
slicecrc option (Where a CRC is calculated for each frame slice), to use 
a faster algorithm instead (if one exists)?

I'm wondering if, for example something like "xxHash" may warrant a try?
(Haven't found CRC vs xxHash benchmarks yet, but I'm still looking)



Anyhow,
Thanks for any of your time :D





___
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] avcodec/libaomdec: fix pix_fmt w/AVCOL_SPC_RGB

2022-10-25 Thread James Zern
Signed-off-by: James Zern 
---
 libavcodec/libaomdec.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libaomdec.c b/libavcodec/libaomdec.c
index 378d638a89..53982559d9 100644
--- a/libavcodec/libaomdec.c
+++ b/libavcodec/libaomdec.c
@@ -113,15 +113,19 @@ static int set_pix_fmt(AVCodecContext *avctx, struct 
aom_image *img)
 case AOM_IMG_FMT_I444:
 case AOM_IMG_FMT_I44416:
 if (img->bit_depth == 8) {
-avctx->pix_fmt = AV_PIX_FMT_YUV444P;
+avctx->pix_fmt = avctx->colorspace == AVCOL_SPC_RGB ?
+ AV_PIX_FMT_GBRP : AV_PIX_FMT_YUV444P;
 avctx->profile = FF_PROFILE_AV1_HIGH;
 return 0;
 } else if (img->bit_depth == 10) {
 avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
+avctx->pix_fmt = avctx->colorspace == AVCOL_SPC_RGB ?
+ AV_PIX_FMT_GBRP10 : AV_PIX_FMT_YUV444P10;
 avctx->profile = FF_PROFILE_AV1_HIGH;
 return 0;
 } else if (img->bit_depth == 12) {
-avctx->pix_fmt = AV_PIX_FMT_YUV444P12;
+avctx->pix_fmt = avctx->colorspace == AVCOL_SPC_RGB ?
+ AV_PIX_FMT_GBRP12 : AV_PIX_FMT_YUV444P12;
 avctx->profile = FF_PROFILE_AV1_PROFESSIONAL;
 return 0;
 } else {
-- 
2.38.0.135.g90850a2211-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 v2 2/2] ffmpeg: fix implementation of updated input start time

2022-10-25 Thread Gyan Doshi

Ping.

On 2022-10-21 10:01 pm, Gyan Doshi wrote:

The current adjustment of input start times just adjusts the tsoffset.
And it does so, by resetting the tsoffset to nullify the new start time.
This leads to breakage of -copyts, ignoring of input_ts_offset, breaking
of -isync as well as breaking wrap correction.

Fixed by taking cognizance of these parameters, and by correcting start times
just before sync offsets are applied.
---
  fftools/ffmpeg.c   |  2 +-
  fftools/ffmpeg.h   |  5 -
  fftools/ffmpeg_demux.c |  4 ++--
  fftools/ffmpeg_opt.c   | 33 +++--
  4 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 0fe582be3b..c564b2649e 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1815,7 +1815,7 @@ static void do_streamcopy(InputStream *ist, OutputStream 
*ost, const AVPacket *p
  start_time = 0;
  if (copy_ts) {
  start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0;
-start_time += start_at_zero ? 0 : f->ctx->start_time;
+start_time += start_at_zero ? 0 : f->start_time_effective;
  }
  if (ist->pts >= f->recording_time + start_time) {
  close_output_stream(ost);
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 5966cac60e..2d97ccaa15 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -447,7 +447,10 @@ typedef struct InputFile {
  AVRational time_base; /* time base of the duration */
  int64_t input_ts_offset;
  int input_sync_ref;
-
+/**
+ * Effective format start time based on enabled streams.
+ */
+int64_t start_time_effective;
  int64_t ts_offset;
  /**
   * Extra timestamp offset added by discontinuity handling.
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 6e89f5999a..220fda56da 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -120,7 +120,7 @@ static int seek_to_start(InputFile *ifile)
  static void ts_fixup(InputFile *ifile, AVPacket *pkt, int *repeat_pict)
  {
  InputStream *ist = input_streams[ifile->ist_index + pkt->stream_index];
-const int64_t start_time = ifile->ctx->start_time;
+const int64_t start_time = ifile->start_time_effective;
  int64_t duration;
  
  if (debug_ts) {

@@ -367,7 +367,7 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt)
  if (f->readrate || f->rate_emu) {
  int i;
  int64_t file_start = copy_ts * (
-  (f->ctx->start_time != AV_NOPTS_VALUE ? 
f->ctx->start_time * !start_at_zero : 0) +
+  (f->start_time_effective != AV_NOPTS_VALUE ? 
f->start_time_effective * !start_at_zero : 0) +
(f->start_time != AV_NOPTS_VALUE ? 
f->start_time : 0)
   );
  float scale = f->rate_emu ? 1.0 : f->readrate;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 28b7d4dc27..a6fa9b7801 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -216,13 +216,15 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, 
int file_idx, int st_id
  return 0;
  }
  
+/* Correct input file start times based on enabled streams */

  static void correct_input_start_times(void)
  {
-// Correct starttime based on the enabled streams
  for (int i = 0; i < nb_input_files; i++) {
  InputFile   *ifile = input_files[i];
  AVFormatContext*is = ifile->ctx;
-int64_t new_start_time = INT64_MAX;
+int64_t new_start_time = INT64_MAX, diff, abs_start_seek;
+
+ifile->start_time_effective = is->start_time;
  
  if (is->start_time == AV_NOPTS_VALUE ||

  !(is->iformat->flags & AVFMT_TS_DISCONT))
@@ -234,9 +236,20 @@ static void correct_input_start_times(void)
  continue;
  new_start_time = FFMIN(new_start_time, av_rescale_q(st->start_time, 
st->time_base, AV_TIME_BASE_Q));
  }
-if (new_start_time > is->start_time) {
-av_log(is, AV_LOG_VERBOSE, "Correcting start time by %"PRId64"\n", 
new_start_time - is->start_time);
-ifile->ts_offset = -new_start_time;
+
+diff = new_start_time - is->start_time;
+if (diff) {
+av_log(NULL, AV_LOG_VERBOSE, "Correcting start time of Input #%d by 
%"PRId64" us.\n", i, diff);
+ifile->start_time_effective = new_start_time;
+if (copy_ts && start_at_zero)
+ifile->ts_offset = -new_start_time;
+else if (!copy_ts) {
+abs_start_seek = is->start_time + (ifile->start_time != 
AV_NOPTS_VALUE) ? ifile->start_time : 0;
+ifile->ts_offset = abs_start_seek > new_start_time ? 
-abs_start_seek : -new_start_time;
+} else if (copy_ts)
+ifile->ts_offset = 0;
+
+ifile->ts_offset += ifile->input_ts_offset;
  }
  }
  }
@@ -269,9 +282,9 @@ static int 

Re: [FFmpeg-devel] [avcodec/amfenc: 10 bit support v2 1/3] amf: Update the min version to 1.4.23.0 for AMF SDK.

2022-10-25 Thread Dmitrii Ovchinnikov
Hi! These patches have already been tested and accepted into the  HandBrake
  (https://github.com/HandBrake/HandBrake/pull/4538 ). Could you take a
look?
___
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 V2] lavc/libvpx: increase thread limit to 64

2022-10-25 Thread Dmitrii Ovchinnikov
>> Why do you still impose an upper limit unconditionally even if the
>>user has set his preferred number of threads?
Libvpx-vp9 does not support number of threads greater than 64, so we impose
an upper limit of 64.
E.g. if we set it any higher we get the following execution error:
[libvpx-vp9 @ 0x2f631c0] Failed to initialize encoder: Invalid parameter
[libvpx-vp9 @ 0x2f631c0]   Additional information: g_threads out of range
[..64]
Error initializing output stream 0:0 -- Error while opening encoder for
output stream #0:0 - maybe incorrect parameters such as bit_rate, rate,
width or height

>>According to
https://ffmpeg.org/pipermail/ffmpeg-devel/2018-November/236406.html the
>>maximum of 16 has not been chosen because of H.264, but because there
>>was some form of restriction in libvpx. Or at least there was belief in
>>the existence of such a restriction.
There is a restriction of maximum 64 threads, not 16.

>>This code potentially calls av_cpu_count() twice.
Can you please clarify how it calls it twice? 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".


Re: [FFmpeg-devel] [PATCH v2] lavc/hevc_ps: fix process failed when SPS before VPS in hvcC

2022-10-25 Thread wangyaqiang


> 2022年10月15日 07:00,Michael Niedermayer  写道:
> 
> On Fri, Oct 14, 2022 at 06:13:14PM +0800, wangyaqiang wrote:
>> 
>> 
>>> 2022年9月27日 04:21,Michael Niedermayer  写道:
>>> 
>>> On Mon, Sep 26, 2022 at 05:38:14PM +0800, 1035567...@qq.com wrote:
 From: Wang Yaqiang 
 
 In some videos, SPS will be stored before VPS in hvcC box,
 parse SPS does not depend on VPS, so the video is expected to be processed 
 normally.
 Added "parsed_vps" parameter to indicate whether VPS have been parsed.
 Only VPS have been parsed can be verified during SPS parsing.
 
 Signed-off-by: Wang Yaqiang 
 ---
 libavcodec/hevc_ps.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
>>> 
>>> This causes segfaults
>>> 
>>> ==816== Invalid read of size 8
>>> ==816==at 0xFAF178: hevc_parse (in ffmpeg_g)
>>> ==816==by 0xA7A2A6: av_parser_parse2 (in ffmpeg_g)
>>> ==816==by 0x5FC388: parse_packet (in ffmpeg_g)
>>> ==816==by 0x5FDC5D: read_frame_internal (in ffmpeg_g)
>>> ==816==by 0x5FFA10: avformat_find_stream_info (in ffmpeg_g)
>>> ==816==by 0x2F6054: open_input_file (in ffmpeg_g)
>>> ==816==by 0x2FC6AB: ffmpeg_parse_options (in ffmpeg_g)
>>> ==816==by 0x2E8A34: main (in ffmpeg_g)
>>> ==816==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
>>> 
>>> 
>>> [...]
>> 
>> Excuse me, we have run tests on our own business and have not found this 
>> problem, but it is a hidden risk,really hope you can tell me how to 
>> reproduce this problem. Thanks
> 
> heres a more complete stack trace, i willmail you the input sample privatly
> 

Thanks very much for the materials. Under the condition that vps is not 
strongly checked when parsing sps, it is necessary to determine whether vps is 
empty when vps is used. I submitted a new patch to fix the crash, but I feel 
that this way is a little trick,any good ideas?

> Trailing option(s) found in the command: may be ignored.
> [hevc @ 0x16a0ad40] Invalid NAL unit 0, skipping.
> [hevc @ 0x16a0ad40] PTL information too short
> ==24589==at 0x12A19DF: VALGRIND_PRINTF_BACKTRACE (valgrind.h:6303)
> ==24589==by 0x12A259D: av_log_default_callback (log.c:399)
> ==24589==by 0x12A2844: av_vlog (log.c:434)
> ==24589==by 0x12A26A3: av_log (log.c:413)
> ==24589==by 0x10A7216: parse_ptl (hevc_ps.c:342)
> ==24589==by 0x10A78B4: ff_hevc_decode_nal_vps (hevc_ps.c:503)
> ==24589==by 0x10A579C: parse_nal_units (hevc_parser.c:212)
> ==24589==by 0x10A5B46: hevc_parse (hevc_parser.c:331)
> ==24589==by 0xB82366: av_parser_parse2 (parser.c:163)
> ==24589==by 0x61BD17: parse_packet (demux.c:1140)
> ==24589==by 0x61C936: read_frame_internal (demux.c:1334)
> ==24589==by 0x6217A7: avformat_find_stream_info (demux.c:2612)
> ==24589==by 0x246A51: open_input_file (ffmpeg_opt.c:1315)
> ==24589==by 0x255E38: open_files (ffmpeg_opt.c:3703)
> ==24589==by 0x255FEC: ffmpeg_parse_options (ffmpeg_opt.c:3742)
> ==24589==by 0x26EFEE: main (ffmpeg.c:4236)
> [hevc @ 0x16a0ad40] VPS 0 does not exist
> ==24589== Invalid read of size 8
> ==24589==at 0x10A5189: hevc_parse_slice_header (hevc_parser.c:88)
> ==24589==by 0x10A584E: parse_nal_units (hevc_parser.c:245)
> ==24589==by 0x10A5B46: hevc_parse (hevc_parser.c:331)
> ==24589==by 0xB82366: av_parser_parse2 (parser.c:163)
> ==24589==by 0x61BD17: parse_packet (demux.c:1140)
> ==24589==by 0x61C936: read_frame_internal (demux.c:1334)
> ==24589==by 0x6217A7: avformat_find_stream_info (demux.c:2612)
> ==24589==by 0x246A51: open_input_file (ffmpeg_opt.c:1315)
> ==24589==by 0x255E38: open_files (ffmpeg_opt.c:3703)
> ==24589==by 0x255FEC: ffmpeg_parse_options (ffmpeg_opt.c:3742)
> ==24589==by 0x26EFEE: main (ffmpeg.c:4236)
> ==24589==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
> ==24589== 
> ==24589== 
> ==24589== Process terminating with default action of signal 11 (SIGSEGV)
> ==24589==  Access not within mapped region at address 0x8
> ==24589==at 0x10A5189: hevc_parse_slice_header (hevc_parser.c:88)
> ==24589==by 0x10A584E: parse_nal_units (hevc_parser.c:245)
> ==24589==by 0x10A5B46: hevc_parse (hevc_parser.c:331)
> ==24589==by 0xB82366: av_parser_parse2 (parser.c:163)
> ==24589==by 0x61BD17: parse_packet (demux.c:1140)
> ==24589==by 0x61C936: read_frame_internal (demux.c:1334)
> ==24589==by 0x6217A7: avformat_find_stream_info (demux.c:2612)
> ==24589==by 0x246A51: open_input_file (ffmpeg_opt.c:1315)
> ==24589==by 0x255E38: open_files (ffmpeg_opt.c:3703)
> ==24589==by 0x255FEC: ffmpeg_parse_options (ffmpeg_opt.c:3742)
> ==24589==by 0x26EFEE: main (ffmpeg.c:4236)
> 
> [...]
> 
> -- 
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> Concerning the gods, I have no means of knowing whether they exist or not
> or of what sort they may be, because of the obscurity of the subject, and
> the brevity of human life -- Protagoras
> 

Re: [FFmpeg-devel] [PATCH v3] lavc/aarch64: add hevc horizontal qpel/uni/bi

2022-10-25 Thread J. Dekker


On 24 Oct 2022, at 14:01, Martin Storsjö wrote:

> On Tue, 11 Oct 2022, J. Dekker wrote:
>
>> [...]
>> diff --git a/libavcodec/aarch64/hevcdsp_init_aarch64.c 
>> b/libavcodec/aarch64/hevcdsp_init_aarch64.c
>> index 644cc17715..44399b05d8 100644
>> --- a/libavcodec/aarch64/hevcdsp_init_aarch64.c
>> +++ b/libavcodec/aarch64/hevcdsp_init_aarch64.c
>> @@ -69,6 +69,46 @@ void ff_hevc_sao_edge_filter_16x16_8_neon(uint8_t *dst, 
>> const uint8_t *src, ptrd
>>   const int16_t *sao_offset_val, int 
>> eo, int width, int height);
>> void ff_hevc_sao_edge_filter_8x8_8_neon(uint8_t *dst, const uint8_t *src, 
>> ptrdiff_t stride_dst,
>> const int16_t *sao_offset_val, int 
>> eo, int width, int height);
>> +void ff_hevc_put_hevc_qpel_h4_8_neon(int16_t *dst, uint8_t *_src, ptrdiff_t 
>> _srcstride, int height,
>> + intptr_t mx, intptr_t my, int width);
>
> The function pointers in the dsp context has gotten 'const' on the source 
> pointers now, which makes it emit a lot of warnings with GCC, and fail with 
> latest Clang. Please rebase and check that it builds without warnings.
>

Fixed.

>> [...]
>> +.ifc \type, qpel
>> +function ff_hevc_put_hevc_h4_8_neon, export=0
>> +uxtlv16.8h,  v16.8b
>> +uxtlv17.8h,  v17.8b
>> +uxtlv18.8h,  v18.8b
>> +uxtlv19.8h,  v19.8b
>> +
>> +mul v23.4h,  v16.4h, v0.h[0]
>> +mul v24.4h,  v18.4h, v0.h[0]
>> +
>> +.irpc i, 1234567
>> +ext v20.16b, v16.16b, v17.16b, #(2*\i)
>> +ext v21.16b, v18.16b, v19.16b, #(2*\i)
>> +mla v23.4h,  v20.4h, v0.h[\i]
>> +mla v24.4h,  v21.4h, v0.h[\i]
>> +.endr
>> +ret
>> +endfunc
>> +.endif
>> +
>> +function ff_hevc_put_hevc_\type\()_h4_8_neon, export=1
>> +load_filter mx
>> +.ifc \type, qpel_bi
>> +mov x16, #(MAX_PB_SIZE << 2) // src2bstridel
>> +add x15, x4, #(MAX_PB_SIZE << 1) // src2b
>
> Beware that you can't in general rely on x16/x17 keeping their values for 
> long. If you branch to a function which is implemented in a different object 
> file, it may end up linked at a place in the address space which is too far 
> away for a regular 'bl' branch, so the linker has to insert a range extension 
> thunk, which clobbers x16/x17. But as long as everything here is branched 
> within the same object file, it should be ok.
>
> In general, if you need to use x16/x17, use it only for very short-lived 
> temporaries.

Alright, thanks for the consideration. Left as is since as you said we're not 
branching anywhere outside this file.

>> +.endif
>> +sub src, src, #3
>> +mov mx, lr
>
> Please use literal 'x30' instead of 'lr' - older binutils don't support the 
> 'lr' register name alias.

Fixed.

> Other than that, the code seems to run correctly, and the code looks mostly 
> reasonable now. (I didn't do a very deep read-through this time, but it looks 
> like you've addressed my earlier concerns.)

Thanks for the review, pushed with above fixes.

-- 
jd
___
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] avcodec/svq1enc: Workaround GCC bug 102513

2022-10-25 Thread J. Dekker
On 25 Oct 2022, at 14:48, Andreas Rheinhardt wrote:

> GCC 11 has a bug: When it creates clones of recursive functions
> (to inline some parameters), it clones a recursive function
> eight times by default, even when this exceeds the recursion
> depth. This happens with encode_block() in libavcodec/svq1enc.c
> where a parameter level is always in the range 0..5;
> but GCC 11 also creates functions corresponding to level UINT_MAX
> and UINT_MAX - 1 (on -O3; -O2 is fine).
>
> Using such levels would produce undefined behaviour and because
> of this GCC emits bogus -Warray-bounds warnings for these clones.
>
> Since commit d08b2900a9f0935959303da668cb00a8a7245228, certain
> symbols that are accessed like ff_svq1_inter_multistage_vlc[level]
> are declared with hidden visibility, which allows compilers
> to bake the offset implied by level into the instructions
> if level is a compile-time constant as it is in the clones.
> Yet this leads to insane offsets for level == UINT_MAX which
> can be incompatible with the supported offset ranges of relocations.
> This happens in the small code model (the default code model for
> AArch64).
>
> This commit therefore works around this bug by disabling cloning
> recursive functions for GCC 10 and 11. GCC 10 is affected by the
> underlying bug (see
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102513), so the workaround
> also targets it, although it only produces three versions of
> encode_block(), so it does not seem to trigger the actual issue here.
>
> The issue has been mitigated in GCC 12.1 (it no longer creates clones
> for impossible values; see also commit
> 1cb7fd317c84117bbb13b14851d62f77f57bb9ce), so the workaround
> does not target it.
>
> Reported-by: Josh Dekker 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/svq1enc.c | 6 ++
>  1 file changed, 6 insertions(+)
>
> diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
> index 75adbe7ea0..7c9430a137 100644
> --- a/libavcodec/svq1enc.c
> +++ b/libavcodec/svq1enc.c
> @@ -46,6 +46,12 @@
>  #include "libavutil/frame.h"
>  #include "libavutil/mem_internal.h"
>
> +// Workaround for GCC bug 102513
> +#if AV_GCC_VERSION_AT_LEAST(10, 0) && AV_GCC_VERSION_AT_MOST(12, 0) \
> +&& !defined(__clang__) && !defined(__INTEL_COMPILER)
> +#pragma GCC optimize ("no-ipa-cp-clone")
> +#endif
> +
>  typedef struct SVQ1EncContext {
>  /* FIXME: Needed for motion estimation, should not be used for anything
>   * else, the idea is to make the motion estimation eventually independent

Discussed on IRC, LGTM & pushed.

-- 
jd
___
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] avcodec/svq1enc: Workaround GCC bug 102513

2022-10-25 Thread Andreas Rheinhardt
GCC 11 has a bug: When it creates clones of recursive functions
(to inline some parameters), it clones a recursive function
eight times by default, even when this exceeds the recursion
depth. This happens with encode_block() in libavcodec/svq1enc.c
where a parameter level is always in the range 0..5;
but GCC 11 also creates functions corresponding to level UINT_MAX
and UINT_MAX - 1 (on -O3; -O2 is fine).

Using such levels would produce undefined behaviour and because
of this GCC emits bogus -Warray-bounds warnings for these clones.

Since commit d08b2900a9f0935959303da668cb00a8a7245228, certain
symbols that are accessed like ff_svq1_inter_multistage_vlc[level]
are declared with hidden visibility, which allows compilers
to bake the offset implied by level into the instructions
if level is a compile-time constant as it is in the clones.
Yet this leads to insane offsets for level == UINT_MAX which
can be incompatible with the supported offset ranges of relocations.
This happens in the small code model (the default code model for
AArch64).

This commit therefore works around this bug by disabling cloning
recursive functions for GCC 10 and 11. GCC 10 is affected by the
underlying bug (see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102513), so the workaround
also targets it, although it only produces three versions of
encode_block(), so it does not seem to trigger the actual issue here.

The issue has been mitigated in GCC 12.1 (it no longer creates clones
for impossible values; see also commit
1cb7fd317c84117bbb13b14851d62f77f57bb9ce), so the workaround
does not target it.

Reported-by: Josh Dekker 
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/svq1enc.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 75adbe7ea0..7c9430a137 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -46,6 +46,12 @@
 #include "libavutil/frame.h"
 #include "libavutil/mem_internal.h"
 
+// Workaround for GCC bug 102513
+#if AV_GCC_VERSION_AT_LEAST(10, 0) && AV_GCC_VERSION_AT_MOST(12, 0) \
+&& !defined(__clang__) && !defined(__INTEL_COMPILER)
+#pragma GCC optimize ("no-ipa-cp-clone")
+#endif
+
 typedef struct SVQ1EncContext {
 /* FIXME: Needed for motion estimation, should not be used for anything
  * else, the idea is to make the motion estimation eventually independent
-- 
2.34.1

___
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 v14 9/9] avcodec/evc: Changes in Changelog and MAINTAINERS files

2022-10-25 Thread Lynne




Oct 24, 2022, 18:29 by jamr...@gmail.com:

> On 10/24/2022 12:56 PM, Lynne wrote:
>
>> Oct 24, 2022, 09:42 by d.kozin...@samsung.com:
>>
>>> - Changelog update
>>> - MAINTAINERS update
>>>
>>> Signed-off-by: Dawid Kozinski 
>>> ---
>>>  Changelog   | 3 ++-
>>>  MAINTAINERS | 5 +
>>>  2 files changed, 7 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/Changelog b/Changelog
>>> index ec9de1bd85..19e9ae3b1f 100644
>>> --- a/Changelog
>>> +++ b/Changelog
>>> @@ -45,6 +45,8 @@ version 5.1:
>>>  - remap_opencl filter
>>>  - added chromakey_cuda filter
>>>  - added bilateral_cuda filter
>>> +- eXtra-fast Essential Video Encoder (XEVE)
>>> +- eXtra-fast Essential Video Decoder (XEVD)
>>>  version 5.0:
>>> @@ -92,7 +94,6 @@ version 5.0:
>>>  - anlmf audio filter
>>>  - IMF demuxer (experimental)
>>>  -
>>>  version 4.4:
>>>  - AudioToolbox output device
>>>  - MacCaption demuxer
>>> diff --git a/MAINTAINERS b/MAINTAINERS
>>> index eebfa5cfb7..df8d8eca73 100644
>>> --- a/MAINTAINERS
>>> +++ b/MAINTAINERS
>>> @@ -200,6 +200,8 @@ Codecs:
>>>  libvpx*   James Zern
>>>  libxavs.c Stefan Gehrer
>>>  libxavs2.cHuiwen Ren
>>> +  libxevd.c Dawid Kozinski
>>> +  libxeve.c,Dawid Kozinski
>>>  libzvbi-teletextdec.c Marton Balint
>>>  lzo.h, lzo.c  Reimar Doeffinger
>>>  mdec.cMichael Niedermayer
>>> @@ -420,6 +422,9 @@ Muxers/Demuxers:
>>>  dv.c  Roman Shaposhnik
>>>  electronicarts.c  Peter Ross
>>>  epafdec.c Paul B Mahol
>>> +  evc.c, evc.h  Dawid Kozinski
>>> +  evcdec.c  Dawid Kozinski
>>> +  evc_parser.c  Dawid Kozinski
>>>  ffm*  Baptiste Coudurier
>>>  flic.cMike Melanson
>>>  flvdec.c  Michael Niedermayer
>>>
>>
>> Nak, that list is only for those with push access, and no
>> other changes may be made in the same patch.
>>
>
> No, it's the other way around. Those in this list may be eligible for push 
> access.
> Being listed here gives them the right to NAK a patch made for a module they 
> maintain, as well as their approval being (ideally) a requirement before 
> making changes to it.
>

Nope. Michael will give anyone on the list push access.
That's why I insisted on a rule to separate out such patches to avoid sneaking 
in.
The whole problem would be solved by having 2 lists, but instead, users
have to explicitly ask not to get push access if they want to get added to 
maintainers.

___
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] ffmpeg-rtpdec-4175-gray

2022-10-25 Thread Evgeny
Support of grayscale video (from IR-camera as example)

--- libavformat/rtpdec_rfc4175.c
+++ libavformat/rtpdec_rfc4175.c
@@ -96,6 +96,16 @@ static int rfc4175_parse_format(AVStream *stream, PayloadContext *data)
 		} else {
 			return AVERROR_INVALIDDATA;
 		}
+	} else if (!strncmp(data->sampling, "Gray", 3)) {
+		tag = MKTAG('Y', '8', ' ', ' ');
+		if (data->depth == 8) {
+			data->xinc = 1;
+			data->pgroup = 1;
+			pixfmt = AV_PIX_FMT_GRAY8;
+			stream->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
+		} else {
+			return AVERROR_INVALIDDATA;
+		}
 	} else {
 		return AVERROR_INVALIDDATA;
 	}

___
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] fate/microsoft: add mss2 region test case

2022-10-25 Thread Peter Ross
---

please copy https://trac.ffmpeg.org/raw-attachment/ticket/4043/fail.wmv
to $FATE_SAMPLES/mss2

 tests/fate/microsoft.mak | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/fate/microsoft.mak b/tests/fate/microsoft.mak
index ee1a062425..edd42df8b3 100644
--- a/tests/fate/microsoft.mak
+++ b/tests/fate/microsoft.mak
@@ -14,8 +14,9 @@ FATE_MSS2-$(call FRAMECRC, ASF, MSS2, SCALE_FILTER) += 
fate-mss2-rgb555 fate-mss
 fate-mss2-rgb555:  CMD = framecrc -i $(TARGET_SAMPLES)/mss2/rle555.wmv  
-pix_fmt rgb555le -vf scale
 fate-mss2-rgb555s: CMD = framecrc -i $(TARGET_SAMPLES)/mss2/rle555s.wmv 
-pix_fmt rgb555le -vf scale
 
-FATE_MSS2 += fate-mss2-wmv
+FATE_MSS2 += fate-mss2-wmv fate-mss2-region
 fate-mss2-wmv: CMD = framecrc -i $(TARGET_SAMPLES)/mss2/msscreencodec.wmv -an 
-frames 100
+fate-mss2-region: CMD = framecrc -i $(TARGET_SAMPLES)/mss2/fail.wmv -an
 
 FATE_MSS2-$(call FRAMECRC, ASF, MSS2) += $(FATE_MSS2)
 
-- 
2.35.1

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


signature.asc
Description: PGP signature
___
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] swscale: aarch64: Fix yuv2rgb with negative strides

2022-10-25 Thread Martin Storsjö
Treat the 32 bit stride registers as signed.

Alternatively, we could make the stride arguments ptrdiff_t instead
of int, and changing all of the assembly to operate on these
registers with their full 64 bit width, but that's a much larger
and more intrusive change (and risks missing some operation, which
would clamp the intermediates to 32 bit still).

Fixes: https://trac.ffmpeg.org/ticket/9985

Signed-off-by: Martin Storsjö 
---
 libswscale/aarch64/yuv2rgb_neon.S | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libswscale/aarch64/yuv2rgb_neon.S 
b/libswscale/aarch64/yuv2rgb_neon.S
index f4b220fb60..f341268c5d 100644
--- a/libswscale/aarch64/yuv2rgb_neon.S
+++ b/libswscale/aarch64/yuv2rgb_neon.S
@@ -118,8 +118,8 @@
 .endm
 
 .macro increment_yuv422p
-add x6,  x6,  w7, UXTW  // 
srcU += incU
-add x13, x13, w14, UXTW // 
srcV += incV
+add x6,  x6,  w7, SXTW  // 
srcU += incU
+add x13, x13, w14, SXTW // 
srcV += incV
 .endm
 
 .macro compute_rgba r1 g1 b1 a1 r2 g2 b2 a2
@@ -189,8 +189,8 @@ function ff_\ifmt\()_to_\ofmt\()_neon, export=1
 st4 {v16.8B,v17.8B,v18.8B,v19.8B}, [x2], #32
 subsw8, w8, #16 // 
width -= 16
 b.gt2b
-add x2, x2, w3, UXTW// dst 
 += padding
-add x4, x4, w5, UXTW// 
srcY += paddingY
+add x2, x2, w3, SXTW// dst 
 += padding
+add x4, x4, w5, SXTW// 
srcY += paddingY
 increment_\ifmt
 subsw1, w1, #1  // 
height -= 1
 b.gt1b
-- 
2.37.0 (Apple Git-136)

___
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 v9 02/25] avutil/frame: Prepare AVFrame for subtitle handling

2022-10-25 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Hendrik Leppkes
> Sent: Tuesday, October 25, 2022 11:38 AM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH v9 02/25] avutil/frame: Prepare
> AVFrame for subtitle handling
> 
> On Tue, Oct 25, 2022 at 11:14 AM softworkz 
> wrote:
> >
> > @@ -712,6 +712,53 @@ typedef struct AVFrame {
> >   * Duration of the frame, in the same units as pts. 0 if
> unknown.
> >   */
> >  int64_t duration;
> > +
> > +/**
> > + * Media type of the frame (audio, video, subtitles..)
> > + *
> > + * See AVMEDIA_TYPE_xxx
> > + */
> > +enum AVMediaType type;
> > +
> > +/**
> > + * Number of items in the @ref subtitle_areas array.
> > + */
> > +unsigned num_subtitle_areas;
> > +
> > +/**
> > + * Array of subtitle areas, may be empty.
> > + */
> > +AVSubtitleArea **subtitle_areas;
> > +
> > +/**
> > + * Header containing style information for text subtitles.
> > + */
> > +AVBufferRef *subtitle_header;
> > +
> > +/**
> > + * Indicates that a subtitle frame is a repeated frame for
> arbitrating flow
> > + * in a filter graph.
> > + * The field subtitle_timing.start_pts always indicates the
> original presentation
> > + * time, while the frame's pts field may be different.
> > + */
> > +int repeat_sub;
> > +
> > +struct SubtitleTiming
> > +{
> > +/**
> > + * The display start time, in AV_TIME_BASE.
> > + *
> > + * For subtitle frames, AVFrame.pts is populated from the
> packet pts value,
> > + * which is not always the same as this value.
> > + */
> > +int64_t start_pts;
> 
> There is still no explanation here why they are not the same, why
> they
> could not just be the same, and which field a user should look at.
> The cover letter talks about clarity why this is needed is important,
> but then provides none of that.
> 
> "Its required" is not an argument. So please enlighten us once again
> why we absolutely need two timestamps for subtitles, instead of just
> one. As far as I can see, subtitle frames only have one relevant time
> - when its supposed to be shown on the screen. What would the other
> time ever be good for to a user?
> Similarly for the duration, of course. I can even see the
> AVFrame.duration field in this patch snippet just above the additions
> that would seem to fully replace this one.
> 
> - Hendrik

Hi Hendrik,

thanks a lot for your reply.

Probably I should have better advertised the article I had written 
specifically to explain the background of this:

https://github.com/softworkz/SubtitleFilteringDemos/issues/1

I hope it's understandable - please let me know when you have 
questions.


Thanks again,
softworkz
___
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 v2 2/5] avutil/dict: Use av_dict_iterate in av_dict_get

2022-10-25 Thread Anton Khirnov
Quoting Marvin Scholz (2022-09-24 16:36:56)
> ---
>  libavutil/dict.c | 16 ++--
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/libavutil/dict.c b/libavutil/dict.c
> index ee059d712c..ea03590d0f 100644
> --- a/libavutil/dict.c
> +++ b/libavutil/dict.c
> @@ -60,18 +60,14 @@ const AVDictionaryEntry *av_dict_iterate(const 
> AVDictionary *m,
>  AVDictionaryEntry *av_dict_get(const AVDictionary *m, const char *key,
> const AVDictionaryEntry *prev, int flags)
>  {
> -unsigned int i, j;
> +   const AVDictionaryEntry *entry = prev;

Broken indentation, otherwise looks good.

-- 
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".


Re: [FFmpeg-devel] [PATCH v2 1/5] avutil/dict: Add av_dict_iterate

2022-10-25 Thread Anton Khirnov
Quoting Marvin Scholz (2022-09-24 16:36:55)
> diff --git a/libavutil/dict.h b/libavutil/dict.h
> index 0d1afc6c64..344afb452b 100644
> --- a/libavutil/dict.h
> +++ b/libavutil/dict.h
> @@ -32,6 +32,8 @@
>  
>  #include 
>  
> +#include "attributes.h"

This seems unnecessary now.

Will push with this include removed, if noone objects.

-- 
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".


Re: [FFmpeg-devel] [PATCH v9 02/25] avutil/frame: Prepare AVFrame for subtitle handling

2022-10-25 Thread Hendrik Leppkes
On Tue, Oct 25, 2022 at 11:14 AM softworkz  wrote:
>
> @@ -712,6 +712,53 @@ typedef struct AVFrame {
>   * Duration of the frame, in the same units as pts. 0 if unknown.
>   */
>  int64_t duration;
> +
> +/**
> + * Media type of the frame (audio, video, subtitles..)
> + *
> + * See AVMEDIA_TYPE_xxx
> + */
> +enum AVMediaType type;
> +
> +/**
> + * Number of items in the @ref subtitle_areas array.
> + */
> +unsigned num_subtitle_areas;
> +
> +/**
> + * Array of subtitle areas, may be empty.
> + */
> +AVSubtitleArea **subtitle_areas;
> +
> +/**
> + * Header containing style information for text subtitles.
> + */
> +AVBufferRef *subtitle_header;
> +
> +/**
> + * Indicates that a subtitle frame is a repeated frame for arbitrating 
> flow
> + * in a filter graph.
> + * The field subtitle_timing.start_pts always indicates the original 
> presentation
> + * time, while the frame's pts field may be different.
> + */
> +int repeat_sub;
> +
> +struct SubtitleTiming
> +{
> +/**
> + * The display start time, in AV_TIME_BASE.
> + *
> + * For subtitle frames, AVFrame.pts is populated from the packet pts 
> value,
> + * which is not always the same as this value.
> + */
> +int64_t start_pts;

There is still no explanation here why they are not the same, why they
could not just be the same, and which field a user should look at.
The cover letter talks about clarity why this is needed is important,
but then provides none of that.

"Its required" is not an argument. So please enlighten us once again
why we absolutely need two timestamps for subtitles, instead of just
one. As far as I can see, subtitle frames only have one relevant time
- when its supposed to be shown on the screen. What would the other
time ever be good for to a user?
Similarly for the duration, of course. I can even see the
AVFrame.duration field in this patch snippet just above the additions
that would seem to fully replace this one.

- Hendrik



> +
> +/**
> + * Display duration, in AV_TIME_BASE.
> + */
> +int64_t duration;
> +
> +} subtitle_timing;
>  } AVFrame;
>
>
> @@ -788,6 +835,8 @@ void av_frame_move_ref(AVFrame *dst, AVFrame *src);
>  /**
>   * Allocate new buffer(s) for audio or video data.
>   *
> + * Note: For subtitle data, use av_frame_get_buffer2
> + *
>   * The following fields must be set on frame before calling this function:
>   * - format (pixel format for video, sample format for audio)
>   * - width and height for video
> @@ -807,9 +856,39 @@ void av_frame_move_ref(AVFrame *dst, AVFrame *src);
>   *  recommended to pass 0 here unless you know what you are 
> doing.
>   *
>   * @return 0 on success, a negative AVERROR on error.
> + *
> + * @deprecated Use @ref av_frame_get_buffer2 instead and set @ref 
> AVFrame.type
> + * before calling.
>   */
> +attribute_deprecated
>  int av_frame_get_buffer(AVFrame *frame, int align);
>
> +/**
> + * Allocate new buffer(s) for audio, video or subtitle data.
> + *
> + * The following fields must be set on frame before calling this function:
> + * - format (pixel format for video, sample format for audio)
> + * - width and height for video
> + * - nb_samples and channel_layout for audio
> + * - type (AVMediaType)
> + *
> + * This function will fill AVFrame.data and AVFrame.buf arrays and, if
> + * necessary, allocate and fill AVFrame.extended_data and 
> AVFrame.extended_buf.
> + * For planar formats, one buffer will be allocated for each plane.
> + *
> + * @warning: if frame already has been allocated, calling this function will
> + *   leak memory. In addition, undefined behavior can occur in 
> certain
> + *   cases.
> + *
> + * @param frame frame in which to store the new buffers.
> + * @param align Required buffer size alignment. If equal to 0, alignment 
> will be
> + *  chosen automatically for the current CPU. It is highly
> + *  recommended to pass 0 here unless you know what you are 
> doing.
> + *
> + * @return 0 on success, a negative AVERROR on error.
> + */
> +int av_frame_get_buffer2(AVFrame *frame, int align);
> +
>  /**
>   * Check if the frame data is writable.
>   *
> diff --git a/libavutil/subfmt.c b/libavutil/subfmt.c
> new file mode 100644
> index 00..c72ebe2a43
> --- /dev/null
> +++ b/libavutil/subfmt.c
> @@ -0,0 +1,45 @@
> +/*
> + * Copyright (c) 2021 softworkz
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> 

[FFmpeg-devel] [PATCHv3 4/4] avcodec/svq1dec: detect buggy FFmpeg encoder and apply correction to interframe mean symbols

2022-10-25 Thread Peter Ross
---
 libavcodec/svq1dec.c | 32 +++-
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/libavcodec/svq1dec.c b/libavcodec/svq1dec.c
index 828b38b93d..c7269456e2 100644
--- a/libavcodec/svq1dec.c
+++ b/libavcodec/svq1dec.c
@@ -73,6 +73,8 @@ typedef struct SVQ1Context {
 int height;
 int frame_code;
 int nonref; // 1 if the current frame won't be referenced
+
+int last_tempref;
 } SVQ1Context;
 
 static const uint8_t string_table[256] = {
@@ -229,7 +231,7 @@ static int svq1_decode_block_intra(GetBitContext *bitbuf, 
uint8_t *pixels,
 }
 
 static int svq1_decode_block_non_intra(GetBitContext *bitbuf, uint8_t *pixels,
-   ptrdiff_t pitch)
+   ptrdiff_t pitch, int buggy)
 {
 uint32_t bit_cache;
 uint8_t *list[63];
@@ -270,6 +272,13 @@ static int svq1_decode_block_non_intra(GetBitContext 
*bitbuf, uint8_t *pixels,
 
 mean = get_vlc2(bitbuf, svq1_inter_mean.table, 9, 3) - 256;
 
+if (buggy) {
+if (mean == -128)
+mean = 128;
+else if (mean == 128)
+mean = -128;
+}
+
 SVQ1_CALC_CODEBOOK_ENTRIES(ff_svq1_inter_codebooks);
 
 for (y = 0; y < height; y++) {
@@ -455,7 +464,7 @@ static int svq1_decode_delta_block(AVCodecContext *avctx, 
HpelDSPContext *hdsp,
GetBitContext *bitbuf,
uint8_t *current, uint8_t *previous,
ptrdiff_t pitch, svq1_pmv *motion, int x, 
int y,
-   int width, int height)
+   int width, int height, int buggy)
 {
 uint32_t block_type;
 int result = 0;
@@ -487,7 +496,7 @@ static int svq1_decode_delta_block(AVCodecContext *avctx, 
HpelDSPContext *hdsp,
 ff_dlog(avctx, "Error in svq1_motion_inter_block %i\n", result);
 break;
 }
-result = svq1_decode_block_non_intra(bitbuf, current, pitch);
+result = svq1_decode_block_non_intra(bitbuf, current, pitch, buggy);
 break;
 
 case SVQ1_BLOCK_INTER_4V:
@@ -498,7 +507,7 @@ static int svq1_decode_delta_block(AVCodecContext *avctx, 
HpelDSPContext *hdsp,
 ff_dlog(avctx, "Error in svq1_motion_inter_4v_block %i\n", result);
 break;
 }
-result = svq1_decode_block_non_intra(bitbuf, current, pitch);
+result = svq1_decode_block_non_intra(bitbuf, current, pitch, buggy);
 break;
 
 case SVQ1_BLOCK_INTRA:
@@ -524,15 +533,18 @@ static void svq1_parse_string(GetBitContext *bitbuf, 
uint8_t out[257])
 out[i] = 0;
 }
 
-static int svq1_decode_frame_header(AVCodecContext *avctx, AVFrame *frame)
+static int svq1_decode_frame_header(AVCodecContext *avctx, AVFrame *frame, int 
* buggy)
 {
 SVQ1Context *s = avctx->priv_data;
 GetBitContext *bitbuf = >gb;
 int frame_size_code;
 int width  = s->width;
 int height = s->height;
+int tempref;
 
-skip_bits(bitbuf, 8); /* temporal_reference */
+tempref = get_bits(bitbuf, 8); /* temporal_reference */
+*buggy = tempref == 0 && s->last_tempref == 0 && avctx->extradata_size == 
0;
+s->last_tempref = tempref;
 
 /* frame type */
 s->nonref = 0;
@@ -624,7 +636,7 @@ static int svq1_decode_frame(AVCodecContext *avctx, AVFrame 
*cur,
 int buf_size   = avpkt->size;
 SVQ1Context *s = avctx->priv_data;
 uint8_t *current;
-int result, i, x, y, width, height;
+int result, i, x, y, width, height, buggy;
 int ret;
 
 /* initialize bit buffer */
@@ -664,7 +676,7 @@ static int svq1_decode_frame(AVCodecContext *avctx, AVFrame 
*cur,
 src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];
 }
 
-result = svq1_decode_frame_header(avctx, cur);
+result = svq1_decode_frame_header(avctx, cur, );
 if (result != 0) {
 ff_dlog(avctx, "Error in svq1_decode_frame_header %i\n", result);
 return result;
@@ -734,7 +746,7 @@ static int svq1_decode_frame(AVCodecContext *avctx, AVFrame 
*cur,
 result = svq1_decode_delta_block(avctx, >hdsp,
  >gb, [x],
  previous, linesize,
- s->pmv, x, y, width, 
height);
+ s->pmv, x, y, width, 
height, buggy);
 if (result != 0) {
 ff_dlog(avctx,
 "Error in svq1_decode_delta_block %i\n",
@@ -820,6 +832,8 @@ static av_cold int svq1_decode_init(AVCodecContext *avctx)
 
 ff_thread_once(_static_once, svq1_static_init);
 
+s->last_tempref = 0xFF;
+
 return 0;
 }
 
-- 
2.35.1

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


signature.asc
Description: PGP 

[FFmpeg-devel] [PATCHv3 3/4] avcodec/svq1: fix interframe mean VLC symbols

2022-10-25 Thread Peter Ross
Fixes ticket #128.

The SVQ1 interframe mean VLC symbols -128 and 128 are incorrectly swapped
in our SVQ1 implementation, resulting in visible artifacts for some videos.
This patch unswaps the order of these two symbols.

The most noticable example of the artiacts caused by this error can be observed 
in
https://trac.ffmpeg.org/attachment/ticket/128/svq1_set.7z '352_288_k_50.mov'.
The artifacts are not observed when using the reference decoder
(QuickTime 7.7.9 x86 binary).

As a result of this patch, the reference data for the fate-svq1 test
($SAMPLES/svq1/marymary-shackles.mov) must be modified. For this file, our
decoder output is now bitwise identical to the reference decoder. I have
tested patch with various other samples and they are all now bitwise identical.
---
 libavcodec/svq1_vlc.h |  4 ++--
 tests/ref/fate/svq1   | 22 +++---
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/libavcodec/svq1_vlc.h b/libavcodec/svq1_vlc.h
index 06e3509e4d..5c27928c2a 100644
--- a/libavcodec/svq1_vlc.h
+++ b/libavcodec/svq1_vlc.h
@@ -167,7 +167,7 @@ const uint16_t ff_svq1_inter_mean_vlc[512][2] = {
 { 0xA0, 22 },  { 0xA1, 22 },  { 0xA2, 22 },  { 0xA3, 22 },
 { 0xA4, 22 },  { 0xA5, 22 },  { 0xA6, 22 },  { 0xA7, 22 },
 { 0xA8, 22 },  { 0xA9, 22 },  { 0xAA, 22 },  { 0xAB, 22 },
-{ 0x7F, 22 },  { 0x8F, 21 },  { 0xAC, 22 },  { 0xAD, 22 },
+{ 0x8E, 21 },  { 0x8F, 21 },  { 0xAC, 22 },  { 0xAD, 22 },
 { 0xAE, 22 },  { 0xAF, 22 },  { 0xB0, 22 },  { 0xB1, 22 },
 { 0x53, 20 },  { 0x90, 21 },  { 0xB2, 22 },  { 0x91, 21 },
 { 0xB3, 22 },  { 0xB4, 22 },  { 0x54, 20 },  { 0xB5, 22 },
@@ -231,7 +231,7 @@ const uint16_t ff_svq1_inter_mean_vlc[512][2] = {
 { 0x87, 21 },  { 0x4F, 20 },  { 0x35, 19 },  { 0x4E, 20 },
 { 0x33, 19 },  { 0x32, 19 },  { 0x4D, 20 },  { 0x4C, 20 },
 { 0x83, 22 },  { 0x4B, 20 },  { 0x81, 22 },  { 0x80, 22 },
-{ 0x8E, 21 },  { 0x7E, 22 },  { 0x7D, 22 },  { 0x84, 21 },
+{ 0x7F, 22 },  { 0x7E, 22 },  { 0x7D, 22 },  { 0x84, 21 },
 { 0x8D, 21 },  { 0x7A, 22 },  { 0x79, 22 },  { 0x4A, 20 },
 { 0x77, 22 },  { 0x76, 22 },  { 0x89, 21 },  { 0x74, 22 },
 { 0x73, 22 },  { 0x72, 22 },  { 0x49, 20 },  { 0x70, 22 },
diff --git a/tests/ref/fate/svq1 b/tests/ref/fate/svq1
index d53e2952e4..0b0948cce6 100644
--- a/tests/ref/fate/svq1
+++ b/tests/ref/fate/svq1
@@ -24,19 +24,19 @@
 0, 18, 18,1,21600, 0x8d5b2ad0
 0, 19, 19,1,21600, 0xe67128e6
 0, 20, 20,1,21600, 0xb7bf613e
-0, 21, 21,1,21600, 0xefd0f51b
-0, 22, 22,1,21600, 0x31b7da59
+0, 21, 21,1,21600, 0xf697fa3e
+0, 22, 22,1,21600, 0x5b6ede88
 0, 23, 23,1,21600, 0x7a84a8f7
 0, 24, 24,1,21600, 0x0351ad27
-0, 25, 25,1,21600, 0xed6f434d
-0, 26, 26,1,21600, 0x0e771127
-0, 27, 27,1,21600, 0x37bf0b95
-0, 28, 28,1,21600, 0x30e10a77
-0, 29, 29,1,21600, 0x1a48288a
-0, 30, 30,1,21600, 0xf43c6770
-0, 31, 31,1,21600, 0x3c43ae68
-0, 32, 32,1,21600, 0x04dc0949
-0, 33, 33,1,21600, 0x7920758d
+0, 25, 25,1,21600, 0x57b547c2
+0, 26, 26,1,21600, 0xbb9e1558
+0, 27, 27,1,21600, 0xcb470f6b
+0, 28, 28,1,21600, 0xeb100de0
+0, 29, 29,1,21600, 0x089c2bf0
+0, 30, 30,1,21600, 0xe27b6a42
+0, 31, 31,1,21600, 0xbfe2b11b
+0, 32, 32,1,21600, 0xd9ca0bb5
+0, 33, 33,1,21600, 0x12fe783c
 0, 34, 34,1,21600, 0x6c12bab5
 0, 35, 35,1,21600, 0x1ac23706
 0, 36, 36,1,21600, 0x7a95cb5f
-- 
2.35.1

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


signature.asc
Description: PGP signature
___
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] [PATCHv3 2/4] avcodec/svq1enc: output ident string in extradata field

2022-10-25 Thread Peter Ross
This will enable the acurate identification of FFmpeg produced
SVQ1 streams, should there be new bugs found in the encoder.
---
 libavcodec/svq1enc.c  | 16 +++-
 tests/ref/vsynth/vsynth1-svq1 |  4 ++--
 tests/ref/vsynth/vsynth2-svq1 |  4 ++--
 tests/ref/vsynth/vsynth3-svq1 |  4 ++--
 tests/ref/vsynth/vsynth_lena-svq1 |  4 ++--
 5 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 9bd5a04368..73c85bff6b 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -41,6 +41,7 @@
 #include "svq1.h"
 #include "svq1encdsp.h"
 #include "svq1enc_cb.h"
+#include "version.h"
 
 #include "libavutil/avassert.h"
 #include "libavutil/frame.h"
@@ -567,6 +568,19 @@ static av_cold int svq1_encode_end(AVCodecContext *avctx)
 return 0;
 }
 
+static av_cold int write_ident(AVCodecContext *avctx, const char *ident)
+{
+int size = strlen(ident);
+avctx->extradata = av_malloc(size + 8);
+if (!avctx->extradata)
+return AVERROR(ENOMEM);
+AV_WB32(avctx->extradata, size + 8);
+AV_WL32(avctx->extradata + 4, MKTAG('S', 'V', 'Q', '1'));
+memcpy(avctx->extradata + 8, ident, size);
+avctx->extradata_size = size + 8;
+return 0;
+}
+
 static av_cold int svq1_encode_init(AVCodecContext *avctx)
 {
 SVQ1EncContext *const s = avctx->priv_data;
@@ -628,7 +642,7 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
 
 ff_h263_encode_init(>m); // mv_penalty
 
-return 0;
+return write_ident(avctx, s->avctx->flags & AV_CODEC_FLAG_BITEXACT ? 
"Lavc" : LIBAVCODEC_IDENT);
 }
 
 static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
diff --git a/tests/ref/vsynth/vsynth1-svq1 b/tests/ref/vsynth/vsynth1-svq1
index e91ef46f17..6a517f6b7b 100644
--- a/tests/ref/vsynth/vsynth1-svq1
+++ b/tests/ref/vsynth/vsynth1-svq1
@@ -1,4 +1,4 @@
-78cdca850b19faf3aac0b0682207451e *tests/data/fate/vsynth1-svq1.mov
-1333541 tests/data/fate/vsynth1-svq1.mov
+89b1ec4d7bbee1ed2710c8cc8c1e269d *tests/data/fate/vsynth1-svq1.mov
+1333561 tests/data/fate/vsynth1-svq1.mov
 0b9ee47ee4bf735fe3697daad64fc409 *tests/data/fate/vsynth1-svq1.out.rawvideo
 stddev:9.57 PSNR: 28.50 MAXDIFF:  210 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-svq1 b/tests/ref/vsynth/vsynth2-svq1
index b50ba45e20..01d78bd279 100644
--- a/tests/ref/vsynth/vsynth2-svq1
+++ b/tests/ref/vsynth/vsynth2-svq1
@@ -1,4 +1,4 @@
-42578021105a2f526179c5601e635312 *tests/data/fate/vsynth2-svq1.mov
-940337 tests/data/fate/vsynth2-svq1.mov
+14f355a06d475dcf6a90ac6ab3ae2970 *tests/data/fate/vsynth2-svq1.mov
+940357 tests/data/fate/vsynth2-svq1.mov
 ba8f6b721a8e19fe8a6ef92a8cff7479 *tests/data/fate/vsynth2-svq1.out.rawvideo
 stddev:3.71 PSNR: 36.72 MAXDIFF:  210 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth3-svq1 b/tests/ref/vsynth/vsynth3-svq1
index ba1d3d5082..05fd497336 100644
--- a/tests/ref/vsynth/vsynth3-svq1
+++ b/tests/ref/vsynth/vsynth3-svq1
@@ -1,4 +1,4 @@
-03805cb764c00c2162b2bed24b7f34bd *tests/data/fate/vsynth3-svq1.mov
-40757 tests/data/fate/vsynth3-svq1.mov
+969dcdd69774b9c42dcf81e8dd393364 *tests/data/fate/vsynth3-svq1.mov
+40777 tests/data/fate/vsynth3-svq1.mov
 a99efde992a2e3efcc085ecc6920a1e3 *tests/data/fate/vsynth3-svq1.out.rawvideo
 stddev:   14.49 PSNR: 24.91 MAXDIFF:  183 bytes:86700/86700
diff --git a/tests/ref/vsynth/vsynth_lena-svq1 
b/tests/ref/vsynth/vsynth_lena-svq1
index 94f260865a..0889eba5bb 100644
--- a/tests/ref/vsynth/vsynth_lena-svq1
+++ b/tests/ref/vsynth/vsynth_lena-svq1
@@ -1,4 +1,4 @@
-7534b2c6b7fc7201f193e9b4514cdb90 *tests/data/fate/vsynth_lena-svq1.mov
-766817 tests/data/fate/vsynth_lena-svq1.mov
+8890d9ca13934391b6891ac5f67897c6 *tests/data/fate/vsynth_lena-svq1.mov
+766837 tests/data/fate/vsynth_lena-svq1.mov
 85261558fa744ef468fe77dbe4d91d8d *tests/data/fate/vsynth_lena-svq1.out.rawvideo
 stddev:3.23 PSNR: 37.93 MAXDIFF:   61 bytes:  7603200/  7603200
-- 
2.35.1

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


signature.asc
Description: PGP signature
___
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] [PATCHv3 1/4] avcodec/svq1enc: do not use ambiguous interframe mean symbols

2022-10-25 Thread Peter Ross
Don't emit interframe mean symbols -128 and 128.
---

v3 patch set changes:
- reordered patchset
- add stds fields around extradata codec ident
- use Lavc codec ident when operating in bitexact mode

 libavcodec/svq1enc.c  |  5 +
 tests/ref/seek/vsynth_lena-svq1   | 28 ++--
 tests/ref/vsynth/vsynth1-svq1 |  8 
 tests/ref/vsynth/vsynth2-svq1 |  6 +++---
 tests/ref/vsynth/vsynth3-svq1 |  6 +++---
 tests/ref/vsynth/vsynth_lena-svq1 |  6 +++---
 6 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 75adbe7ea0..9bd5a04368 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -234,6 +234,11 @@ static int encode_block(SVQ1EncContext *s, uint8_t *src, 
uint8_t *ref,
 }
 }
 
+if (best_mean == -128)
+best_mean = -127;
+else if (best_mean == 128)
+best_mean = 127;
+
 split = 0;
 if (best_score > threshold && level) {
 int score  = 0;
diff --git a/tests/ref/seek/vsynth_lena-svq1 b/tests/ref/seek/vsynth_lena-svq1
index 33fe33e916..36c0fb7f4e 100644
--- a/tests/ref/seek/vsynth_lena-svq1
+++ b/tests/ref/seek/vsynth_lena-svq1
@@ -2,49 +2,49 @@ ret: 0 st: 0 flags:1 dts: 0.00 pts: 0.00 pos: 
36 size: 22300
 ret: 0 st:-1 flags:0  ts:-1.00
 ret: 0 st: 0 flags:1 dts: 0.00 pts: 0.00 pos: 36 size: 
22300
 ret: 0 st:-1 flags:1  ts: 1.894167
-ret: 0 st: 0 flags:1 dts: 1.44 pts: 1.44 pos: 517568 size: 
25636
+ret: 0 st: 0 flags:1 dts: 1.44 pts: 1.44 pos: 517672 size: 
25636
 ret: 0 st: 0 flags:0  ts: 0.788359
-ret: 0 st: 0 flags:1 dts: 0.96 pts: 0.96 pos: 326556 size: 
23552
+ret: 0 st: 0 flags:1 dts: 0.96 pts: 0.96 pos: 326616 size: 
23552
 ret: 0 st: 0 flags:1  ts:-0.317500
 ret: 0 st: 0 flags:1 dts: 0.00 pts: 0.00 pos: 36 size: 
22300
 ret:-1 st:-1 flags:0  ts: 2.576668
 ret: 0 st:-1 flags:1  ts: 1.470835
-ret: 0 st: 0 flags:1 dts: 1.44 pts: 1.44 pos: 517568 size: 
25636
+ret: 0 st: 0 flags:1 dts: 1.44 pts: 1.44 pos: 517672 size: 
25636
 ret: 0 st: 0 flags:0  ts: 0.365000
-ret: 0 st: 0 flags:1 dts: 0.48 pts: 0.48 pos: 157040 size: 
21896
+ret: 0 st: 0 flags:1 dts: 0.48 pts: 0.48 pos: 157232 size: 
21896
 ret: 0 st: 0 flags:1  ts:-0.740859
 ret: 0 st: 0 flags:1 dts: 0.00 pts: 0.00 pos: 36 size: 
22300
 ret:-1 st:-1 flags:0  ts: 2.153336
 ret: 0 st:-1 flags:1  ts: 1.047503
-ret: 0 st: 0 flags:1 dts: 0.96 pts: 0.96 pos: 326556 size: 
23552
+ret: 0 st: 0 flags:1 dts: 0.96 pts: 0.96 pos: 326616 size: 
23552
 ret: 0 st: 0 flags:0  ts:-0.058359
 ret: 0 st: 0 flags:1 dts: 0.00 pts: 0.00 pos: 36 size: 
22300
 ret: 0 st: 0 flags:1  ts: 2.835859
-ret: 0 st: 0 flags:1 dts: 1.92 pts: 1.92 pos: 722804 size: 
25888
+ret: 0 st: 0 flags:1 dts: 1.92 pts: 1.92 pos: 722884 size: 
25888
 ret: 0 st:-1 flags:0  ts: 1.730004
-ret: 0 st: 0 flags:1 dts: 1.92 pts: 1.92 pos: 722804 size: 
25888
+ret: 0 st: 0 flags:1 dts: 1.92 pts: 1.92 pos: 722884 size: 
25888
 ret: 0 st:-1 flags:1  ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.48 pts: 0.48 pos: 157040 size: 
21896
+ret: 0 st: 0 flags:1 dts: 0.48 pts: 0.48 pos: 157232 size: 
21896
 ret: 0 st: 0 flags:0  ts:-0.481641
 ret: 0 st: 0 flags:1 dts: 0.00 pts: 0.00 pos: 36 size: 
22300
 ret: 0 st: 0 flags:1  ts: 2.412500
-ret: 0 st: 0 flags:1 dts: 1.92 pts: 1.92 pos: 722804 size: 
25888
+ret: 0 st: 0 flags:1 dts: 1.92 pts: 1.92 pos: 722884 size: 
25888
 ret: 0 st:-1 flags:0  ts: 1.306672
-ret: 0 st: 0 flags:1 dts: 1.44 pts: 1.44 pos: 517568 size: 
25636
+ret: 0 st: 0 flags:1 dts: 1.44 pts: 1.44 pos: 517672 size: 
25636
 ret: 0 st:-1 flags:1  ts: 0.200839
 ret: 0 st: 0 flags:1 dts: 0.00 pts: 0.00 pos: 36 size: 
22300
 ret: 0 st: 0 flags:0  ts:-0.905000
 ret: 0 st: 0 flags:1 dts: 0.00 pts: 0.00 pos: 36 size: 
22300
 ret: 0 st: 0 flags:1  ts: 1.989141
-ret: 0 st: 0 flags:1 dts: 1.92 pts: 1.92 pos: 722804 size: 
25888
+ret: 0 st: 0 flags:1 dts: 1.92 pts: 1.92 pos: 722884 size: 
25888
 ret: 0 st:-1 flags:0  ts: 0.883340
-ret: 0 st: 0 flags:1 dts: 0.96 pts: 0.96 pos: 326556 size: 
23552
+ret: 0 st: 0 flags:1 dts: 0.96 pts: 0.96 pos: 326616 size: 
23552
 ret: 0 st:-1 flags:1  ts:-0.222493
 ret: 0 st: 0 flags:1 dts: 0.00 pts: 0.00 pos: 36 size: 
22300
 ret:-1 st: 0 flags:0  ts: 2.671641
 ret: 0 st: 0 

[FFmpeg-devel] [PATCH v9 19/25] avfilter/subscale: Add filter for scaling and/or re-arranging graphical subtitles

2022-10-25 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 configure |   1 +
 doc/filters.texi  | 164 +++
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/sf_subscale.c | 884 ++
 5 files changed, 1051 insertions(+)
 create mode 100644 libavfilter/sf_subscale.c

diff --git a/configure b/configure
index 815e8e067f..8968851571 100755
--- a/configure
+++ b/configure
@@ -3755,6 +3755,7 @@ sr_filter_deps="avformat swscale"
 sr_filter_select="dnn"
 stereo3d_filter_deps="gpl"
 splitcc_filter_deps="avcodec"
+subscale_filter_deps="swscale avcodec"
 subtitles_filter_deps="avformat avcodec libass"
 super2xsai_filter_deps="gpl"
 pixfmts_super2xsai_test_deps="super2xsai_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index 6b05864706..5b058e8f3f 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -27954,6 +27954,170 @@ Set the rendering margin in pixels.
 For rendering, alway use the latest event only, which is covering the given 
point in time.
 @end table
 
+@section subscale
+
+Provides high-quality scaling and rearranging functionality for graphical 
subtitles.
+
+The subscale filter provides multiple approaches for manipulating
+the size and position of graphical subtitle rectangles wich can
+be combined or used separately.
+Scaling is performed by converting the palettized subtitle bitmaps
+to RGBA and re-quantization to palette colors afterwards via elbg algorithm.
+
+The two major operations are 'scale' and 're-arrange' with the
+latter being separated as 'arrange_h' and 'arrange_v'.
+
+
+Inputs:
+- 0: Subtitles [bitmap]
+
+Outputs:
+- 0: Subtitles [bitmap]
+
+It accepts the following parameters:
+
+@table @option
+
+@item w, width
+Set the width of the output.
+Width and height in case of graphical subtitles are just indicating
+a virtual size for which the output (consisting of 0-n bitmap rectangles)
+is intended to be displayed on.
+
+@item h, height
+Set the height of the output.
+
+@item margin_h
+Sets a horizontal margin to be preserverved when using any
+of the arrange modes.
+
+@item margin_v
+Sets a vertical margin to be preserverved when using any
+of the arrange modes.
+
+@item force_original_aspect_ratio
+Enable decreasing or increasing output video width or height if necessary to
+keep the original aspect ratio. Possible values:
+
+@table @samp
+@item disable
+Scale the video as specified and disable this feature.
+
+@item decrease
+The output video dimensions will automatically be decreased if needed.
+
+@item increase
+The output video dimensions will automatically be increased if needed.
+
+@end table
+
+
+@item scale_mode
+Specifies how subtitle bitmaps should be scaled.
+The scale factor is determined by the the factor between input
+and output size.
+
+@table @samp
+@item none
+Do not apply any common scaling.
+
+@item uniform
+Uniformly scale all subtitle bitmaps including their positions.
+
+@item uniform_no_reposition
+Uniformly scale all subtitle bitmaps without changing positions.
+
+@end table
+
+
+@item arrange_h
+Specifies how subtitle bitmaps should be arranged horizontally.
+
+@item arrange_v
+Specifies how subtitle bitmaps should be arranged vertically.
+
+
+@table @samp
+@item none
+Do not rearrange subtitle bitmaps.
+
+@item margin_no_scale
+Move subtitle bitmaps to be positioned inside the specified
+margin (margin_h or margin_v) when possible and without scaling.
+
+@item margin_and_scale
+Move subtitle bitmaps to be positioned inside the specified
+margin (margin_h or margin_v) and scale in case it doesn't fit.
+
+@item snapalign_no_scale
+Categorize subtitle bitmap positions as one of left/center/right
+or top/bottom/middle based on original positioning and apply
+these alignments for the target positioning.
+No scaling will be applied.
+
+@item snapalign_and_scale
+Categorize subtitle bitmap positions as one of left/center/right
+or top/bottom/middle based on original positioning and apply
+these alignments for the target positioning.
+Bitmaps that do not fit inside the margins borders are
+scaled to fit.
+@end table
+
+@item eval
+Set evaluation mode for the expressions (@option{width}, @option{height}).
+
+It accepts the following values:
+@table @samp
+@item init
+Evaluate expressions only once during the filter initialization.
+
+@item frame
+Evaluate expressions for each incoming frame. This is way slower than the
+@samp{init} mode since it requires all the scalers to be re-computed, but it
+allows advanced dynamic expressions.
+@end table
+
+Default value is @samp{init}.
+
+
+@item num_colors
+Set the number of palette colors for output images.
+Choose the maximum (256) when further processing is done (e.g.
+overlaying on a video).
+When subtitles will be encoded as bitmap subtitles (e.g. dvbsub),
+a smaller number of palette colors (e.g. 4-16) might need to be used, depending
+on the target format and codec.
+
+@item bitmap_width_align
+@item bitmap_height_align
+Make 

[FFmpeg-devel] [PATCH v9 25/25] avcodec/dvbsubdec: Fix conditions for fallback to default resolution

2022-10-25 Thread softworkz
From: softworkz 

The previous code expected a segment of type CLUT definition to exist
in order to accept a set of segments to be complete.
This was an incorrect assumption as the presence of a CLUT segment
is not mandatory.
(version 1.6.1 of the spec is probably a bit more clear about this
than earlier versions: https://www.etsi.org/deliver/etsi_en/
300700_300799/300743/01.06.01_20/en_300743v010601a.pdf)

The flawed condition prevented proper fallback to using the default
resolution for the decoding context.

Signed-off-by: softworkz 
---
 libavcodec/dvbsubdec.c | 51 +-
 1 file changed, 30 insertions(+), 21 deletions(-)

diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index c864ba3fb6..4df350574d 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -34,7 +34,7 @@
 #define DVBSUB_CLUT_SEGMENT 0x12
 #define DVBSUB_OBJECT_SEGMENT   0x13
 #define DVBSUB_DISPLAYDEFINITION_SEGMENT 0x14
-#define DVBSUB_DISPLAY_SEGMENT  0x80
+#define DVBSUB_END_DISPLAY_SEGMENT  0x80
 
 #define cm (ff_crop_tab + MAX_NEG_CROP)
 
@@ -1450,8 +1450,12 @@ static int dvbsub_decode(AVCodecContext *avctx, 
AVSubtitle *sub,
 int segment_length;
 int i;
 int ret = 0;
-int got_segment = 0;
-int got_dds = 0;
+//int got_segment = 0;
+int got_page = 0;
+int got_region = 0;
+int got_object = 0;
+int got_end_display = 0;
+int got_displaydef = 0;
 
 ff_dlog(avctx, "DVB sub packet:\n");
 
@@ -1496,34 +1500,28 @@ static int dvbsub_decode(AVCodecContext *avctx, 
AVSubtitle *sub,
 switch (segment_type) {
 case DVBSUB_PAGE_SEGMENT:
 ret = dvbsub_parse_page_segment(avctx, p, segment_length, sub, 
got_sub_ptr);
-got_segment |= 1;
+got_page = 1;
 break;
 case DVBSUB_REGION_SEGMENT:
 ret = dvbsub_parse_region_segment(avctx, p, segment_length);
-got_segment |= 2;
+got_region = 1;
 break;
 case DVBSUB_CLUT_SEGMENT:
 ret = dvbsub_parse_clut_segment(avctx, p, segment_length);
 if (ret < 0) goto end;
-got_segment |= 4;
 break;
 case DVBSUB_OBJECT_SEGMENT:
 ret = dvbsub_parse_object_segment(avctx, p, segment_length);
-got_segment |= 8;
+got_object = 1;
 break;
 case DVBSUB_DISPLAYDEFINITION_SEGMENT:
 ret = dvbsub_parse_display_definition_segment(avctx, p,
   segment_length);
-got_dds = 1;
+got_displaydef = 1;
 break;
-case DVBSUB_DISPLAY_SEGMENT:
+case DVBSUB_END_DISPLAY_SEGMENT:
 ret = dvbsub_display_end_segment(avctx, p, segment_length, 
sub, got_sub_ptr);
-if (got_segment == 15 && !got_dds && !avctx->width && 
!avctx->height) {
-// Default from ETSI EN 300 743 V1.3.1 (7.2.1)
-avctx->width  = 720;
-avctx->height = 576;
-}
-got_segment |= 16;
+got_end_display = 1;
 break;
 default:
 ff_dlog(avctx, "Subtitling segment type 0x%x, page id %d, 
length %d\n",
@@ -1536,13 +1534,24 @@ static int dvbsub_decode(AVCodecContext *avctx, 
AVSubtitle *sub,
 
 p += segment_length;
 }
-// Some streams do not send a display segment but if we have all the other
-// segments then we need no further data.
-if (got_segment == 15) {
-av_log(avctx, AV_LOG_DEBUG, "Missing display_end_segment, 
emulating\n");
-dvbsub_display_end_segment(avctx, p, 0, sub, got_sub_ptr);
-}
 
+// Even though not mandated by the spec, we're imposing a minimum 
requirement
+// for a useful packet to have at least one page, region and object 
segment.
+if (got_page && got_region && got_object && got_end_display) {
+
+if (!got_displaydef && !avctx->width && !avctx->height) {
+// Default from ETSI EN 300 743 V1.3.1 (7.2.1)
+avctx->width  = 720;
+avctx->height = 576;
+}
+
+// Some streams do not send an end-of-display segment but if we have 
all the other
+// segments then we need no further data.
+if (!got_end_display) {
+av_log(avctx, AV_LOG_DEBUG, "Missing display_end_segment, 
emulating\n");
+dvbsub_display_end_segment(avctx, p, 0, sub, got_sub_ptr);
+}
+}
 end:
 if (ret < 0) {
 return ret;
-- 
ffmpeg-codebot
___
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 v9 23/25] avcodec/subtitles: Migrate subtitle encoders to frame-based API

2022-10-25 Thread softworkz
From: softworkz 

and provide a compatibility shim for the legacy api

Signed-off-by: softworkz 
---
 libavcodec/assenc.c | 189 ++--
 libavcodec/avcodec.h|   5 +-
 libavcodec/codec_internal.h |  12 ---
 libavcodec/dvbsubenc.c  |  96 ++
 libavcodec/dvdsubenc.c  | 103 
 libavcodec/encode.c |  61 +++-
 libavcodec/movtextenc.c | 114 --
 libavcodec/srtenc.c | 108 ++---
 libavcodec/tests/avcodec.c  |   5 +-
 libavcodec/ttmlenc.c| 101 ++-
 libavcodec/utils.c  |   1 -
 libavcodec/webvttenc.c  |  86 +++-
 libavcodec/xsubenc.c|  88 ++---
 13 files changed, 689 insertions(+), 280 deletions(-)

diff --git a/libavcodec/assenc.c b/libavcodec/assenc.c
index 9bbcdd9054..45fd5a217f 100644
--- a/libavcodec/assenc.c
+++ b/libavcodec/assenc.c
@@ -25,67 +25,192 @@
 
 #include "avcodec.h"
 #include "codec_internal.h"
+#include "encode.h"
 #include "libavutil/ass_internal.h"
 #include "libavutil/avstring.h"
 #include "libavutil/internal.h"
 #include "libavutil/mem.h"
 
+typedef struct {
+AVCodecContext *avctx;
+AVFrame* current_frame;
+int have_frame;
+int current_area;
+} AssEncContext;
+
+static void check_write_header(AVCodecContext* avctx, const AVFrame* frame)
+{
+if (avctx->extradata_size)
+return;
+
+if (frame->subtitle_header && frame->subtitle_header->size > 0) {
+const char* subtitle_header = (char*)frame->subtitle_header->data;
+avctx->extradata_size = strlen(subtitle_header);
+avctx->extradata = av_mallocz(frame->subtitle_header->size + 1);
+memcpy(avctx->extradata, subtitle_header, avctx->extradata_size);
+avctx->extradata[avctx->extradata_size] = 0;
+}
+
+if (!avctx->extradata_size) {
+const char* subtitle_header = 
avpriv_ass_get_subtitle_header_default(0);
+if (!subtitle_header)
+return;
+
+avctx->extradata_size = strlen(subtitle_header);
+avctx->extradata = av_mallocz(avctx->extradata_size + 1);
+memcpy(avctx->extradata, subtitle_header, avctx->extradata_size);
+avctx->extradata[avctx->extradata_size] = 0;
+av_freep(_header);
+}
+}
+
 static av_cold int ass_encode_init(AVCodecContext *avctx)
 {
-avctx->extradata = av_malloc(avctx->subtitle_header_size + 1);
-if (!avctx->extradata)
-return AVERROR(ENOMEM);
-memcpy(avctx->extradata, avctx->subtitle_header, 
avctx->subtitle_header_size);
-avctx->extradata_size = avctx->subtitle_header_size;
-avctx->extradata[avctx->extradata_size] = 0;
+AssEncContext *s = avctx->priv_data;
+
+if (avctx->subtitle_header_size) {
+avctx->extradata = av_malloc(avctx->subtitle_header_size + 1);
+if (!avctx->extradata)
+return AVERROR(ENOMEM);
+memcpy(avctx->extradata, avctx->subtitle_header, 
avctx->subtitle_header_size);
+avctx->extradata_size   = avctx->subtitle_header_size;
+avctx->extradata[avctx->extradata_size] = 0;
+}
+
+s->current_frame = av_frame_alloc();
+return 0;
+}
+
+static av_cold int ass_encode_close(AVCodecContext *avctx)
+{
+AssEncContext *s = avctx->priv_data;
+av_frame_free(>current_frame);
 return 0;
 }
 
-static int ass_encode_frame(AVCodecContext *avctx,
-unsigned char *buf, int bufsize,
-const AVSubtitle *sub)
+static int ass_encode_frame(AVCodecContext* avctx, AVPacket* avpkt,
+const AVFrame* frame, int* got_packet)
+{
+int ret;
+size_t req_len = 0, total_len = 0;
+
+check_write_header(avctx, frame);
+
+for (unsigned i = 0; i < frame->num_subtitle_areas; i++) {
+const char *ass = frame->subtitle_areas[i]->ass;
+
+if (frame->subtitle_areas[i]->type != AV_SUBTITLE_FMT_ASS) {
+av_log(avctx, AV_LOG_ERROR, "Only AV_SUBTITLE_FMT_ASS type 
supported.\n");
+return AVERROR(EINVAL);
+}
+
+if (ass)
+req_len += strlen(ass);
+}
+
+ret = ff_get_encode_buffer(avctx, avpkt, req_len + 1, 0);
+if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
+return ret;
+}
+
+for (unsigned i = 0; i < frame->num_subtitle_areas; i++) {
+const char *ass = frame->subtitle_areas[i]->ass;
+
+if (ass) {
+size_t len = av_strlcpy((char *)avpkt->data + total_len, ass, 
avpkt->size - total_len);
+total_len += len;
+}
+}
+
+avpkt->size = total_len;
+*got_packet = total_len > 0;
+
+return 0;
+}
+
+static int ass_receive_packet(AVCodecContext *avctx, AVPacket 

[FFmpeg-devel] [PATCH v9 22/25] avfilter/snull, strim: Add snull and strim filters

2022-10-25 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 configure|  2 +-
 libavfilter/Makefile |  2 ++
 libavfilter/allfilters.c |  2 ++
 libavfilter/sf_snull.c   | 61 
 libavfilter/trim.c   | 60 ++-
 5 files changed, 125 insertions(+), 2 deletions(-)
 create mode 100644 libavfilter/sf_snull.c

diff --git a/configure b/configure
index 3703aa216b..3d830be10f 100755
--- a/configure
+++ b/configure
@@ -3842,7 +3842,7 @@ avutil_extralibs="d3d11va_extralibs nanosleep_extralibs 
pthreads_extralibs vaapi
 # programs
 ffmpeg_deps="avcodec avfilter avformat threads"
 ffmpeg_select="aformat_filter anull_filter atrim_filter format_filter
-   hflip_filter null_filter
+   snull_filter strim_filter hflip_filter null_filter
transpose_filter trim_filter vflip_filter"
 ffmpeg_suggest="ole32 psapi shell32"
 ffplay_deps="avcodec avformat swscale swresample sdl2"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index c6dfa517e8..4e5d33a43f 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -591,7 +591,9 @@ OBJS-$(CONFIG_NULLSINK_FILTER)   += 
vsink_nullsink.o
 # subtitle filters
 OBJS-$(CONFIG_CENSOR_FILTER) += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)   += sf_textmod.o
+OBJS-$(CONFIG_SNULL_FILTER)  += sf_snull.o
 OBJS-$(CONFIG_SPLITCC_FILTER)+= sf_splitcc.o
+OBJS-$(CONFIG_STRIM_FILTER)  += trim.o
 OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 OBJS-$(CONFIG_SUBFEED_FILTER)+= sf_subfeed.o
 OBJS-$(CONFIG_SUBSCALE_FILTER)   += sf_subscale.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 8779141aad..9c84347659 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -579,7 +579,9 @@ extern const AVFilter ff_avsrc_movie;
 extern const AVFilter ff_sf_censor;
 extern const AVFilter ff_sf_graphicsub2text;
 extern const AVFilter ff_sf_showspeaker;
+extern const AVFilter ff_sf_snull;
 extern const AVFilter ff_sf_splitcc;
+extern const AVFilter ff_sf_strim;
 extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_subfeed;
 extern const AVFilter ff_sf_subscale;
diff --git a/libavfilter/sf_snull.c b/libavfilter/sf_snull.c
new file mode 100644
index 00..815436cfff
--- /dev/null
+++ b/libavfilter/sf_snull.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * null subtitle filter
+ */
+
+#include "avfilter.h"
+#include "internal.h"
+#include "libavutil/internal.h"
+
+static int sconfig_output(AVFilterLink *outlink)
+{
+AVFilterContext *ctx = outlink->src;
+AVFilterLink *inlink = ctx->inputs[0];
+
+outlink->format = inlink->format;
+
+return 0;
+}
+
+static const AVFilterPad avfilter_sf_snull_inputs[] = {
+{
+.name = "default",
+.type = AVMEDIA_TYPE_SUBTITLE,
+},
+};
+
+static const AVFilterPad avfilter_sf_snull_outputs[] = {
+{
+.name = "default",
+.type = AVMEDIA_TYPE_SUBTITLE,
+.config_props = sconfig_output,
+},
+};
+
+const AVFilter ff_sf_snull = {
+.name  = "snull",
+.description   = NULL_IF_CONFIG_SMALL("Pass the source unchanged to the 
output."),
+.flags = AVFILTER_FLAG_METADATA_ONLY,
+FILTER_INPUTS(avfilter_sf_snull_inputs),
+FILTER_OUTPUTS(avfilter_sf_snull_outputs),
+};
diff --git a/libavfilter/trim.c b/libavfilter/trim.c
index ee6e821cd2..a25366497b 100644
--- a/libavfilter/trim.c
+++ b/libavfilter/trim.c
@@ -83,7 +83,7 @@ static int config_input(AVFilterLink *inlink)
 {
 AVFilterContext *ctx = inlink->dst;
 TrimContext   *s = ctx->priv;
-AVRational tb = (inlink->type == AVMEDIA_TYPE_VIDEO) ?
+AVRational tb = (inlink->type != AVMEDIA_TYPE_AUDIO) ?
  inlink->time_base : (AVRational){ 1, inlink->sample_rate 
};
 
 if (s->start_time != INT64_MAX) {
@@ -369,3 +369,61 @@ const AVFilter ff_af_atrim = {
 FILTER_OUTPUTS(atrim_outputs),
 };
 #endif // CONFIG_ATRIM_FILTER
+
+#if CONFIG_STRIM_FILTER
+
+static int sconfig_output(AVFilterLink *outlink)

[FFmpeg-devel] [PATCH v9 21/25] avfilter/text2graphicsub: Added text2graphicsub subtitle filter

2022-10-25 Thread softworkz
From: softworkz 

Added a text2graphicsub subtitle filter which converts text-based
subtitle tracks to bitmap-based subtitle tracks. The filter uses libass
to render the subtitles.
It takes as parameters an output height and width, as well as a number
of colors in the output palette as well as sources of fonts. All its
arguments are optional.

Reviewed-by: softworkz 
Signed-off-by: softworkz 
Signed-off-by: tcoza 
---
 configure|   1 +
 doc/filters.texi |  51 +++
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_text2graphicsub.c | 634 +++
 5 files changed, 688 insertions(+)
 create mode 100644 libavfilter/sf_text2graphicsub.c

diff --git a/configure b/configure
index 8968851571..3703aa216b 100755
--- a/configure
+++ b/configure
@@ -3759,6 +3759,7 @@ subscale_filter_deps="swscale avcodec"
 subtitles_filter_deps="avformat avcodec libass"
 super2xsai_filter_deps="gpl"
 pixfmts_super2xsai_test_deps="super2xsai_filter"
+text2graphicsub_filter_deps="avformat avcodec libass"
 textsub2video_filter_deps="avcodec libass"
 tinterlace_filter_deps="gpl"
 tinterlace_merge_test_deps="tinterlace_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index 5b058e8f3f..ebd398386b 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -28118,6 +28118,57 @@ ffmpeg -y -y -loglevel verbose -i 
"https://streams.videolan.org/samples/sub/larg
 @end example
 @end itemize
 
+@section text2graphicsub
+
+Converts a text-based subtitle track to a bitmap-based subtitle track.
+
+The text2graphicsub filter uses libass to render all the subtitle
+frames in a text-based subtitle track (such as srt or ass) to allow
+its encoding with a bitmap-based subtitle encoder (such as dvd_subtitle).
+
+Inputs:
+- 0: Subtitles [text]
+
+Outputs:
+- 0: Subtitles [bitmap]
+
+It accepts the following parameters:
+
+@table @option
+
+@item s, size
+Set the size of the output. Default from input track.
+
+@item n, num_colors
+Set the number of palette colors for output images,
+Range [2,256]. Default 16.
+
+@item f, filename
+Set the media container from which to extract fonts required
+for rendering the subtitles, usually the same as the input
+track's media container. Can be omitted.
+
+@item fd, fontsdir
+Set the directory from which to load fonts required for
+rendering the subtitles. Can be used with 'fonts'. Can be omitted.
+
+@item ss, stripstyles
+Remove certain styles from an ass track which do not render well.
+Stripped styles include blurs, fades, and other animations.
+Default yes.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Convert a video's text-based subtitle track to a dvd_subtitle subtitle track.
+@example
+ffmpeg -i video.mkv -map 0:v -map 0:a -filter_complex 
[0:s]text2graphicsub=f=video.mkv[dvd_sub] -map [dvd_sub] -c copy -c:s 
dvd_subtitle output.mkv
+@end example
+@end itemize
+
 @c man end SUBTITLE FILTERS
 
 @chapter Multimedia Filters
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 4a8badeddf..c6dfa517e8 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -595,6 +595,7 @@ OBJS-$(CONFIG_SPLITCC_FILTER)+= sf_splitcc.o
 OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 OBJS-$(CONFIG_SUBFEED_FILTER)+= sf_subfeed.o
 OBJS-$(CONFIG_SUBSCALE_FILTER)   += sf_subscale.o
+OBJS-$(CONFIG_TEXT2GRAPHICSUB_FILTER)+= sf_text2graphicsub.o
 OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
 
 # multimedia filters
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index fe5f815731..8779141aad 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -583,6 +583,7 @@ extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_subfeed;
 extern const AVFilter ff_sf_subscale;
+extern const AVFilter ff_sf_text2graphicsub;
 extern const AVFilter ff_sf_textmod;
 
 /* those filters are part of public or internal API,
diff --git a/libavfilter/sf_text2graphicsub.c b/libavfilter/sf_text2graphicsub.c
new file mode 100644
index 00..1fd7a76c53
--- /dev/null
+++ b/libavfilter/sf_text2graphicsub.c
@@ -0,0 +1,634 @@
+/*
+ * Copyright (c) 2021 tcoza
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, 

[FFmpeg-devel] [PATCH v9 20/25] avfilter/subfeed: add subtitle feed filter

2022-10-25 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_subfeed.c | 412 +++
 3 files changed, 414 insertions(+)
 create mode 100644 libavfilter/sf_subfeed.c

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 9dbac707d1..4a8badeddf 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -593,6 +593,7 @@ OBJS-$(CONFIG_CENSOR_FILTER) += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)   += sf_textmod.o
 OBJS-$(CONFIG_SPLITCC_FILTER)+= sf_splitcc.o
 OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
+OBJS-$(CONFIG_SUBFEED_FILTER)+= sf_subfeed.o
 OBJS-$(CONFIG_SUBSCALE_FILTER)   += sf_subscale.o
 OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
 
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 9c64f3f585..fe5f815731 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -581,6 +581,7 @@ extern const AVFilter ff_sf_graphicsub2text;
 extern const AVFilter ff_sf_showspeaker;
 extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
+extern const AVFilter ff_sf_subfeed;
 extern const AVFilter ff_sf_subscale;
 extern const AVFilter ff_sf_textmod;
 
diff --git a/libavfilter/sf_subfeed.c b/libavfilter/sf_subfeed.c
new file mode 100644
index 00..3227861ac0
--- /dev/null
+++ b/libavfilter/sf_subfeed.c
@@ -0,0 +1,412 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * subtitle filter for feeding subtitle frames into a filtergraph in a 
contiguous way
+ *
+ *
+ * also supports
+ *   - duration fixup
+ * delaying a subtitle event with unknown duration and infer duration from 
the
+ * start time of the subsequent subtitle
+ *   - scattering
+ * splitting a subtitle event with unknown duration into multiple ones with
+ * a short and fixed duration
+ *
+ */
+
+#include "filters.h"
+#include "libavutil/opt.h"
+#include "subtitles.h"
+#include "libavutil/avassert.h"
+
+enum SubFeedMode {
+FM_REPEAT,
+FM_SCATTER,
+FM_FORWARD,
+};
+
+typedef struct SubFeedContext {
+const AVClass *class;
+enum AVSubtitleType format;
+enum SubFeedMode mode;
+
+AVRational frame_rate;
+int fix_durations;
+int fix_overlap;
+
+int current_frame_isnew;
+int eof;
+int got_first_input;
+int need_frame;
+int64_t next_pts_offset;
+int64_t recent_subtitle_pts;
+
+int64_t counter;
+
+/**
+ * Queue of frames waiting to be filtered.
+ */
+FFFrameQueue fifo;
+
+} SubFeedContext;
+
+static int64_t ms_to_avtb(int64_t ms)
+{
+return av_rescale_q(ms, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q);
+}
+
+static int64_t avtb_to_ms(int64_t avtb)
+{
+return av_rescale_q(avtb, AV_TIME_BASE_Q, (AVRational){ 1, 1000 });
+}
+
+static int init(AVFilterContext *ctx)
+{
+SubFeedContext *s = ctx->priv;
+
+ff_framequeue_init(>fifo, NULL);
+
+return 0;
+}
+
+static void uninit(AVFilterContext *ctx)
+{
+SubFeedContext *s = ctx->priv;
+ff_framequeue_free(>fifo);
+}
+
+static int config_input(AVFilterLink *link)
+{
+const subfeedContext *context = link->dst->priv;
+
+return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+AVFilterFormats *formats;
+AVFilterLink *inlink0 = ctx->inputs[0];
+AVFilterLink *outlink0 = ctx->outputs[0];
+static const enum AVSubtitleType subtitle_fmts[] = { 
AV_SUBTITLE_FMT_BITMAP, AV_SUBTITLE_FMT_ASS, AV_SUBTITLE_FMT_NB };
+int ret;
+
+formats = ff_make_format_list(subtitle_fmts);
+
+if ((ret = ff_formats_ref(formats, >outcfg.formats)) < 0)
+return ret;
+
+if ((ret = ff_formats_ref(formats, >incfg.formats)) < 0)
+return ret;
+
+return 0;
+}
+
+static int config_output(AVFilterLink *outlink)
+{
+SubFeedContext *s = outlink->src->priv;
+const AVFilterLink *inlink = outlink->src->inputs[0];
+
+outlink->time_base = AV_TIME_BASE_Q;
+outlink->format = inlink->format;
+outlink->w = inlink->w;
+outlink->h = inlink->h;
+
+if (s->mode == FM_FORWARD)
+outlink->frame_rate = 

[FFmpeg-devel] [PATCH v9 18/25] avfilter/graphicsub2text: Add new graphicsub2text filter (OCR)

2022-10-25 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 configure|1 +
 doc/filters.texi |   55 ++
 libavfilter/Makefile |1 +
 libavfilter/allfilters.c |1 +
 libavfilter/sf_graphicsub2text.c | 1137 ++
 5 files changed, 1195 insertions(+)
 create mode 100644 libavfilter/sf_graphicsub2text.c

diff --git a/configure b/configure
index a992a4795f..815e8e067f 100755
--- a/configure
+++ b/configure
@@ -3687,6 +3687,7 @@ frei0r_filter_deps="frei0r"
 frei0r_src_filter_deps="frei0r"
 fspp_filter_deps="gpl"
 gblur_vulkan_filter_deps="vulkan spirv_compiler"
+graphicsub2text_filter_deps="libtesseract"
 hflip_vulkan_filter_deps="vulkan spirv_compiler"
 histeq_filter_deps="gpl"
 hqdn3d_filter_deps="gpl"
diff --git a/doc/filters.texi b/doc/filters.texi
index d1954b280f..6b05864706 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -27548,6 +27548,61 @@ ffmpeg -i 
"https://streams.videolan.org/ffmpeg/mkv_subtitles.mkv; -filter_comple
 @end example
 @end itemize
 
+@section graphicsub2text
+
+Converts graphic subtitles to text subtitles by performing OCR.
+
+For this filter to be available, ffmpeg needs to be compiled with libtesseract 
(see https://github.com/tesseract-ocr/tesseract).
+Language models need to be downloaded from 
https://github.com/tesseract-ocr/tessdata and put into as subfolder named 
'tessdata' or into a folder specified via the environment variable 
'TESSDATA_PREFIX'.
+The path can also be specified via filter option (see below).
+
+Note: These models are including the data for both OCR modes.
+
+Inputs:
+- 0: Subtitles [bitmap]
+
+Outputs:
+- 0: Subtitles [text]
+
+It accepts the following parameters:
+
+@table @option
+@item ocr_mode
+The character recognition mode to use.
+
+Supported OCR modes are:
+
+@table @var
+@item 0, tesseract
+This is the classic libtesseract operation mode. It is fast but less accurate 
than LSTM.
+@item 1, lstm
+Newer OCR implementation based on ML models. Provides usually better results, 
requires more processing resources.
+@item 2, both
+Use a combination of both modes.
+@end table
+
+@item tessdata_path
+The path to a folder containing the language models to be used.
+
+@item language
+The recognition language. It needs to match the first three characters of a  
language model file in the tessdata path.
+
+@end table
+
+
+@subsection Examples
+
+@itemize
+@item
+Convert DVB graphic subtitles to ASS (text) subtitles
+
+Note: For this to work, you need to have the data file 'eng.traineddata' in a 
'tessdata' subfolder (see above).
+@example
+ffmpeg -loglevel verbose -i 
"https://streams.videolan.org/streams/ts/video_subs_ttxt%2Bdvbsub.ts; 
-filter_complex "[0:13]graphicsub2text=delay_when_no_duration=1" -c:s ass -y 
output.mkv
+@end example
+@end itemize
+
+
 @section graphicsub2video
 
 Renders graphic subtitles as video frames.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 66c2210a46..03dd8ed5ef 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -314,6 +314,7 @@ OBJS-$(CONFIG_GBLUR_FILTER)  += vf_gblur.o
 OBJS-$(CONFIG_GBLUR_VULKAN_FILTER)   += vf_gblur_vulkan.o vulkan.o 
vulkan_filter.o
 OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o
 OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o
+OBJS-$(CONFIG_GRAPHICSUB2TEXT_FILTER)+= sf_graphicsub2text.o
 OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlaygraphicsubs.o 
framesync.o
 OBJS-$(CONFIG_GRAPHMONITOR_FILTER)   += f_graphmonitor.o
 OBJS-$(CONFIG_GRAYWORLD_FILTER)  += vf_grayworld.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 529ccbf760..a1137e6c25 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -577,6 +577,7 @@ extern const AVFilter ff_avsrc_movie;
 
 /* subtitle filters */
 extern const AVFilter ff_sf_censor;
+extern const AVFilter ff_sf_graphicsub2text;
 extern const AVFilter ff_sf_showspeaker;
 extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
diff --git a/libavfilter/sf_graphicsub2text.c b/libavfilter/sf_graphicsub2text.c
new file mode 100644
index 00..47c7030939
--- /dev/null
+++ b/libavfilter/sf_graphicsub2text.c
@@ -0,0 +1,1137 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, 

[FFmpeg-devel] [PATCH v9 08/25] fftools/play, probe: Adjust for subtitle changes

2022-10-25 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 fftools/ffplay.c  | 102 +-
 fftools/ffprobe.c |  47 +
 2 files changed, 77 insertions(+), 72 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index bcc00afe31..4ec186a0b3 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -153,7 +153,6 @@ typedef struct Clock {
 /* Common struct for handling all types of decoded data and allocated render 
buffers. */
 typedef struct Frame {
 AVFrame *frame;
-AVSubtitle sub;
 int serial;
 double pts;   /* presentation timestamp for the frame */
 double duration;  /* estimated duration of the frame */
@@ -574,7 +573,7 @@ static int decoder_init(Decoder *d, AVCodecContext *avctx, 
PacketQueue *queue, S
 return 0;
 }
 
-static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVSubtitle *sub) {
+static int decoder_decode_frame(Decoder *d, AVFrame *frame) {
 int ret = AVERROR(EAGAIN);
 
 for (;;) {
@@ -608,6 +607,9 @@ static int decoder_decode_frame(Decoder *d, AVFrame *frame, 
AVSubtitle *sub) {
 }
 }
 break;
+case AVMEDIA_TYPE_SUBTITLE:
+ret = avcodec_receive_frame(d->avctx, frame);
+break;
 }
 if (ret == AVERROR_EOF) {
 d->finished = d->pkt_serial;
@@ -640,25 +642,11 @@ static int decoder_decode_frame(Decoder *d, AVFrame 
*frame, AVSubtitle *sub) {
 av_packet_unref(d->pkt);
 } while (1);
 
-if (d->avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
-int got_frame = 0;
-ret = avcodec_decode_subtitle2(d->avctx, sub, _frame, d->pkt);
-if (ret < 0) {
-ret = AVERROR(EAGAIN);
-} else {
-if (got_frame && !d->pkt->data) {
-d->packet_pending = 1;
-}
-ret = got_frame ? 0 : (d->pkt->data ? AVERROR(EAGAIN) : 
AVERROR_EOF);
-}
-av_packet_unref(d->pkt);
+if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN)) {
+av_log(d->avctx, AV_LOG_ERROR, "Receive_frame and send_packet both 
returned EAGAIN, which is an API violation.\n");
+d->packet_pending = 1;
 } else {
-if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN)) {
-av_log(d->avctx, AV_LOG_ERROR, "Receive_frame and send_packet 
both returned EAGAIN, which is an API violation.\n");
-d->packet_pending = 1;
-} else {
-av_packet_unref(d->pkt);
-}
+av_packet_unref(d->pkt);
 }
 }
 }
@@ -671,7 +659,6 @@ static void decoder_destroy(Decoder *d) {
 static void frame_queue_unref_item(Frame *vp)
 {
 av_frame_unref(vp->frame);
-avsubtitle_free(>sub);
 }
 
 static int frame_queue_init(FrameQueue *f, PacketQueue *pktq, int max_size, 
int keep_last)
@@ -969,7 +956,7 @@ static void video_image_display(VideoState *is)
 if (frame_queue_nb_remaining(>subpq) > 0) {
 sp = frame_queue_peek(>subpq);
 
-if (vp->pts >= sp->pts + ((float) sp->sub.start_display_time / 
1000)) {
+if (vp->pts >= sp->pts) {
 if (!sp->uploaded) {
 uint8_t* pixels[4];
 int pitch[4];
@@ -981,25 +968,27 @@ static void video_image_display(VideoState *is)
 if (realloc_texture(>sub_texture, 
SDL_PIXELFORMAT_ARGB, sp->width, sp->height, SDL_BLENDMODE_BLEND, 1) < 0)
 return;
 
-for (i = 0; i < sp->sub.num_rects; i++) {
-AVSubtitleRect *sub_rect = sp->sub.rects[i];
+for (i = 0; i < sp->frame->num_subtitle_areas; i++) {
+AVSubtitleArea *area = sp->frame->subtitle_areas[i];
+SDL_Rect sdl_rect = { .x = area->x, .y = area->y, .w = 
area->w, .h = area->h };
 
-sub_rect->x = av_clip(sub_rect->x, 0, sp->width );
-sub_rect->y = av_clip(sub_rect->y, 0, sp->height);
-sub_rect->w = av_clip(sub_rect->w, 0, sp->width  - 
sub_rect->x);
-sub_rect->h = av_clip(sub_rect->h, 0, sp->height - 
sub_rect->y);
+area->x = av_clip(area->x, 0, sp->width );
+area->y = av_clip(area->y, 0, sp->height);
+area->w = av_clip(area->w, 0, sp->width  - area->x);
+area->h = av_clip(area->h, 0, sp->height - area->y);
 
 is->sub_convert_ctx = 
sws_getCachedContext(is->sub_convert_ctx,
-sub_rect->w, sub_rect->h, AV_PIX_FMT_PAL8,
-sub_rect->w, sub_rect->h, AV_PIX_FMT_BGRA,
+

[FFmpeg-devel] [PATCH v9 16/25] avfilter/stripstyles: Add stripstyles filter

2022-10-25 Thread softworkz
From: softworkz 

- stripstyles {S -> S)
  Remove all inline styles from subtitle events

Signed-off-by: softworkz 
---
 doc/filters.texi |  37 ++
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_stripstyles.c | 237 +++
 4 files changed, 276 insertions(+)
 create mode 100644 libavfilter/sf_stripstyles.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 1f7989e92f..383e020c8d 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -27432,6 +27432,43 @@ ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.
 @end example
 @end itemize
 
+@section stripstyles
+
+Remove all inline styles from subtitle events.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item remove_animated
+Also remove text which is subject to animation (default: true)
+Usually, animated text elements are used used in addition to static subtitle 
lines for creating effects, so in most cases it is safe to remove the animation 
content.
+If subtitle text is missing, try setting this to false.
+
+@item select_layer
+Process only ASS subtitle events from a specific layer. This allows to filter 
out certain effects where an ASS author duplicates the text onto multiple 
layers.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Remove styles and animations from ASS subtitles and output events from ass 
layer 0 only. Then convert asn save as SRT stream:
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv; 
-filter_complex "[0:1]stripstyles=select_layer=0" -map 0 -c:s srt output.mkv
+@end example
+@end itemize
+
 
 @section textmod
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 5d82b3e8c4..01b7440cce 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -590,6 +590,7 @@ OBJS-$(CONFIG_NULLSINK_FILTER)   += 
vsink_nullsink.o
 # subtitle filters
 OBJS-$(CONFIG_CENSOR_FILTER) += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)   += sf_textmod.o
+OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
 
 # multimedia filters
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index d7f24ab7db..33bfae7358 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -578,6 +578,7 @@ extern const AVFilter ff_avsrc_movie;
 /* subtitle filters */
 extern const AVFilter ff_sf_censor;
 extern const AVFilter ff_sf_showspeaker;
+extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_textmod;
 
 /* those filters are part of public or internal API,
diff --git a/libavfilter/sf_stripstyles.c b/libavfilter/sf_stripstyles.c
new file mode 100644
index 00..78dc6f3ef4
--- /dev/null
+++ b/libavfilter/sf_stripstyles.c
@@ -0,0 +1,237 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * text subtitle filter which removes inline-styles from subtitles
+ */
+
+#include "libavutil/opt.h"
+#include "internal.h"
+#include "libavutil/ass_internal.h"
+#include "libavutil/ass_split_internal.h"
+#include "libavutil/bprint.h"
+
+typedef struct StripStylesContext {
+const AVClass *class;
+enum AVSubtitleType format;
+int remove_animated;
+enum ASSSplitComponents keep_flags;
+int select_layer;
+} StripStylesContext;
+
+typedef struct DialogContext {
+StripStylesContext* ss_ctx;
+AVBPrint buffer;
+int drawing_scale;
+int is_animated;
+int plain_text_length;
+} DialogContext;
+
+static void dialog_text_cb(void *priv, const char *text, int len)
+{
+DialogContext *s = priv;
+
+av_log(s->ss_ctx, AV_LOG_DEBUG, "dialog_text_cb: %s\n", text);
+
+if (!s->drawing_scale && (!s->is_animated || !s->ss_ctx->remove_animated))
+s->plain_text_length += len;
+av_bprint_append_data(>buffer, text, len);
+}
+
+static void dialog_new_line_cb(void *priv, int forced)
+{
+DialogContext *s = priv;
+if (!s->drawing_scale && !s->is_animated)
+s->plain_text_length += 2;
+ 

[FFmpeg-devel] [PATCH v9 17/25] avfilter/splitcc: Add splitcc filter for closed caption handling

2022-10-25 Thread softworkz
From: softworkz 

- splitcc {V -> VS)
  Extract closed-caption (A53) data from video
  frames as subtitle Frames

ffmpeg -y -loglevel verbose -i "https://streams.videolan.org/streams
/ts/CC/NewsStream-608-ac3.ts" -filter_complex "[0:v]splitcc[vid1],
textmod=mode=remove_chars:find='@',[vid1]overlay_textsubs" output.mkv

Signed-off-by: softworkz 
---
 configure|   1 +
 doc/filters.texi |  63 +++
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_splitcc.c | 395 +++
 5 files changed, 461 insertions(+)
 create mode 100644 libavfilter/sf_splitcc.c

diff --git a/configure b/configure
index 61a7bd1438..a992a4795f 100755
--- a/configure
+++ b/configure
@@ -3753,6 +3753,7 @@ spp_filter_select="fft idctdsp fdctdsp me_cmp pixblockdsp"
 sr_filter_deps="avformat swscale"
 sr_filter_select="dnn"
 stereo3d_filter_deps="gpl"
+splitcc_filter_deps="avcodec"
 subtitles_filter_deps="avformat avcodec libass"
 super2xsai_filter_deps="gpl"
 pixfmts_super2xsai_test_deps="super2xsai_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index 383e020c8d..d1954b280f 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -27782,6 +27782,69 @@ ffmpeg -i INPUT -filter_complex 
"showspeaker=format=colon:style='@{\\c&\
 @end example
 @end itemize
 
+
+@section splitcc
+
+Split-out closed-caption/A53 subtitles from video frame side data.
+
+This filter provides an input and an output for video frames, which are just 
passed through without modification.
+The second out provides subtitle frames which are extracted from video frame 
side data.
+
+Inputs:
+@itemize
+@item 0: Video [ALL]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@item 1: Subtitles [TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item use_cc_styles
+Emit closed caption style header.
+This will make closed captions appear in white font with a black rectangle 
background.
+
+@item real_time
+Emit subtitle events as they are decoded for real-time display.
+
+@item real_time_latency_msec
+Minimum elapsed time between emitting real-time subtitle events.
+Only applies to real_time mode.
+
+@item data_field
+Select data field. Possible values:
+
+@table @samp
+@item auto
+Pick first one that appears.
+@item first
+@item second
+@end table
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Extract closed captions as text subtitle stream and overlay it onto the video 
in cc style (black bar background):
+@example
+ffmpeg -i "https://streams.videolan.org/streams/ts/CC/NewsStream-608-ac3.ts; 
-filter_complex  
"[0:v:0]splitcc=use_cc_styles=1[vid1][sub1];[vid1][sub1]overlaytextsubs" 
output.mkv
+@end example
+
+@item
+A nicer variant, using realtime output from cc_dec and rendering it with the 
render_latest_only parameter from overlaytextsubs to avoid ghosting by timely 
overlap.
+@example
+ffmpeg -i "https://streams.videolan.org/streams/ts/CC/NewsStream-608-ac3.ts; 
-filter_complex  
"[0:v:0]splitcc=real_time=1:real_time_latency_msec=200[vid1][sub1];[vid1][sub1]overlaytextsubs=render_latest_only=1"
 output.mkv
+@end example
+@end itemize
+
+
 @section textsub2video
 
 Converts text subtitles to video frames.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 01b7440cce..66c2210a46 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -590,6 +590,7 @@ OBJS-$(CONFIG_NULLSINK_FILTER)   += 
vsink_nullsink.o
 # subtitle filters
 OBJS-$(CONFIG_CENSOR_FILTER) += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)   += sf_textmod.o
+OBJS-$(CONFIG_SPLITCC_FILTER)+= sf_splitcc.o
 OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
 
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 33bfae7358..529ccbf760 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -578,6 +578,7 @@ extern const AVFilter ff_avsrc_movie;
 /* subtitle filters */
 extern const AVFilter ff_sf_censor;
 extern const AVFilter ff_sf_showspeaker;
+extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_textmod;
 
diff --git a/libavfilter/sf_splitcc.c b/libavfilter/sf_splitcc.c
new file mode 100644
index 00..14235e822c
--- /dev/null
+++ b/libavfilter/sf_splitcc.c
@@ -0,0 +1,395 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser 

[FFmpeg-devel] [PATCH v9 15/25] avfilter/textmod: Add textmod, censor and show_speaker filters

2022-10-25 Thread softworkz
From: softworkz 

- textmod {S -> S)
  Modify subtitle text in a number of ways

- censor {S -> S)
  Censor subtitles using a word list

- show_speaker {S -> S)
  Prepend speaker names from ASS subtitles to the visible text lines

Signed-off-by: softworkz 
---
 doc/filters.texi | 206 
 libavfilter/Makefile |   5 +
 libavfilter/allfilters.c |   5 +
 libavfilter/sf_textmod.c | 710 +++
 4 files changed, 926 insertions(+)
 create mode 100644 libavfilter/sf_textmod.c

diff --git a/doc/filters.texi b/doc/filters.texi
index fa6fd57cdc..1f7989e92f 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -27372,6 +27372,145 @@ existing filters using @code{--disable-filters}.
 
 Below is a description of the currently available subtitle filters.
 
+
+@section censor
+
+Censor selected words in text subtitles.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item mode
+The censoring mode to apply.
+
+Supported censoring modes are:
+
+@table @var
+@item 0, keep_first_last
+Replace all characters with the 'censor_char' except the first and the last 
character of a word.
+For words with less than 4 characters, the last character will be replaced as 
well.
+For words with less than 3 characters, the first character will be replaced as 
well.
+@item 1, keep_first
+Replace all characters with the 'censor_char' except the first character of a 
word.
+For words with less than 3 characters, the first character will be replaced as 
well.
+@item 2, all
+Replace all characters with the 'censor_char'.
+@end table
+
+@item words
+A list of words to censor, separated by 'separator'.
+
+@item words_file
+Specify a file from which to load the contents for the 'words' parameter.
+
+@item censor_char
+Single character used as replacement for censoring.
+
+@item separator
+Delimiter character for words. Used with replace_words and remove_words- Must 
be a single character.
+The default is '.'.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Censor a few given words with a pound character.
+@example
+ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv; 
-filter_complex 
"[0:1]censor=words='diss,louder,hope,beam,word':censor_char='#'" -map 0 -y 
output.mkv
+@end example
+@end itemize
+
+
+@section textmod
+
+Modify subtitle text in a number of ways.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item mode
+The kind of text modification to apply
+
+Supported operation modes are:
+
+@table @var
+@item 0, leet
+Convert subtitle text to 'leet speak'. It's primarily useful for testing as 
the modification will be visible with almost all text lines.
+@item 1, to_upper
+Change all text to upper case. Might improve readability.
+@item 2, to_lower
+Change all text to lower case.
+@item 3, replace_chars
+Replace one or more characters. Requires the find and replace parameters to be 
specified.
+Both need to be equal in length.
+The first char in find is replaced by the first char in replace, same for all 
subsequent chars.
+@item 4, remove_chars
+Remove certain characters. Requires the find parameter to be specified.
+All chars in the find parameter string will be removed from all subtitle text.
+@item 5, replace_words
+Replace one or more words. Requires the find and replace parameters to be 
specified. Multiple words must be separated by the delimiter char specified vie 
the separator parameter (default: ',').
+The number of words in the find and replace parameters needs to be equal.
+The first word in find is replaced by the first word in replace, same for all 
subsequent words
+@item 6, remove_words
+Remove certain words. Requires the find parameter to be specified. Multiple 
words must be separated by the delimiter char specified vie the separator 
parameter (default: ',').
+All words in the find parameter string will be removed from all subtitle text.
+@end table
+
+@item find
+Required for replace_chars, remove_chars, replace_words and remove_words.
+
+@item find_file
+Specify a file from which to load the contents for the 'find' parameter.
+
+@item replace
+Required for replace_chars and replace_words.
+
+@item replace_file
+Specify a file from which to load the contents for the 'replace' parameter.
+
+@item separator
+Delimiter character for words. Used with replace_words and remove_words- Must 
be a single character.
+The default is '.'.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Change all characters to upper case while keeping all styles and animations:
+@example
+ffmpeg -i "https://streams.videolan.org/ffmpeg/mkv_subtitles.mkv; 
-filter_complex "[0:s]textmod=mode=to_upper" -map 0 -y out.mkv
+@end example
+@item
+Remove a set of symbol characters for am 

[FFmpeg-devel] [PATCH v9 14/25] avfilter/overlaytextsubs: Add overlaytextsubs and textsubs2video filters

2022-10-25 Thread softworkz
From: softworkz 

- overlaytextsubs {VS -> V)
  Overlay text subtitles onto a video stream.

- textsubs2video {S -> V)
  Converts text subtitles to video frames

Signed-off-by: softworkz 
---
 configure|   2 +
 doc/filters.texi | 113 +
 libavfilter/Makefile |   2 +
 libavfilter/allfilters.c |   2 +
 libavfilter/vf_overlaytextsubs.c | 680 +++
 5 files changed, 799 insertions(+)
 create mode 100644 libavfilter/vf_overlaytextsubs.c

diff --git a/configure b/configure
index b3f242469b..61a7bd1438 100755
--- a/configure
+++ b/configure
@@ -3716,6 +3716,7 @@ overlay_qsv_filter_deps="libmfx"
 overlay_qsv_filter_select="qsvvpp"
 overlay_vaapi_filter_deps="vaapi VAProcPipelineCaps_blend_flags"
 overlay_vulkan_filter_deps="vulkan spirv_compiler"
+overlaytextsubs_filter_deps="avcodec libass"
 owdenoise_filter_deps="gpl"
 pad_opencl_filter_deps="opencl"
 pan_filter_deps="swresample"
@@ -3755,6 +3756,7 @@ stereo3d_filter_deps="gpl"
 subtitles_filter_deps="avformat avcodec libass"
 super2xsai_filter_deps="gpl"
 pixfmts_super2xsai_test_deps="super2xsai_filter"
+textsub2video_filter_deps="avcodec libass"
 tinterlace_filter_deps="gpl"
 tinterlace_merge_test_deps="tinterlace_filter"
 tinterlace_pad_test_deps="tinterlace_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index 70a371ee0e..fa6fd57cdc 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -27480,6 +27480,119 @@ Overlay PGS subtitles
 ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv;
 -filter_complex "[0:0][0:1]overlaygraphicsubs" output.mp4
 @end example
 @end itemize
+
+@section overlaytextsubs
+
+Overlay text subtitles onto a video stream.
+
+This filter supersedes the classic @ref{subtitles} filter opposed to which it 
does no longer require to open and access the source stream separately, which 
is often causing problems or doesn't even work for non-local or slow sources.
+
+Inputs:
+@itemize
+@item 0: Video [YUV420P, YUV422P, YUV444P, ARGB, RGBA, ABGR, BGRA, RGB24, 
BGR24]
+@item 1: Subtitles [TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item alpha
+Process alpha channel, by default alpha channel is untouched.
+
+@item fonts_dir
+Set a directory path containing fonts that can be used by the filter.
+These fonts will be used in addition to whatever the font provider uses.
+
+@item default_font_path
+Path to a font file to be used as the default font.
+
+@item font_size
+Set the default font size.
+
+@item fontconfig_file
+Path to ASS fontconfig configuration file.
+
+@item force_style
+Override default style or script info parameters of the subtitles. It accepts a
+string containing ASS style format @code{KEY=VALUE} couples separated by ",".
+
+@item margin
+Set the rendering margin in pixels.
+
+@item render_latest_only
+For rendering, alway use the latest event only, which is covering the given 
point in time
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay ASS subtitles with animations:
+@example
+ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv; 
-filter_complex "[0:v]overlaytextsubs" -map 0 -y out.mkv
+@end example
+@end itemize
+
+@section textsub2video
+
+Converts text subtitles to video frames.
+
+For overlaying text subtitles onto video frames it is recommended to use the 
overlaytextsubs filter.
+The textsub2video is useful for for creating transparent text-frames when 
overlay is done via hw acceleration
+
+Inputs:
+@itemize
+@item 0: Subtitles [TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video [RGB32]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item rate, r
+Set the framerate for updating overlay frames.
+Normally, overlay frames will only be updated each time when the subtitles to 
display are changing.
+In cases where subtitles include advanced features (like animation), this 
parameter determines the frequency by which the overlay frames should be 
updated.
+
+@item size, s
+Set the output frame size.
+Allows to override the size of output video frames.
+
+@item fonts_dir
+Set a directory path containing fonts that can be used by the filter.
+These fonts will be used in addition to whatever the font provider uses.
+
+@item default_font_path
+Path to a font file to be used as the default font.
+
+@item font_size
+Set the default font size.
+
+@item fontconfig_file
+Path to ASS fontconfig configuration file.
+
+@item force_style
+Override default style or script info parameters of the subtitles. It accepts a
+string containing ASS style format @code{KEY=VALUE} couples separated by ",".
+
+@item margin
+Set the rendering margin in pixels.
+
+@item render_latest_only
+For rendering, alway use the latest event only, which is covering the given 
point in time.
+@end table
+
 @c man end SUBTITLE FILTERS
 
 

[FFmpeg-devel] [PATCH v9 13/25] avfilter/overlaygraphicsubs: Add overlaygraphicsubs and graphicsub2video filters

2022-10-25 Thread softworkz
From: softworkz 

- overlaygraphicsubs (VS -> V)
  Overlay graphic subtitles onto a video stream

- graphicsub2video {S -> V)
  Converts graphic subtitles to video frames (with alpha)
  Gets auto-inserted for retaining compatibility with
  sub2video command lines

Signed-off-by: softworkz 
---
 doc/filters.texi| 118 +
 libavfilter/Makefile|   2 +
 libavfilter/allfilters.c|   2 +
 libavfilter/vf_overlaygraphicsubs.c | 765 
 4 files changed, 887 insertions(+)
 create mode 100644 libavfilter/vf_overlaygraphicsubs.c

diff --git a/doc/filters.texi b/doc/filters.texi
index bcd19cf931..70a371ee0e 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -27364,6 +27364,124 @@ tools.
 
 @c man end VIDEO SINKS
 
+@chapter Subtitle Filters
+@c man begin SUBTITLE FILTERS
+
+When you configure your FFmpeg build, you can disable any of the
+existing filters using @code{--disable-filters}.
+
+Below is a description of the currently available subtitle filters.
+
+@section graphicsub2video
+
+Renders graphic subtitles as video frames.
+
+This filter replaces the previous "sub2video" hack which did the conversion 
implicitly and up-front as subtitle filtering wasn't possible at that time.
+To retain compatibility with earlier sub2video command lines, this filter is 
being auto-inserted in those cases.
+
+For overlaying graphicsal subtitles it is recommended to use the 
'overlaygraphicsubs' filter which is more efficient and takes less processing 
resources.
+
+This filter is still useful in cases where the overlay is done with hardware 
acceleration (e.g. overlay_qsv, overlay_vaapi, overlay_cuda) for preparing the 
overlay frames.
+
+Inputs:
+@itemize
+@item 0: Subtitles [BITMAP]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video [RGB32]
+@end itemize
+
+
+It accepts the following parameters:
+
+@table @option
+@item size, s
+Set the size of the output video frame.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay PGS subtitles
+(not recommended - better use overlaygraphicsubs)
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv;
 -filter_complex "[0:1]graphicsub2video[subs];[0:0][subs]overlay" output.mp4
+@end example
+
+@item
+Overlay PGS subtitles implicitly
+The graphicsub2video is inserted automatically for compatibility with legacy 
command lines.
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv;
 -filter_complex "[0:0][0:1]overlay" output.mp4
+@end example
+@end itemize
+
+@section overlaygraphicsubs
+
+Overlay graphic subtitles onto a video stream.
+
+This filter can blend graphical subtitles on a video stream directly, i.e. 
without creating full-size alpha images first.
+The blending operation is limited to the area of the subtitle rectangles, 
which also means that no processing is done at times where no subtitles are to 
be displayed.
+
+Inputs:
+@itemize
+@item 0: Video [YUV420P, YUV422P, YUV444P, ARGB, RGBA, ABGR, BGRA, RGB24, 
BGR24]
+@item 1: Subtitles [BITMAP]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item x
+@item y
+Set the expression for the x and y coordinates of the overlaid video
+on the main video. Default value is "0" for both expressions. In case
+the expression is invalid, it is set to a huge value (meaning that the
+overlay will not be displayed within the output visible area).
+
+@item eof_action
+See @ref{framesync}.
+
+@item eval
+Set when the expressions for @option{x}, and @option{y} are evaluated.
+
+It accepts the following values:
+@table @samp
+@item init
+only evaluate expressions once during the filter initialization or
+when a command is processed
+
+@item frame
+evaluate expressions for each incoming frame
+@end table
+
+Default value is @samp{frame}.
+
+@item shortest
+See @ref{framesync}.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay PGS subtitles
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv;
 -filter_complex "[0:0][0:1]overlaygraphicsubs" output.mp4
+@end example
+@end itemize
+@c man end SUBTITLE FILTERS
+
 @chapter Multimedia Filters
 @c man begin MULTIMEDIA FILTERS
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 6db90028e0..0dae913b16 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -314,6 +314,7 @@ OBJS-$(CONFIG_GBLUR_FILTER)  += vf_gblur.o
 OBJS-$(CONFIG_GBLUR_VULKAN_FILTER)   += vf_gblur_vulkan.o vulkan.o 
vulkan_filter.o
 OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o
 OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o
+OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlaygraphicsubs.o 
framesync.o
 OBJS-$(CONFIG_GRAPHMONITOR_FILTER)   += f_graphmonitor.o
 OBJS-$(CONFIG_GRAYWORLD_FILTER) 

[FFmpeg-devel] [PATCH v9 12/25] avfilter/sbuffer: Add sbuffersrc and sbuffersink filters

2022-10-25 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 configure|  2 +-
 libavfilter/allfilters.c |  2 ++
 libavfilter/buffersink.c | 54 ++
 libavfilter/buffersink.h |  7 
 libavfilter/buffersrc.c  | 72 
 libavfilter/buffersrc.h  |  1 +
 6 files changed, 137 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 431fa5bf7a..b3f242469b 100755
--- a/configure
+++ b/configure
@@ -7954,7 +7954,7 @@ print_enabled_components(){
 fi
 done
 if [ "$name" = "filter_list" ]; then
-for c in asrc_abuffer vsrc_buffer asink_abuffer vsink_buffer; do
+for c in asrc_abuffer vsrc_buffer ssrc_sbuffer asink_abuffer 
vsink_buffer ssink_sbuffer; do
 printf "_%s,\n" $c >> $TMPH
 done
 fi
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 119de40b25..173d85b982 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -577,8 +577,10 @@ extern const AVFilter ff_avsrc_movie;
  * being the same while having different 'types'). */
 extern  const AVFilter ff_asrc_abuffer;
 extern  const AVFilter ff_vsrc_buffer;
+extern  const AVFilter ff_ssrc_sbuffer;
 extern  const AVFilter ff_asink_abuffer;
 extern  const AVFilter ff_vsink_buffer;
+extern  const AVFilter ff_ssink_sbuffer;
 extern const AVFilter ff_af_afifo;
 extern const AVFilter ff_vf_fifo;
 
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index e269cf72d1..204e9bad6c 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -30,6 +30,8 @@
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
 
+#include "libavcodec/avcodec.h"
+
 #define FF_INTERNAL_FIELDS 1
 #include "framequeue.h"
 
@@ -61,6 +63,10 @@ typedef struct BufferSinkContext {
 int *sample_rates;  ///< list of accepted sample rates
 int sample_rates_size;
 
+/* only used for subtitles */
+enum AVSubtitleType *subtitle_types; ///< list of accepted subtitle 
types, must be terminated with -1
+int subtitle_types_size;
+
 AVFrame *peeked_frame;
 } BufferSinkContext;
 
@@ -372,6 +378,28 @@ static int asink_query_formats(AVFilterContext *ctx)
 return 0;
 }
 
+static int ssink_query_formats(AVFilterContext *ctx)
+{
+BufferSinkContext *buf = ctx->priv;
+AVFilterFormats *formats = NULL;
+unsigned i;
+int ret;
+
+CHECK_LIST_SIZE(subtitle_types)
+if (buf->subtitle_types_size) {
+for (i = 0; i < NB_ITEMS(buf->subtitle_types); i++)
+if ((ret = ff_add_format(, buf->subtitle_types[i])) < 0)
+return ret;
+if ((ret = ff_set_common_formats(ctx, formats)) < 0)
+return ret;
+} else {
+if ((ret = ff_default_query_formats(ctx)) < 0)
+return ret;
+}
+
+return 0;
+}
+
 #define OFFSET(x) offsetof(BufferSinkContext, x)
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 static const AVOption buffersink_options[] = {
@@ -395,9 +423,16 @@ static const AVOption abuffersink_options[] = {
 { NULL },
 };
 #undef FLAGS
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_SUBTITLE_PARAM
+static const AVOption sbuffersink_options[] = {
+{ "subtitle_types", "set the supported subtitle formats", 
OFFSET(subtitle_types), AV_OPT_TYPE_BINARY, .flags = FLAGS },
+{ NULL },
+};
+#undef FLAGS
 
 AVFILTER_DEFINE_CLASS(buffersink);
 AVFILTER_DEFINE_CLASS(abuffersink);
+AVFILTER_DEFINE_CLASS(sbuffersink);
 
 static const AVFilterPad avfilter_vsink_buffer_inputs[] = {
 {
@@ -436,3 +471,22 @@ const AVFilter ff_asink_abuffer = {
 .outputs   = NULL,
 FILTER_QUERY_FUNC(asink_query_formats),
 };
+
+static const AVFilterPad avfilter_ssink_sbuffer_inputs[] = {
+{
+.name = "default",
+.type = AVMEDIA_TYPE_SUBTITLE,
+},
+};
+
+const AVFilter ff_ssink_sbuffer = {
+.name  = "sbuffersink",
+.description   = NULL_IF_CONFIG_SMALL("Buffer subtitle frames, and make 
them available to the end of the filter graph."),
+.priv_class= _class,
+.priv_size = sizeof(BufferSinkContext),
+.init  = common_init,
+.activate  = activate,
+FILTER_INPUTS(avfilter_ssink_sbuffer_inputs),
+.outputs   = NULL,
+FILTER_QUERY_FUNC(ssink_query_formats),
+};
diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
index 01e7c747d8..42c164e670 100644
--- a/libavfilter/buffersink.h
+++ b/libavfilter/buffersink.h
@@ -128,6 +128,13 @@ typedef struct AVABufferSinkParams {
  */
 attribute_deprecated
 AVABufferSinkParams *av_abuffersink_params_alloc(void);
+
+/**
+ * Deprecated and unused struct to use for initializing an sbuffersink context.
+ */
+typedef struct AVSBufferSinkParams {
+const int *subtitle_type;
+} AVSBufferSinkParams;
 #endif
 
 /**
diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index ae8bba19b0..21465fe5e3 100644
--- a/libavfilter/buffersrc.c
+++ 

[FFmpeg-devel] [PATCH v9 06/25] avcodec, avutil: Move ass helper functions to avutil as avpriv_ and extend ass dialog parsing

2022-10-25 Thread softworkz
From: softworkz 

Also add

- hard_space callback (for upcoming fix)
- extensible callback (for future extension)
- new API which allows tag filtering

Signed-off-by: softworkz 
---
 libavcodec/Makefile   |  56 +++---
 libavcodec/ass.h  | 151 +--
 libavcodec/ass_split.h| 191 ---
 libavcodec/assdec.c   |   2 +-
 libavcodec/assenc.c   |   2 +-
 libavcodec/ccaption_dec.c |  20 +-
 libavcodec/jacosubdec.c   |   2 +-
 libavcodec/libaribb24.c   |   2 +-
 libavcodec/libzvbi-teletextdec.c  |  14 +-
 libavcodec/microdvddec.c  |   7 +-
 libavcodec/movtextdec.c   |   3 +-
 libavcodec/movtextenc.c   |  20 +-
 libavcodec/mpl2dec.c  |   2 +-
 libavcodec/realtextdec.c  |   2 +-
 libavcodec/samidec.c  |   2 +-
 libavcodec/srtdec.c   |   2 +-
 libavcodec/srtenc.c   |  16 +-
 libavcodec/subviewerdec.c |   2 +-
 libavcodec/textdec.c  |   4 +-
 libavcodec/ttmlenc.c  |  15 +-
 libavcodec/webvttdec.c|   2 +-
 libavcodec/webvttenc.c|  16 +-
 libavutil/Makefile|   2 +
 {libavcodec => libavutil}/ass.c   | 115 
 libavutil/ass_internal.h  | 135 ++
 {libavcodec => libavutil}/ass_split.c | 179 +++---
 libavutil/ass_split_internal.h| 254 ++
 27 files changed, 726 insertions(+), 492 deletions(-)
 delete mode 100644 libavcodec/ass_split.h
 rename {libavcodec => libavutil}/ass.c (59%)
 create mode 100644 libavutil/ass_internal.h
 rename {libavcodec => libavutil}/ass_split.c (71%)
 create mode 100644 libavutil/ass_split_internal.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 90c7f113a3..58544b40ba 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -224,10 +224,10 @@ OBJS-$(CONFIG_APNG_DECODER)+= png.o pngdec.o 
pngdsp.o
 OBJS-$(CONFIG_APNG_ENCODER)+= png.o pngenc.o
 OBJS-$(CONFIG_ARBC_DECODER)+= arbc.o
 OBJS-$(CONFIG_ARGO_DECODER)+= argo.o
-OBJS-$(CONFIG_SSA_DECODER) += assdec.o ass.o
-OBJS-$(CONFIG_SSA_ENCODER) += assenc.o ass.o
-OBJS-$(CONFIG_ASS_DECODER) += assdec.o ass.o
-OBJS-$(CONFIG_ASS_ENCODER) += assenc.o ass.o
+OBJS-$(CONFIG_SSA_DECODER) += assdec.o
+OBJS-$(CONFIG_SSA_ENCODER) += assenc.o
+OBJS-$(CONFIG_ASS_DECODER) += assdec.o
+OBJS-$(CONFIG_ASS_ENCODER) += assenc.o
 OBJS-$(CONFIG_ASV1_DECODER)+= asvdec.o asv.o mpeg12data.o
 OBJS-$(CONFIG_ASV1_ENCODER)+= asvenc.o asv.o mpeg12data.o
 OBJS-$(CONFIG_ASV2_DECODER)+= asvdec.o asv.o mpeg12data.o
@@ -269,7 +269,7 @@ OBJS-$(CONFIG_BRENDER_PIX_DECODER) += brenderpix.o
 OBJS-$(CONFIG_C93_DECODER) += c93.o
 OBJS-$(CONFIG_CAVS_DECODER)+= cavs.o cavsdec.o cavsdsp.o \
   cavsdata.o
-OBJS-$(CONFIG_CCAPTION_DECODER)+= ccaption_dec.o ass.o
+OBJS-$(CONFIG_CCAPTION_DECODER)+= ccaption_dec.o
 OBJS-$(CONFIG_CDGRAPHICS_DECODER)  += cdgraphics.o
 OBJS-$(CONFIG_CDTOONS_DECODER) += cdtoons.o
 OBJS-$(CONFIG_CDXL_DECODER)+= cdxl.o
@@ -449,7 +449,7 @@ OBJS-$(CONFIG_INTERPLAY_ACM_DECODER)   += interplayacm.o
 OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER)  += dpcm.o
 OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o
 OBJS-$(CONFIG_IPU_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o
-OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o ass.o
+OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o
 OBJS-$(CONFIG_JPEG2000_ENCODER)+= j2kenc.o mqcenc.o mqc.o jpeg2000.o \
   jpeg2000dwt.o
 OBJS-$(CONFIG_JPEG2000_DECODER)+= jpeg2000dec.o jpeg2000.o 
jpeg2000dsp.o \
@@ -472,7 +472,7 @@ OBJS-$(CONFIG_MDEC_DECODER)+= mdec.o mpeg12.o 
mpeg12data.o
 OBJS-$(CONFIG_MEDIA100_DECODER)+= media100.o
 OBJS-$(CONFIG_METASOUND_DECODER)   += metasound.o metasound_data.o \
   twinvq.o
-OBJS-$(CONFIG_MICRODVD_DECODER)+= microdvddec.o ass.o
+OBJS-$(CONFIG_MICRODVD_DECODER)+= microdvddec.o
 OBJS-$(CONFIG_MIMIC_DECODER)   += mimic.o
 OBJS-$(CONFIG_MISC4_DECODER)   += misc4.o
 OBJS-$(CONFIG_MJPEG_DECODER)   += mjpegdec.o mjpegdec_common.o
@@ -488,8 +488,8 @@ OBJS-$(CONFIG_MLP_ENCODER) += mlpenc.o mlp.o
 OBJS-$(CONFIG_MMVIDEO_DECODER) += mmvideo.o
 OBJS-$(CONFIG_MOBICLIP_DECODER)+= mobiclip.o
 OBJS-$(CONFIG_MOTIONPIXELS_DECODER)+= motionpixels.o
-OBJS-$(CONFIG_MOVTEXT_DECODER) += movtextdec.o ass.o
-OBJS-$(CONFIG_MOVTEXT_ENCODER) += movtextenc.o ass_split.o

[FFmpeg-devel] [PATCH v9 11/25] avfilter/avfilter: Fix hardcoded input index

2022-10-25 Thread softworkz
From: softworkz 

This fix targets (rare) cases where multiple input pads have a
.filter_frame function. ff_request_frame_to_filter needs
to call ff_request_frame with the correct input pad
instead of the hardcoded first one.

Signed-off-by: softworkz 
---
 libavfilter/avfilter.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index b40a2fc7cd..6cd83ae34a 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -461,7 +461,7 @@ static int64_t guess_status_pts(AVFilterContext *ctx, int 
status, AVRational lin
 return AV_NOPTS_VALUE;
 }
 
-static int ff_request_frame_to_filter(AVFilterLink *link)
+static int ff_request_frame_to_filter(AVFilterLink *link, int input_index)
 {
 int ret = -1;
 
@@ -470,8 +470,8 @@ static int ff_request_frame_to_filter(AVFilterLink *link)
 link->frame_blocked_in = 1;
 if (link->srcpad->request_frame)
 ret = link->srcpad->request_frame(link);
-else if (link->src->inputs[0])
-ret = ff_request_frame(link->src->inputs[0]);
+else if (link->src->inputs[input_index])
+ret = ff_request_frame(link->src->inputs[input_index]);
 if (ret < 0) {
 if (ret != AVERROR(EAGAIN) && ret != link->status_in)
 ff_avfilter_link_set_in_status(link, ret, 
guess_status_pts(link->src, ret, link->time_base));
@@ -1171,6 +1171,14 @@ static int forward_status_change(AVFilterContext 
*filter, AVFilterLink *in)
 {
 unsigned out = 0, progress = 0;
 int ret;
+int input_index = 0;
+
+for (int i = 0; i < in->dst->nb_inputs; i++) {
+if (>dst->input_pads[i] == in->dstpad) {
+input_index = i;
+break;
+}
+}
 
 av_assert0(!in->status_out);
 if (!filter->nb_outputs) {
@@ -1180,7 +1188,7 @@ static int forward_status_change(AVFilterContext *filter, 
AVFilterLink *in)
 while (!in->status_out) {
 if (!filter->outputs[out]->status_in) {
 progress++;
-ret = ff_request_frame_to_filter(filter->outputs[out]);
+ret = ff_request_frame_to_filter(filter->outputs[out], 
input_index);
 if (ret < 0)
 return ret;
 }
@@ -1217,7 +1225,7 @@ static int ff_filter_activate_default(AVFilterContext 
*filter)
 for (i = 0; i < filter->nb_outputs; i++) {
 if (filter->outputs[i]->frame_wanted_out &&
 !filter->outputs[i]->frame_blocked_in) {
-return ff_request_frame_to_filter(filter->outputs[i]);
+return ff_request_frame_to_filter(filter->outputs[i], 0);
 }
 }
 return FFERROR_NOT_READY;
-- 
ffmpeg-codebot

___
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 v9 07/25] avcodec/subtitles: Replace deprecated enum values

2022-10-25 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/ass.h   | 2 +-
 libavcodec/assdec.c| 2 +-
 libavcodec/dvbsubdec.c | 2 +-
 libavcodec/dvdsubdec.c | 2 +-
 libavcodec/dvdsubenc.c | 2 +-
 libavcodec/pgssubdec.c | 2 +-
 libavcodec/xsubdec.c   | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/ass.h b/libavcodec/ass.h
index 8bc13d7ab8..43c5ad651a 100644
--- a/libavcodec/ass.h
+++ b/libavcodec/ass.h
@@ -83,7 +83,7 @@ static inline int avpriv_ass_add_rect(AVSubtitle *sub, const 
char *dialog,
 rects[sub->num_rects]   = av_mallocz(sizeof(*rects[0]));
 if (!rects[sub->num_rects])
 return AVERROR(ENOMEM);
-rects[sub->num_rects]->type = SUBTITLE_ASS;
+rects[sub->num_rects]->type = AV_SUBTITLE_FMT_ASS;
 ass_str = avpriv_ass_get_dialog(readorder, layer, style, speaker, dialog);
 if (!ass_str)
 return AVERROR(ENOMEM);
diff --git a/libavcodec/assdec.c b/libavcodec/assdec.c
index 2571118ee9..a274d7e92e 100644
--- a/libavcodec/assdec.c
+++ b/libavcodec/assdec.c
@@ -53,7 +53,7 @@ static int ass_decode_frame(AVCodecContext *avctx, AVSubtitle 
*sub,
 if (!sub->rects[0])
 return AVERROR(ENOMEM);
 sub->num_rects = 1;
-sub->rects[0]->type = SUBTITLE_ASS;
+sub->rects[0]->type = AV_SUBTITLE_FMT_ASS;
 sub->rects[0]->ass  = av_strdup(avpkt->data);
 if (!sub->rects[0]->ass)
 return AVERROR(ENOMEM);
diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index bcc607d1d7..c864ba3fb6 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -796,7 +796,7 @@ static int save_subtitle_set(AVCodecContext *avctx, 
AVSubtitle *sub, int *got_ou
 rect->w = region->width;
 rect->h = region->height;
 rect->nb_colors = (1 << region->depth);
-rect->type  = SUBTITLE_BITMAP;
+rect->type  = AV_SUBTITLE_FMT_BITMAP;
 rect->linesize[0] = region->width;
 
 clut = get_clut(ctx, region->clut);
diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index a5da0d7b08..bf97b916c9 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -405,7 +405,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, 
AVSubtitle *sub_header,
 sub_header->rects[0]->y = y1;
 sub_header->rects[0]->w = w;
 sub_header->rects[0]->h = h;
-sub_header->rects[0]->type = SUBTITLE_BITMAP;
+sub_header->rects[0]->type = AV_SUBTITLE_FMT_BITMAP;
 sub_header->rects[0]->linesize[0] = w;
 sub_header->rects[0]->flags = is_menu ? 
AV_SUBTITLE_FLAG_FORCED : 0;
 }
diff --git a/libavcodec/dvdsubenc.c b/libavcodec/dvdsubenc.c
index 0874aaa02d..624e21c000 100644
--- a/libavcodec/dvdsubenc.c
+++ b/libavcodec/dvdsubenc.c
@@ -269,7 +269,7 @@ static int encode_dvd_subtitles(AVCodecContext *avctx,
 if (rects == 0 || !h->rects)
 return AVERROR(EINVAL);
 for (i = 0; i < rects; i++)
-if (h->rects[i]->type != SUBTITLE_BITMAP) {
+if (h->rects[i]->type != AV_SUBTITLE_FMT_BITMAP) {
 av_log(avctx, AV_LOG_ERROR, "Bitmap subtitle required\n");
 return AVERROR(EINVAL);
 }
diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
index 5f76f12615..65ba3ad261 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -534,7 +534,7 @@ static int display_end_segment(AVCodecContext *avctx, 
AVSubtitle *sub,
 if (!rect)
 return AVERROR(ENOMEM);
 sub->rects[sub->num_rects++] = rect;
-rect->type = SUBTITLE_BITMAP;
+rect->type = AV_SUBTITLE_FMT_BITMAP;
 
 /* Process bitmap */
 object = find_object(ctx->presentation.objects[i].id, >objects);
diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c
index f86b7c58e7..1b167e1d0a 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -107,7 +107,7 @@ static int decode_frame(AVCodecContext *avctx, AVSubtitle 
*sub,
 sub->num_rects = 1;
 rect->x = x; rect->y = y;
 rect->w = w; rect->h = h;
-rect->type = SUBTITLE_BITMAP;
+rect->type = AV_SUBTITLE_FMT_BITMAP;
 rect->linesize[0] = w;
 rect->data[0] = av_malloc(w * h);
 rect->nb_colors = 4;
-- 
ffmpeg-codebot

___
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 v9 10/25] avfilter/avfilter: Handle subtitle frames

2022-10-25 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 libavfilter/avfilter.c  | 20 +---
 libavfilter/avfilter.h  | 11 +++
 libavfilter/avfiltergraph.c |  5 +
 libavfilter/formats.c   | 16 
 libavfilter/formats.h   |  3 +++
 libavfilter/internal.h  | 18 +++---
 6 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index e49d76c14a..b40a2fc7cd 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -54,7 +54,8 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end)
 ref->linesize[0], ref->linesize[1], ref->linesize[2], 
ref->linesize[3],
 ref->pts, ref->pkt_pos);
 
-if (ref->width) {
+switch(ref->type) {
+case AVMEDIA_TYPE_VIDEO:
 ff_tlog(ctx, " a:%d/%d s:%dx%d i:%c iskey:%d type:%c",
 ref->sample_aspect_ratio.num, ref->sample_aspect_ratio.den,
 ref->width, ref->height,
@@ -62,8 +63,8 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end)
 ref->top_field_first ? 'T' : 'B',/* Top / Bottom */
 ref->key_frame,
 av_get_picture_type_char(ref->pict_type));
-}
-if (ref->nb_samples) {
+break;
+case AVMEDIA_TYPE_AUDIO:
 AVBPrint bprint;
 
 av_bprint_init(, 1, AV_BPRINT_SIZE_UNLIMITED);
@@ -73,6 +74,7 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end)
 ref->nb_samples,
 ref->sample_rate);
 av_bprint_finalize(, NULL);
+break;
 }
 
 ff_tlog(ctx, "]%s", end ? "\n" : "");
@@ -356,6 +358,14 @@ int avfilter_config_links(AVFilterContext *filter)
 
 if (!link->time_base.num && !link->time_base.den)
 link->time_base = (AVRational) {1, link->sample_rate};
+
+break;
+
+case AVMEDIA_TYPE_SUBTITLE:
+if (!link->time_base.num && !link->time_base.den)
+link->time_base = inlink ? inlink->time_base : 
AV_TIME_BASE_Q;
+
+break;
 }
 
 if (link->src->nb_inputs && link->src->inputs[0]->hw_frames_ctx &&
@@ -1023,6 +1033,10 @@ int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
 av_assert1(frame->width   == link->w);
 av_assert1(frame->height   == link->h);
 }
+} else if (link->type == AVMEDIA_TYPE_SUBTITLE) {
+if (frame->format != link->format) {
+av_log(link->dst, AV_LOG_WARNING, "Subtitle format change from %d 
to %d\n", link->format, frame->format);
+}
 } else {
 if (frame->format != link->format) {
 av_log(link->dst, AV_LOG_ERROR, "Format change is not 
supported\n");
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 6d68ebece4..82f6b21520 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -45,6 +45,7 @@
 #include "libavutil/log.h"
 #include "libavutil/samplefmt.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/subfmt.h"
 #include "libavutil/rational.h"
 
 #include "libavfilter/version_major.h"
@@ -356,6 +357,12 @@ typedef struct AVFilter {
  * and outputs use the same sample rate and channel count/layout.
  */
 const enum AVSampleFormat *samples_list;
+/**
+ * Analogous to pixels, but delimited by AV_SUBTITLE_FMT_NONE
+ * and restricted to filters that only have AVMEDIA_TYPE_SUBTITLE
+ * inputs and outputs.
+ */
+const enum AVSubtitleType *subs_list;
 /**
  * Equivalent to { pix_fmt, AV_PIX_FMT_NONE } as pixels_list.
  */
@@ -364,6 +371,10 @@ typedef struct AVFilter {
  * Equivalent to { sample_fmt, AV_SAMPLE_FMT_NONE } as samples_list.
  */
 enum AVSampleFormat sample_fmt;
+/**
+ * Equivalent to { sub_fmt, AV_SUBTITLE_FMT_NONE } as subs_list.
+ */
+enum AVSubtitleType sub_fmt;
 } formats;
 
 int priv_size;  ///< size of private data to allocate for the filter
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 53f468494d..f7547467f0 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -309,6 +309,8 @@ static int filter_link_check_formats(void *log, 
AVFilterLink *link, AVFilterForm
 return ret;
 break;
 
+case AVMEDIA_TYPE_SUBTITLE:
+return 0;
 default:
 av_assert0(!"reached");
 }
@@ -439,6 +441,9 @@ static int query_formats(AVFilterGraph *graph, void 
*log_ctx)
 if (!link)
 continue;
 
+if (link->type == AVMEDIA_TYPE_SUBTITLE)
+continue;
+
 neg = ff_filter_get_negotiation(link);
 av_assert0(neg);
 for (neg_step = 1; neg_step < neg->nb_mergers; neg_step++) {
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index 

[FFmpeg-devel] [PATCH v9 09/25] avfilter/subtitles: Add subtitles.c for subtitle frame allocation

2022-10-25 Thread softworkz
From: softworkz 

Analog to avfilter/video.c and avfilter/audio.c

Signed-off-by: softworkz 
---
 libavfilter/Makefile|  1 +
 libavfilter/avfilter.c  |  4 +++
 libavfilter/internal.h  |  1 +
 libavfilter/subtitles.c | 63 +
 libavfilter/subtitles.h | 44 
 5 files changed, 113 insertions(+)
 create mode 100644 libavfilter/subtitles.c
 create mode 100644 libavfilter/subtitles.h

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index ff2a06c262..6db90028e0 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -21,6 +21,7 @@ OBJS = allfilters.o   
  \
framequeue.o \
graphdump.o  \
graphparser.o\
+   subtitles.o  \
version.o\
video.o  \
 
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index cc5505e65b..e49d76c14a 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -43,6 +43,7 @@
 #include "formats.h"
 #include "framepool.h"
 #include "internal.h"
+#include "subtitles.h"
 
 static void tlog_ref(void *ctx, AVFrame *ref, int end)
 {
@@ -1462,6 +1463,9 @@ int ff_inlink_make_frame_writable(AVFilterLink *link, 
AVFrame **rframe)
 case AVMEDIA_TYPE_AUDIO:
 out = ff_get_audio_buffer(link, frame->nb_samples);
 break;
+case AVMEDIA_TYPE_SUBTITLE:
+out = ff_get_subtitles_buffer(link, link->format);
+break;
 default:
 return AVERROR(EINVAL);
 }
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index aaf2c6c584..1a0752e4ee 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -89,6 +89,7 @@ struct AVFilterPad {
 union {
 AVFrame *(*video)(AVFilterLink *link, int w, int h);
 AVFrame *(*audio)(AVFilterLink *link, int nb_samples);
+AVFrame *(*subtitle)(AVFilterLink *link, int format);
 } get_buffer;
 
 /**
diff --git a/libavfilter/subtitles.c b/libavfilter/subtitles.c
new file mode 100644
index 00..951bfd612c
--- /dev/null
+++ b/libavfilter/subtitles.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/common.h"
+
+#include "subtitles.h"
+#include "avfilter.h"
+#include "internal.h"
+
+
+AVFrame *ff_null_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+return ff_get_subtitles_buffer(link->dst->outputs[0], format);
+}
+
+AVFrame *ff_default_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+AVFrame *frame;
+
+frame = av_frame_alloc();
+if (!frame)
+return NULL;
+
+frame->format = format;
+frame->type = AVMEDIA_TYPE_SUBTITLE;
+
+if (av_frame_get_buffer2(frame, 0) < 0) {
+av_frame_free();
+return NULL;
+}
+
+return frame;
+}
+
+AVFrame *ff_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+AVFrame *ret = NULL;
+
+if (link->dstpad->get_buffer.subtitle)
+ret = link->dstpad->get_buffer.subtitle(link, format);
+
+if (!ret)
+ret = ff_default_get_subtitles_buffer(link, format);
+
+return ret;
+}
diff --git a/libavfilter/subtitles.h b/libavfilter/subtitles.h
new file mode 100644
index 00..4a9115126e
--- /dev/null
+++ b/libavfilter/subtitles.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of 

[FFmpeg-devel] [PATCH v9 05/25] avfilter/subtitles: Update vf_subtitles to use new decoding api

2022-10-25 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 libavfilter/vf_subtitles.c | 67 ++
 1 file changed, 54 insertions(+), 13 deletions(-)

diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
index 82e140e986..0ae156ad07 100644
--- a/libavfilter/vf_subtitles.c
+++ b/libavfilter/vf_subtitles.c
@@ -36,14 +36,12 @@
 # include "libavformat/avformat.h"
 #endif
 #include "libavutil/avstring.h"
-#include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 #include "libavutil/parseutils.h"
 #include "drawutils.h"
 #include "avfilter.h"
 #include "internal.h"
 #include "formats.h"
-#include "video.h"
 
 typedef struct AssContext {
 const AVClass *class;
@@ -304,8 +302,42 @@ static int attachment_is_font(AVStream * st)
 return 0;
 }
 
+static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, 
AVPacket *pkt)
+{
+int ret;
+
+*got_frame = 0;
+
+if (pkt) {
+ret = avcodec_send_packet(avctx, pkt);
+// In particular, we don't expect AVERROR(EAGAIN), because we read all
+// decoded frames with avcodec_receive_frame() until done.
+if (ret < 0 && ret != AVERROR_EOF)
+return ret;
+}
+
+ret = avcodec_receive_frame(avctx, frame);
+if (ret < 0 && ret != AVERROR(EAGAIN))
+return ret;
+if (ret >= 0)
+*got_frame = 1;
+
+return 0;
+}
+
 AVFILTER_DEFINE_CLASS(subtitles);
 
+static enum AVSubtitleType get_subtitle_format(const AVCodecDescriptor 
*codec_descriptor)
+{
+if(codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
+return AV_SUBTITLE_FMT_BITMAP;
+
+if(codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
+return AV_SUBTITLE_FMT_ASS;
+
+return AV_SUBTITLE_FMT_UNKNOWN;
+}
+
 static av_cold int init_subtitles(AVFilterContext *ctx)
 {
 int j, ret, sid;
@@ -318,6 +350,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
 AVStream *st;
 AVPacket pkt;
 AssContext *ass = ctx->priv;
+enum AVSubtitleType subtitle_format;
 
 /* Init libass */
 ret = init(ctx);
@@ -398,13 +431,17 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
 ret = AVERROR_DECODER_NOT_FOUND;
 goto end;
 }
+
 dec_desc = avcodec_descriptor_get(st->codecpar->codec_id);
-if (dec_desc && !(dec_desc->props & AV_CODEC_PROP_TEXT_SUB)) {
+subtitle_format = get_subtitle_format(dec_desc);
+
+if (subtitle_format != AV_SUBTITLE_FMT_ASS) {
 av_log(ctx, AV_LOG_ERROR,
-   "Only text based subtitles are currently supported\n");
-ret = AVERROR_PATCHWELCOME;
+   "Only text based subtitles are supported by this filter\n");
+ret = AVERROR_INVALIDDATA;
 goto end;
 }
+
 if (ass->charenc)
 av_dict_set(_opts, "sub_charenc", ass->charenc, 0);
 
@@ -460,27 +497,31 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
   dec_ctx->subtitle_header_size);
 while (av_read_frame(fmt, ) >= 0) {
 int i, got_subtitle;
-AVSubtitle sub = {0};
+AVFrame *sub = av_frame_alloc();
+if (!sub) {
+ret = AVERROR(ENOMEM);
+goto end;
+}
 
 if (pkt.stream_index == sid) {
-ret = avcodec_decode_subtitle2(dec_ctx, , _subtitle, );
+ret = decode(dec_ctx, sub, _subtitle, );
 if (ret < 0) {
 av_log(ctx, AV_LOG_WARNING, "Error decoding: %s (ignored)\n",
av_err2str(ret));
 } else if (got_subtitle) {
-const int64_t start_time = av_rescale_q(sub.pts, 
AV_TIME_BASE_Q, av_make_q(1, 1000));
-const int64_t duration   = sub.end_display_time;
-for (i = 0; i < sub.num_rects; i++) {
-char *ass_line = sub.rects[i]->ass;
+const int64_t start_time = 
av_rescale_q(sub->subtitle_timing.start_pts, AV_TIME_BASE_Q, av_make_q(1, 
1000));
+const int64_t duration   = 
av_rescale_q(sub->subtitle_timing.duration, AV_TIME_BASE_Q, av_make_q(1, 1000));
+for (i = 0; i < sub->num_subtitle_areas; i++) {
+char *ass_line = sub->subtitle_areas[i]->ass;
 if (!ass_line)
-break;
+continue;
 ass_process_chunk(ass->track, ass_line, strlen(ass_line),
   start_time, duration);
 }
 }
 }
 av_packet_unref();
-avsubtitle_free();
+av_frame_free();
 }
 
 end:
-- 
ffmpeg-codebot

___
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 v9 04/25] avcodec/libzvbi: set subtitle type

2022-10-25 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/libzvbi-teletextdec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/libzvbi-teletextdec.c b/libavcodec/libzvbi-teletextdec.c
index 45e30eb01c..486aa1724e 100644
--- a/libavcodec/libzvbi-teletextdec.c
+++ b/libavcodec/libzvbi-teletextdec.c
@@ -751,10 +751,13 @@ static int teletext_init_decoder(AVCodecContext *avctx)
 
 switch (ctx->format_id) {
 case 0:
+avctx->subtitle_type = AV_SUBTITLE_FMT_BITMAP;
 return 0;
 case 1:
+avctx->subtitle_type = AV_SUBTITLE_FMT_ASS;
 return ff_ass_subtitle_header_default(avctx);
 case 2:
+avctx->subtitle_type = AV_SUBTITLE_FMT_ASS;
 return my_ass_subtitle_header(avctx);
 }
 return AVERROR_BUG;
-- 
ffmpeg-codebot

___
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 v9 03/25] avcodec/subtitles: Introduce new frame-based subtitle decoding API

2022-10-25 Thread softworkz
From: softworkz 

- Modify avcodec_send_packet() to support subtitles via the regular
  frame based decoding API
- Add decode_subtitle_shim() which takes subtitle frames,
  and serves as a compatibility shim to the legacy subtitle decoding
  API until all subtitle decoders are migrated to the frame-based API
- Add additional methods for conversion between old and new API

Signed-off-by: softworkz 
---
 libavcodec/avcodec.c  |   8 ++
 libavcodec/avcodec.h  |  10 ++-
 libavcodec/decode.c   |  60 --
 libavcodec/internal.h |  18 +
 libavcodec/utils.c| 184 ++
 5 files changed, 271 insertions(+), 9 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index a85d3c2309..3518dd2185 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -350,6 +350,14 @@ FF_ENABLE_DEPRECATION_WARNINGS
 goto free_and_end;
 }
 
+// Set the subtitle type from the codec descriptor in case the decoder 
hasn't done itself
+if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && avctx->subtitle_type 
== AV_SUBTITLE_FMT_UNKNOWN) {
+if(avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
+avctx->subtitle_type = AV_SUBTITLE_FMT_BITMAP;
+if(avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
+ avctx->subtitle_type = AV_SUBTITLE_FMT_ASS;
+}
+
 #if FF_API_AVCTX_TIMEBASE
 if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
 avctx->time_base = av_inv_q(av_mul_q(avctx->framerate, 
(AVRational){avctx->ticks_per_frame, 1}));
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index bf06b01e22..68b588861f 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1700,7 +1700,7 @@ typedef struct AVCodecContext {
 
 /**
  * Header containing style information for text subtitles.
- * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
+ * For AV_SUBTITLE_FMT_ASS subtitle type, it should contain the whole ASS
  * [Script Info] and [V4+ Styles] section, plus the [Events] line and
  * the Format line following. It shouldn't include any Dialogue line.
  * - encoding: Set/allocated/freed by user (before avcodec_open2())
@@ -2058,6 +2058,8 @@ typedef struct AVCodecContext {
  * The decoder can then override during decoding as needed.
  */
 AVChannelLayout ch_layout;
+
+enum AVSubtitleType subtitle_type;
 } AVCodecContext;
 
 /**
@@ -2434,7 +2436,10 @@ int avcodec_close(AVCodecContext *avctx);
  * Free all allocated data in the given subtitle struct.
  *
  * @param sub AVSubtitle to free.
+ *
+ * @deprecated Use the regular frame based encode and decode APIs instead.
  */
+attribute_deprecated
 void avsubtitle_free(AVSubtitle *sub);
 
 /**
@@ -2533,7 +2538,10 @@ enum AVChromaLocation avcodec_chroma_pos_to_enum(int 
xpos, int ypos);
  * must be freed with avsubtitle_free if *got_sub_ptr is set.
  * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, 
otherwise, it is nonzero.
  * @param[in] avpkt The input AVPacket containing the input buffer.
+ *
+ * @deprecated Use the new decode API (avcodec_send_packet, 
avcodec_receive_frame) instead.
  */
+attribute_deprecated
 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
 int *got_sub_ptr,
 AVPacket *avpkt);
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6be2d3d6ed..6a4702807a 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -634,6 +634,39 @@ FF_ENABLE_DEPRECATION_WARNINGS
 return ret;
 }
 
+static int decode_subtitle2_priv(AVCodecContext *avctx, AVSubtitle *sub,
+ int *got_sub_ptr, AVPacket *avpkt);
+
+static int decode_subtitle_shim(AVCodecContext *avctx, AVFrame *frame, 
AVPacket *avpkt)
+{
+int ret, got_sub_ptr = 0;
+AVSubtitle subtitle = { 0 };
+
+if (frame->buf[0])
+return AVERROR(EAGAIN);
+
+av_frame_unref(frame);
+
+ret = decode_subtitle2_priv(avctx, , _sub_ptr, avpkt);
+
+if (ret >= 0 && got_sub_ptr) {
+frame->type = AVMEDIA_TYPE_SUBTITLE;
+frame->format = subtitle.format;
+ret = av_frame_get_buffer2(frame, 0);
+
+if (ret >= 0)
+ret = ff_frame_put_subtitle(frame, );
+
+frame->width = avctx->width;
+frame->height = avctx->height;
+frame->pkt_dts = avpkt->dts;
+}
+
+avsubtitle_free();
+
+return ret;
+}
+
 int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const 
AVPacket *avpkt)
 {
 AVCodecInternal *avci = avctx->internal;
@@ -648,6 +681,13 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext 
*avctx, const AVPacke
 if (avpkt && !avpkt->size && avpkt->data)
 return AVERROR(EINVAL);
 
+if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE)
+   // this does not exactly implement the 

[FFmpeg-devel] [PATCH v9 02/25] avutil/frame: Prepare AVFrame for subtitle handling

2022-10-25 Thread softworkz
From: softworkz 

Root commit for adding subtitle filtering capabilities.
In detail:

- Add type (AVMediaType) field to AVFrame
  Replaces previous way of distinction which was based on checking
  width and height to determine whether a frame is audio or video
- Add subtitle fields to AVFrame
- Add new struct AVSubtitleArea, similar to AVSubtitleRect, but
  different allocation logic. Cannot and must not be used
  interchangeably, hence the new struct

Signed-off-by: softworkz 
---
 libavutil/Makefile |   1 +
 libavutil/frame.c  | 206 +
 libavutil/frame.h  |  85 ++-
 libavutil/subfmt.c |  45 ++
 libavutil/subfmt.h |  47 +++
 5 files changed, 363 insertions(+), 21 deletions(-)
 create mode 100644 libavutil/subfmt.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 74380cf917..4ab4fcb01b 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -165,6 +165,7 @@ OBJS = adler32.o
\
slicethread.o\
spherical.o  \
stereo3d.o   \
+   subfmt.o \
threadmessage.o  \
time.o   \
timecode.o   \
diff --git a/libavutil/frame.c b/libavutil/frame.c
index de4ad1f94d..230673e4e1 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -26,6 +26,7 @@
 #include "imgutils.h"
 #include "mem.h"
 #include "samplefmt.h"
+#include "subfmt.h"
 #include "hwcontext.h"
 
 #if FF_API_OLD_CHANNEL_LAYOUT
@@ -52,6 +53,9 @@ const char *av_get_colorspace_name(enum AVColorSpace val)
 return name[val];
 }
 #endif
+
+static int frame_copy_subtitles(AVFrame *dst, const AVFrame *src, int 
copy_data);
+
 static void get_frame_defaults(AVFrame *frame)
 {
 memset(frame, 0, sizeof(*frame));
@@ -77,7 +81,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
 frame->colorspace  = AVCOL_SPC_UNSPECIFIED;
 frame->color_range = AVCOL_RANGE_UNSPECIFIED;
 frame->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
-frame->flags   = 0;
+frame->num_subtitle_areas  = 0;
+frame->subtitle_areas  = NULL;
+frame->subtitle_header = NULL;
+frame->repeat_sub  = 0;
+frame->subtitle_timing.start_pts = 0;
+frame->subtitle_timing.duration  = 0;
 }
 
 static void free_side_data(AVFrameSideData **ptr_sd)
@@ -256,6 +265,23 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 }
 
+static int get_subtitle_buffer(AVFrame *frame)
+{
+// Buffers in AVFrame->buf[] are not used in case of subtitle frames.
+// To accomodate with existing code, checking ->buf[0] to determine
+// whether a frame is ref-counted or has data, we're adding a 1-byte
+// buffer here, which marks the subtitle frame to contain data.
+frame->buf[0] = av_buffer_alloc(1);
+if (!frame->buf[0]) {
+av_frame_unref(frame);
+return AVERROR(ENOMEM);
+}
+
+frame->extended_data = frame->data;
+
+return 0;
+}
+
 int av_frame_get_buffer(AVFrame *frame, int align)
 {
 if (frame->format < 0)
@@ -263,23 +289,41 @@ int av_frame_get_buffer(AVFrame *frame, int align)
 
 FF_DISABLE_DEPRECATION_WARNINGS
 if (frame->width > 0 && frame->height > 0)
-return get_video_buffer(frame, align);
+frame->type = AVMEDIA_TYPE_VIDEO;
 else if (frame->nb_samples > 0 &&
  (av_channel_layout_check(>ch_layout)
 #if FF_API_OLD_CHANNEL_LAYOUT
   || frame->channel_layout || frame->channels > 0
 #endif
  ))
-return get_audio_buffer(frame, align);
+frame->type = AVMEDIA_TYPE_AUDIO;
 FF_ENABLE_DEPRECATION_WARNINGS
 
-return AVERROR(EINVAL);
+return av_frame_get_buffer2(frame, align);
+}
+
+int av_frame_get_buffer2(AVFrame *frame, int align)
+{
+if (frame->format < 0)
+return AVERROR(EINVAL);
+
+switch (frame->type) {
+case AVMEDIA_TYPE_VIDEO:
+return get_video_buffer(frame, align);
+case AVMEDIA_TYPE_AUDIO:
+return get_audio_buffer(frame, align);
+case AVMEDIA_TYPE_SUBTITLE:
+return get_subtitle_buffer(frame);
+default:
+return AVERROR(EINVAL);
+}
 }
 
 static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
 {
 int ret, i;
 
+dst->type   = src->type;
 dst->key_frame  = src->key_frame;
 dst->pict_type  = src->pict_type;
 dst->sample_aspect_ratio= src->sample_aspect_ratio;
@@ -316,6 +360,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
 dst->colorspace = src->colorspace;
 dst->color_range= src->color_range;
 dst->chroma_location= 

[FFmpeg-devel] [PATCH v9 01/25] avcodec, avutil: Move enum AVSubtitleType to avutil, add new and deprecate old values

2022-10-25 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/avcodec.h | 19 +
 libavutil/Makefile   |  1 +
 libavutil/subfmt.h   | 68 
 libavutil/version.h  |  5 ++--
 4 files changed, 73 insertions(+), 20 deletions(-)
 create mode 100644 libavutil/subfmt.h

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3edd8e2636..bf06b01e22 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -35,6 +35,7 @@
 #include "libavutil/frame.h"
 #include "libavutil/log.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/subfmt.h"
 #include "libavutil/rational.h"
 
 #include "codec.h"
@@ -2257,24 +2258,6 @@ typedef struct AVHWAccel {
  * @}
  */
 
-enum AVSubtitleType {
-SUBTITLE_NONE,
-
-SUBTITLE_BITMAP,///< A bitmap, pict will be set
-
-/**
- * Plain text, the text field must be set by the decoder and is
- * authoritative. ass and pict fields may contain approximations.
- */
-SUBTITLE_TEXT,
-
-/**
- * Formatted text, the ass field must be set by the decoder and is
- * authoritative. pict and text fields may contain approximations.
- */
-SUBTITLE_ASS,
-};
-
 #define AV_SUBTITLE_FLAG_FORCED 0x0001
 
 typedef struct AVSubtitleRect {
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 3d9c07aea8..74380cf917 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -77,6 +77,7 @@ HEADERS = adler32.h   
  \
   sha512.h  \
   spherical.h   \
   stereo3d.h\
+  subfmt.h  \
   threadmessage.h   \
   time.h\
   timecode.h\
diff --git a/libavutil/subfmt.h b/libavutil/subfmt.h
new file mode 100644
index 00..791b45519f
--- /dev/null
+++ b/libavutil/subfmt.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_SUBFMT_H
+#define AVUTIL_SUBFMT_H
+
+#include "version.h"
+
+enum AVSubtitleType {
+
+/**
+ * Subtitle format unknown.
+ */
+AV_SUBTITLE_FMT_NONE = -1,
+
+/**
+ * Subtitle format unknown.
+ */
+AV_SUBTITLE_FMT_UNKNOWN = 0,
+#if FF_API_OLD_SUBTITLES
+SUBTITLE_NONE = 0,  ///< Deprecated, use AV_SUBTITLE_FMT_NONE 
instead.
+#endif
+
+/**
+ * Bitmap area in AVSubtitleRect.data, pixfmt AV_PIX_FMT_PAL8.
+ */
+AV_SUBTITLE_FMT_BITMAP = 1,
+#if FF_API_OLD_SUBTITLES
+SUBTITLE_BITMAP = 1,///< Deprecated, use AV_SUBTITLE_FMT_BITMAP 
instead.
+#endif
+
+/**
+ * Plain text in AVSubtitleRect.text.
+ */
+AV_SUBTITLE_FMT_TEXT = 2,
+#if FF_API_OLD_SUBTITLES
+SUBTITLE_TEXT = 2,  ///< Deprecated, use AV_SUBTITLE_FMT_TEXT 
instead.
+#endif
+
+/**
+ * Text Formatted as per ASS specification, contained AVSubtitleRect.ass.
+ */
+AV_SUBTITLE_FMT_ASS = 3,
+#if FF_API_OLD_SUBTITLES
+SUBTITLE_ASS = 3,   ///< Deprecated, use AV_SUBTITLE_FMT_ASS 
instead.
+#endif
+
+AV_SUBTITLE_FMT_NB, ///< number of subtitle formats, DO NOT USE 
THIS if you want to link with shared libav* because the number of formats might 
differ between versions.
+};
+
+#endif /* AVUTIL_SUBFMT_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index cb0c928bd0..009c628e35 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,8 +79,8 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  57
-#define LIBAVUTIL_VERSION_MINOR  39
-#define LIBAVUTIL_VERSION_MICRO 101
+#define LIBAVUTIL_VERSION_MINOR  40
+#define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \
@@ -115,6 +115,7 @@
 #define FF_API_OLD_CHANNEL_LAYOUT   (LIBAVUTIL_VERSION_MAJOR < 58)
 #define FF_API_AV_FOPEN_UTF8(LIBAVUTIL_VERSION_MAJOR < 58)
 

[FFmpeg-devel] [PATCH v9 00/25] Subtitle Filtering 2022

2022-10-25 Thread ffmpegagent

Subtitle Filtering 2022
===

This is a substantial update to the earlier subtitle filtering patch series.
A primary goal has been to address others' concerns as much as possible on
one side and to provide more clarity and control over the way things are
working. Clarity is is specifically important to allow for a better
understanding of the need for a subtitle start pts value that can be
different from the frame's pts value. This is done by refactoring the
subtitle timing fields in AVFrame, adding a frame field to indicate repeated
subtitle frames, and finally the full removal of the heartbeat
functionality, replaced by a new 'subfeed' filter that provides different
modes for arbitrating subtitle frames in a filter graph. Finally, each
subtitle filter's documentation has been amended by a section describing the
filter's timeline behavior (in v3 update).


Subtitle Filtering Demos


I published a demonstration of subtitle filtering capabilities with OCR,
text and bitmap subtitle manipulation involved: Demo 1: Text-Manipulation
with Bitmap Subtitles
[https://github.com/softworkz/SubtitleFilteringDemos/tree/master/Demo1]


v9
==

 * Cleared the cc recipient list
 * Resending after e-mail error


v8
==

 * Rebased and adapted to upstream changes


v7
==

 * Revert loglevel change
 * snull: propagate format
 * fftools/ffmpeg: ensure monotonic (frame-)pts values for subtitles


v6 - Fix assertion errors
=

 * text2graphicsub: fix null point on uninit after error
 * strim: propagate width and height
 * avfilter: add default propagation time_base from inlink to outlink


v5 - Conversion to Graphic Subtitles, and other enhancements


 * I'm glad to announce that Traian (@tcoza) has joined the project and
   contributed a new 'text2graphicsub' filter to convert text subtitles to
   graphic subtitles, which can in turn be encoded as dvd, dvb or x-subs
   (and any other encoder for graphic subs that might be added in the
   future). This filter closes the last open "gap" in subtitle processing.
 * stripstyles filter: now allows very fine-grained control over which ASS
   style codes should be preserved or stripped
 * stripstyles: do not drop dialog margin values
 * subfeed filter: eliminates duplicate frames with duplicate start times
   when 'fix_overlap' is specified
 * textmod: do not drop effect values
 * graphicsub2text: reduce font size jitter
 * ass_split: add function to selectively preserve elements when splitting
 * add strim, snull and ssink and further unify subtitle frame handling with
   audio and video
 * ffmpeg_filter: get simple filter notation working for subtitles


v4 - Quality Improvements
=

 * finally an updated version
 * includes many improvements from internal testing
 * all FATE tests passed
 * all example commands from the docs verified to work
 * can't list all the detail changes..
 * I have left out the extra commits which can be handled separately, just
   in case somebody wonders why these are missing:
   * avcodec/webvttenc: Don't encode drawing codes and empty lines
   * avcodec/webvttenc: convert hard-space tags to  
   * avutil/ass_split: Add parsing of hard-space tags (\h)
   * avutil/ass_split: Treat all content in curly braces as hidden
   * avutil/ass_split: Fix ass parsing of style codes with comments


v3 - Rebase
===

due to merge conflicts - apologies.


Changes in v2
=

 * added .gitattributes file to enforce binary diffs for the test refs that
   cannot be applied when being sent via e-mail
 * perform filter graph re-init due to subtitle "frame size" change only
   when the size was unknown before and not set via -canvas_size
 * overlaytextsubs: Make sure to request frames on the subtitle input
 * avfilter/splitcc: Start parsing cc data on key frames only
 * avcodec/webvttenc: Don't encode ass drawing codes and empty lines
 * stripstyles: fix mem leak
 * gs2t: improve color detection
 * gs2t: empty frames must not be skipped
 * subfeed: fix name
 * textmod: preserve margins
 * added .gitattributes file to enforce binary diffs for the test refs that
   cannot be applied when being sent via e-mail
 * perform filter graph re-init due to subtitle "frame size" change only
   when the size was unknown before and not set via -canvas_size
 * avcodec/dvbsubdec: Fix conditions for fallback to default resolution
 * Made changes suggested by Andreas
 * Fixed failing command line reported by Michael

Changes from previous version v24:


AVFrame
===

 * Removed sub_start_time The start time is now added to the subtitle
   start_pts during decoding The sub_end_time field is adjusted accordingly
 * Renamed sub_end_time to duration which it is effectively after removing
   the start_time
 * Added a sub-struct 'subtitle_timing' to av frame Contains subtitle_pts
   renamed to 'subtitle_timing.start_pts' and 

Re: [FFmpeg-devel] [PATCH] avcodec/mss2: calculate draw region and revise split position

2022-10-25 Thread Anton Khirnov
Quoting Peter Ross (2022-10-20 10:59:25)
> for videos with wmv9 rectangles, the region drawn by ff_mss12_decode_rect
> may be less than the entire video area. the wmv9 rectangles are used to
> calculate the ff_mss12_decode_rect draw region.
> 
> Fixes tickets #3255 and #4043

Would be nice to have a test.

-- 
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".


Re: [FFmpeg-devel] [PATCH v5] libavfilter/x86/vf_convolution: add sobel filter optimization and unit test with intel AVX512 VNNI

2022-10-25 Thread Wang, Bin
-Original Message-
From: Wang, Bin 
Sent: Tuesday, September 20, 2022 6:33 PM
To: ffmpeg-devel@ffmpeg.org
Cc: Wang, Bin 
Subject: [FFmpeg-devel] [PATCH v5] libavfilter/x86/vf_convolution: add sobel 
filter optimization and unit test with intel AVX512 VNNI

From: bwang30 

This commit enabled assembly code with intel AVX512 VNNI and added unit test 
for sobel filter

sobel_c: 4537
sobel_avx512icl 2136

Signed-off-by: bwang30 
---
 libavfilter/convolution.h |  74 +
 libavfilter/vf_convolution.c  |  91 +++-
 libavfilter/x86/vf_convolution.asm| 147 ++
 libavfilter/x86/vf_convolution_init.c |  18 
 tests/checkasm/Makefile   |   1 +
 tests/checkasm/checkasm.c |   3 +
 tests/checkasm/checkasm.h |   1 +
 tests/checkasm/vf_convolution.c   | 103 ++
 8 files changed, 360 insertions(+), 78 deletions(-)  create mode 100644 
tests/checkasm/vf_convolution.c

diff --git a/libavfilter/convolution.h b/libavfilter/convolution.h index 
88aabe9a20..e44bfb5da8 100644
--- a/libavfilter/convolution.h
+++ b/libavfilter/convolution.h
@@ -21,6 +21,7 @@
 #ifndef AVFILTER_CONVOLUTION_H
 #define AVFILTER_CONVOLUTION_H
 #include "avfilter.h"
+#include "libavutil/intreadwrite.h"
 
 enum MatrixMode {
 MATRIX_SQUARE,
@@ -61,4 +62,77 @@ typedef struct ConvolutionContext {  } ConvolutionContext;
 
 void ff_convolution_init_x86(ConvolutionContext *s);
+void ff_sobel_init_x86(ConvolutionContext *s, int depth, int 
+nb_planes);
+
+static void setup_3x3(int radius, const uint8_t *c[], const uint8_t *src, int 
stride,
+  int x, int w, int y, int h, int bpc) {
+int i;
+
+for (i = 0; i < 9; i++) {
+int xoff = FFABS(x + ((i % 3) - 1));
+int yoff = FFABS(y + (i / 3) - 1);
+
+xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
+yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
+
+c[i] = src + xoff * bpc + yoff * stride;
+}
+}
+
+static void filter_sobel(uint8_t *dst, int width,
+ float scale, float delta, const int *const matrix,
+ const uint8_t *c[], int peak, int radius,
+ int dstride, int stride, int size) {
+const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
+const uint8_t *c3 = c[3], *c5 = c[5];
+const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
+int x;
+
+for (x = 0; x < width; x++) {
+float suma = c0[x] * -1 + c1[x] * -2 + c2[x] * -1 +
+ c6[x] *  1 + c7[x] *  2 + c8[x] *  1;
+float sumb = c0[x] * -1 + c2[x] *  1 + c3[x] * -2 +
+ c5[x] *  2 + c6[x] * -1 + c8[x] *  1;
+
+dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
+}
+}
+
+static void filter16_sobel(uint8_t *dstp, int width,
+   float scale, float delta, const int *const matrix,
+   const uint8_t *c[], int peak, int radius,
+   int dstride, int stride, int size) {
+uint16_t *dst = (uint16_t *)dstp;
+int x;
+
+for (x = 0; x < width; x++) {
+float suma = AV_RN16A([0][2 * x]) * -1 + AV_RN16A([1][2 * x]) * -2 
+ AV_RN16A([2][2 * x]) * -1 +
+ AV_RN16A([6][2 * x]) *  1 + AV_RN16A([7][2 * x]) *  2 
+ AV_RN16A([8][2 * x]) *  1;
+float sumb = AV_RN16A([0][2 * x]) * -1 + AV_RN16A([2][2 * x]) *  1 
+ AV_RN16A([3][2 * x]) * -2 +
+ AV_RN16A([5][2 * x]) *  2 + AV_RN16A([6][2 *
+ x]) * -1 + AV_RN16A([8][2 * x]) *  1;
+
+dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, 
peak);
+}
+}
+
+static av_unused void ff_sobel_init(ConvolutionContext *s, int depth, 
+int nb_planes) {
+for (int i = 0; i < 4; i++) {
+s->filter[i] = filter_sobel;
+s->copy[i] = !((1 << i) & s->planes);
+s->size[i] = 3;
+s->setup[i] = setup_3x3;
+s->rdiv[i] = s->scale;
+s->bias[i] = s->delta;
+}
+if (s->depth > 8)
+for (int i = 0; i < 4; i++)
+s->filter[i] = filter16_sobel; #if ARCH_X86_64
+ff_sobel_init_x86(s, depth, nb_planes); #endif }
 #endif
diff --git a/libavfilter/vf_convolution.c b/libavfilter/vf_convolution.c index 
9a9c099e6d..7762fa2a05 100644
--- a/libavfilter/vf_convolution.c
+++ b/libavfilter/vf_convolution.c
@@ -139,24 +139,6 @@ static void filter16_roberts(uint8_t *dstp, int width,
 }
 }
 
-static void filter16_sobel(uint8_t *dstp, int width,
-   float scale, float delta, const int *const matrix,
-   const uint8_t *c[], int peak, int radius,
-   int dstride, int stride, int size)
-{
-uint16_t *dst = (uint16_t *)dstp;
-int x;
-
-for (x = 0; x < width; x++) {
-float suma = AV_RN16A([0][2 * x]) * -1 + AV_RN16A([1][2 * x]) * -2 
+ AV_RN16A([2][2 * x]) * -1 +
- AV_RN16A([6][2 * x]) *  1 + 

Re: [FFmpeg-devel] [PATCH 4/4] sw_scale: Add specializations for hscale 16 to 19

2022-10-25 Thread Hubert Mazur
Thanks for the review.
I will fix the failing checkasm first and then take care of the minor
issues. I will try to to resend fixed versions this week.

Regards,
Hubert

On Mon, Oct 24, 2022 at 3:19 PM Martin Storsjö  wrote:

> On Mon, 17 Oct 2022, Hubert Mazur wrote:
>
> > Provide arm64 neon optimized implementations for hscale16To19 with
> > filter sizes 4, 8 and X4.
> >
> > The tests and benchmarks run on AWS Graviton 2 instances.
> > The results from a checkasm tool are shown below.
> >
> > hscale_16_to_19__fs_4_dstW_512_c: 6216.0
> > hscale_16_to_19__fs_4_dstW_512_neon: 2257.0
> > hscale_16_to_19__fs_8_dstW_512_c: 10417.7
> > hscale_16_to_19__fs_8_dstW_512_neon: 3112.5
> > hscale_16_to_19__fs_12_dstW_512_c: 14890.5
> > hscale_16_to_19__fs_12_dstW_512_neon: 3899.0
> > hscale_16_to_19__fs_16_dstW_512_c: 19006.5
> > hscale_16_to_19__fs_16_dstW_512_neon: 5341.2
> > hscale_16_to_19__fs_32_dstW_512_c: 36629.5
> > hscale_16_to_19__fs_32_dstW_512_neon: 9502.7
> > hscale_16_to_19__fs_40_dstW_512_c: 45477.5
> > hscale_16_to_19__fs_40_dstW_512_neon: 11552.0
> >
> > Signed-off-by: Hubert Mazur 
> > ---
> > libswscale/aarch64/hscale.S  | 402 +++
> > libswscale/aarch64/swscale.c |  70 +-
> > 2 files changed, 471 insertions(+), 1 deletion(-)
>
> > +void ff_hscale16to19_4_neon_asm(int shift, int16_t *_dst, int dstW,
> > +  const uint8_t *_src, const int16_t *filter,
> > +  const int32_t *filterPos, int filterSize);
> > +void ff_hscale16to19_X8_neon_asm(int shift, int16_t *_dst, int dstW,
> > +  const uint8_t *_src, const int16_t *filter,
> > +  const int32_t *filterPos, int filterSize);
> > +void ff_hscale16to19_X4_neon_asm(int shift, int16_t *_dst, int dstW,
> > +  const uint8_t *_src, const int16_t *filter,
> > +  const int32_t *filterPos, int filterSize);
> > +
> > #define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \
> > void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt(
> \
> > SwsContext *c, int16_t
> *data, \
> > @@ -43,7 +53,8 @@ void ff_hscale ## from_bpc ## to ## to_bpc ## _ ##
> filter_n ## _ ## opt( \
> > #define SCALE_FUNCS(filter_n, opt) \
> > SCALE_FUNC(filter_n,  8, 15, opt); \
> > SCALE_FUNC(filter_n, 8, 19, opt); \
> > -SCALE_FUNC(filter_n, 16, 15, opt);
> > +SCALE_FUNC(filter_n, 16, 15, opt); \
> > +SCALE_FUNC(filter_n, 16, 19, opt);
>
> So this declares the functions we're implementing as C wrappers below, and
> the manual declarations further up declare the actual asm functions?
>
> I guess that works, although it makes unnecessary extern functions. In
> such cases, we usually have the C functions be static functions, placed
> above the code that uses them. But it's not a big deal.
>
> Other than that, this patchset mostly seems fine.
>
> However, I tested the patches on x86, and the new checkasm tests do fail
> on x86 (both i386 and x86_64) - so that needs to be fixed anyway. So since
> we'll need to do a new round anyway, please do try to fix up the minor
> cosmetics I mentioned.
>
> // Martin
>
>
___
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".