Re: [FFmpeg-devel] [PATCH] avformat/aviobuf: let avio_read can retry when timeout

2022-01-13 Thread zhilizhao(赵志立)


> On Jan 14, 2022, at 12:50 PM, Wang Chuan  wrote:
> 
> I just try to use avio to read stream by http protocol.
> 
> But if the server responds too late, avio_read will return timeout, and the 
> only way I can do is close it and reopen.
> 
> Of course I can set a large timeout, but it's hard to decide which timeout 
> value is large enough.

Then don’t set it, use the default infinite value.

> 
> On 2022/1/14 11:21, "zhilizhao(赵志立)" wrote:
>> 
>>> On Jan 14, 2022, at 10:42 AM, Wang Chuan  wrote:
>>> 
>>> If we meet timeout when reading network resource, avio_read will set
>>> [eof_reached] to 1. And this prevent caller to retry since avio_read
>>> do nothing and just return if eof_reached == 1.
>> If timeout was triggered by a small ‘timeout’ setting from user, just
>> change the ‘timeout' configuration. If it was triggered by a system call,
>> it’s likely to be in a state of not recoverable. Could you share more
>> details about the issue this patch trying to solve?
>> 
>>> Signed-off-by: Wang Chuan 
>>> ---
>>> libavformat/aviobuf.c | 5 +++--
>>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>> 
>>> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
>>> index 29d4bd7510..38cb21debf 100644
>>> --- a/libavformat/aviobuf.c
>>> +++ b/libavformat/aviobuf.c
>>> @@ -580,8 +580,9 @@ static void fill_buffer(AVIOContext *s)
>>>be done without rereading data */
>>> s->eof_reached = 1;
>>> } else if (len < 0) {
>>> -s->eof_reached = 1;
>>> -s->error= len;
>>> +s->error = len;
>>> +if (s->error != AVERROR(ETIMEDOUT))
>>> +s->eof_reached = 1;
>>> } else {
>>> s->pos += len;
>>> s->buf_ptr = dst;
>>> -- 
>>> 2.29.2
>>> 
>>> ___
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>> 
>>> To unsubscribe, visit link above, or email
>>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> ___
> ffmpeg-devel 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] avformat/aviobuf: let avio_read can retry when timeout

2022-01-13 Thread Wang Chuan

I just try to use avio to read stream by http protocol.

But if the server responds too late, avio_read will return timeout, and 
the only way I can do is close it and reopen.


Of course I can set a large timeout, but it's hard to decide which 
timeout value is large enough.


On 2022/1/14 11:21, "zhilizhao(赵志立)" wrote:



On Jan 14, 2022, at 10:42 AM, Wang Chuan  wrote:

If we meet timeout when reading network resource, avio_read will set
[eof_reached] to 1. And this prevent caller to retry since avio_read
do nothing and just return if eof_reached == 1.

If timeout was triggered by a small ‘timeout’ setting from user, just
change the ‘timeout' configuration. If it was triggered by a system call,
it’s likely to be in a state of not recoverable. Could you share more
details about the issue this patch trying to solve?


Signed-off-by: Wang Chuan 
---
libavformat/aviobuf.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 29d4bd7510..38cb21debf 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -580,8 +580,9 @@ static void fill_buffer(AVIOContext *s)
be done without rereading data */
 s->eof_reached = 1;
 } else if (len < 0) {
-s->eof_reached = 1;
-s->error= len;
+s->error = len;
+if (s->error != AVERROR(ETIMEDOUT))
+s->eof_reached = 1;
 } else {
 s->pos += len;
 s->buf_ptr = dst;
--
2.29.2

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

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

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

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

___
ffmpeg-devel 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/aviobuf: let avio_read can retry when timeout

2022-01-13 Thread zhilizhao(赵志立)


> On Jan 14, 2022, at 10:42 AM, Wang Chuan  wrote:
> 
> If we meet timeout when reading network resource, avio_read will set
> [eof_reached] to 1. And this prevent caller to retry since avio_read
> do nothing and just return if eof_reached == 1.

If timeout was triggered by a small ‘timeout’ setting from user, just
change the ‘timeout' configuration. If it was triggered by a system call,
it’s likely to be in a state of not recoverable. Could you share more
details about the issue this patch trying to solve?

> 
> Signed-off-by: Wang Chuan 
> ---
> libavformat/aviobuf.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> index 29d4bd7510..38cb21debf 100644
> --- a/libavformat/aviobuf.c
> +++ b/libavformat/aviobuf.c
> @@ -580,8 +580,9 @@ static void fill_buffer(AVIOContext *s)
>be done without rereading data */
> s->eof_reached = 1;
> } else if (len < 0) {
> -s->eof_reached = 1;
> -s->error= len;
> +s->error = len;
> +if (s->error != AVERROR(ETIMEDOUT))
> +s->eof_reached = 1;
> } else {
> s->pos += len;
> s->buf_ptr = dst;
> -- 
> 2.29.2
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-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 3/3] avcodec/libopenh264enc: set iEntropyCodingModeFlag by coder option

2022-01-13 Thread lance . lmwang
On Fri, Jan 14, 2022 at 12:01:26AM +0200, Martin Storsjö wrote:
> On Thu, 13 Jan 2022, lance.lmw...@gmail.com wrote:
> 
> > From: Limin Wang 
> > 
> > ffmpeg -y -f lavfi -i testsrc -c:v libopenh264 -profile:v main -coder cavlc 
> > -frames:v 1 -bsf trace_headers -f null -
> > 
> > before the patch:
> > entropy_coding_mode_flag0 = 1
> > 
> > after the patch:
> > entropy_coding_mode_flag0 = 0
> 
> I don't understand what this bit in the commit message tries to say?
> 
> 
> Doesn't this patch have the effect, that if I only specify "-profile high",
> I'll end up with CAVLC unless I specifically pass "-coder cabac" too? If
> coder wasn't specified, I think we should still default to CABAC for
> main/high.

Sorry, I'll update the message.
it's high profile, we can't to use cavlc even if specify -coder. Yes, if haven't
set coder, it's preferable to enable cabac for high.

> 
> // Martin
> 

-- 
Thanks,
Limin Wang
___
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 2/3] avcodec/libopenh264enc: make the profile configuablable correctly

2022-01-13 Thread lance . lmwang
On Thu, Jan 13, 2022 at 11:57:36PM +0200, Martin Storsjö wrote:
> On Thu, 13 Jan 2022, lance.lmw...@gmail.com wrote:
> 
> > From: Limin Wang 
> > 
> > If the version of libopenh264 >= 1.8, we can't configured main profile as
> > expected, below is the testing cli:
> > 
> > ffmpeg -y -f lavfi -i testsrc -c:v libopenh264 -profile:v main -frames:v 1 
> > test.ts
> > It'll report:
> > [libopenh264 @ 0x5638300] Unsupported profile, select EProfileIdc 
> > PRO_BASELINE in libopenh264.
> > 
> > Signed-off-by: Limin Wang 
> > ---
> > libavcodec/libopenh264enc.c | 8 +---
> > 1 file changed, 5 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
> > index a55bef8..995ee37 100644
> > --- a/libavcodec/libopenh264enc.c
> > +++ b/libavcodec/libopenh264enc.c
> > @@ -220,26 +220,27 @@ static av_cold int svc_encode_init(AVCodecContext 
> > *avctx)
> > #endif
> > 
> > switch (s->profile) {
> > -#if OPENH264_VER_AT_LEAST(1, 8)
> > case FF_PROFILE_H264_HIGH:
> > +s->profile = PRO_HIGH;
> 
> I don't think we should reuse the s->profile field for this value here.
> 
> In practice, both FF_PROFILE_H264_HIGH and PRO_HIGH have the same values,
> but they're enums from different namespaces, so would it be clearer to use
> one variable for profiles set with FF_PROFILE_* and one with the PRO_*
> values?

Yes, I think they're same value by specs, I'll delete the assignment for PRO_* 
to make it be cleaner.

> 
> > param.iEntropyCodingModeFlag = 1;
> > av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
> > "select EProfileIdc PRO_HIGH in libopenh264.\n");
> > break;
> > -#else
> > case FF_PROFILE_H264_MAIN:
> > +s->profile = PRO_MAIN;
> > param.iEntropyCodingModeFlag = 1;
> > av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
> > "select EProfileIdc PRO_MAIN in libopenh264.\n");
> > break;
> > -#endif
> > case FF_PROFILE_H264_CONSTRAINED_BASELINE:
> > case FF_PROFILE_UNKNOWN:
> > +s->profile = PRO_BASELINE;
> > param.iEntropyCodingModeFlag = 0;
> > av_log(avctx, AV_LOG_VERBOSE, "Using CAVLC, "
> >"select EProfileIdc PRO_BASELINE in libopenh264.\n");
> > break;
> > default:
> > +s->profile = PRO_BASELINE;
> > param.iEntropyCodingModeFlag = 0;
> > av_log(avctx, AV_LOG_WARNING, "Unsupported profile, "
> >"select EProfileIdc PRO_BASELINE in libopenh264.\n");
> > @@ -251,6 +252,7 @@ static av_cold int svc_encode_init(AVCodecContext 
> > *avctx)
> > param.sSpatialLayers[0].fFrameRate  = param.fMaxFrameRate;
> > param.sSpatialLayers[0].iSpatialBitrate = param.iTargetBitrate;
> > param.sSpatialLayers[0].iMaxSpatialBitrate  = param.iMaxBitrate;
> > +param.sSpatialLayers[0].uiProfileIdc= s->profile;
> 
> So this assignment is what was missing, and was what caused the incorrect
> conclusion in d3a7bdd4ac54349aea9150a234478635d50ebd87? I think it'd be good
> to explicitly spell this out in the commit message, saying that

OK, will add the following message into commit message:
d3a7bdd4ac54349aea9150a234478635d50ebd87 was based on incorrect conclusions
because we had missed to set uiProfileIdc.

> 
> // Martin
> 

-- 
Thanks,
Limin Wang
___
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 1/3] avcodec/libopenh264enc: support for colorspace and range information

2022-01-13 Thread lance . lmwang
On Thu, Jan 13, 2022 at 11:35:32PM +0200, Martin Storsjö wrote:
> On Thu, 13 Jan 2022, lance.lmw...@gmail.com wrote:
> 
> > From: Limin Wang 
> > 
> > Signed-off-by: Limin Wang 
> > ---
> > libavcodec/libopenh264enc.c | 15 +++
> > 1 file changed, 15 insertions(+)
> > 
> > diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
> > index de4b85c..a55bef8 100644
> > --- a/libavcodec/libopenh264enc.c
> > +++ b/libavcodec/libopenh264enc.c
> > @@ -330,6 +330,21 @@ static av_cold int svc_encode_init(AVCodecContext 
> > *avctx)
> > }
> > }
> > 
> > +#if OPENH264_VER_AT_LEAST(1, 6)
> > +param.sSpatialLayers[0].uiVideoFormat = VF_UNDEF;
> > +param.sSpatialLayers[0].bVideoSignalTypePresent = true;
> 
> What does this flag do, and why do we set it unconditionally while we didn't
> use to before?
> 

OK, will update and set the flag only if bFullRange is set.

> > +if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED)
> > +param.sSpatialLayers[0].bFullRange = (avctx->color_range == 
> > AVCOL_RANGE_JPEG);
> > +
> > +param.sSpatialLayers[0].bColorDescriptionPresent = true;
> 
> Ditto - what does this do and why do we set it even if we wouldn't set any
> of the other fields?

will update and set the flag only if any the following fields are set.

> 
> // Martin
> 

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH] avformat/aviobuf: let avio_read can retry when timeout

2022-01-13 Thread Wang Chuan

If we meet timeout when reading network resource, avio_read will set
[eof_reached] to 1. And this prevent caller to retry since avio_read
do nothing and just return if eof_reached == 1.

Signed-off-by: Wang Chuan 
---
 libavformat/aviobuf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 29d4bd7510..38cb21debf 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -580,8 +580,9 @@ static void fill_buffer(AVIOContext *s)
be done without rereading data */
 s->eof_reached = 1;
 } else if (len < 0) {
-s->eof_reached = 1;
-s->error= len;
+s->error = len;
+if (s->error != AVERROR(ETIMEDOUT))
+s->eof_reached = 1;
 } else {
 s->pos += len;
 s->buf_ptr = dst;
--
2.29.2

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

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


Re: [FFmpeg-devel] [PATCH] avfilter/vf_libvmaf: update filter for libvmaf v2.0.0

2022-01-13 Thread Kyle Swanson
Hi,

On Mon, Jan 10, 2022 at 10:22 AM Andreas Rheinhardt
 wrote:
> 1. FFmpeg uses the ancient C90 rule that only allows variable
> declarations at the beginning of a block (before all statements). You
> should actually have received a compiler warning because of the above
> code (unless you use Clang, which claims to support this type of
> warning, yet doesn't).
> 2. You jump over the initializion of str_copy if the dict allocation
> fails and consequently you free an uninitialized string.

New patch attached. Fixes all of the GCC -Wdeclaration-after-statement
warnings. You're right, I didn't notice because I was building with
Clang. Andreas, I will just wait for your LGTM before merging.

Thanks,
Kyle


0001-avfilter-vf_libvmaf-update-filter-for-libvmaf-v2.0.0.patch
Description: Binary data
___
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 24/24] doc/APIchanges: update for subtitle filtering changes

2022-01-13 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 doc/APIchanges   | 24 
 libavcodec/version.h |  2 +-
 libavutil/version.h  |  2 +-
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 8df0364e4c..c8238fb008 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,30 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2021-12-05 - xx - lavc 59.15.100 - avcodec.h
+  Deprecate avcodec_encode_subtitle(), use regular encode api now
+
+2021-12-05 - xx - lavc 59.15.100 - codec_desc.h
+  Add avcodec_descriptor_get_subtitle_format()
+
+2021-12-05 - xx - lavc 59.15.100 - avcodec.h
+  Deprecate avsubtitle_free()
+  Deprecate avcodec_decode_subtitle2(), use regular decode api now
+
+2021-12-05 - xx - lavu 57.11.100 - frame.h
+  Add AVMediaType field to AVFrame
+  Add Fields for carrying subtitle data to AVFrame
+  (subtitle_areas, subtitle_header, subtitle_pts, start/end time, etc.)
+  Add av_frame_get_buffer2() and deprecate av_frame_get_buffer()
+
+2021-12-05 - xx - lavu 57.11.100 - subfmt.h
+  Add struct AVSubtitleArea (replaces AVSubtitle)
+  Add av_get_subtitle_fmt_name() and av_get_subtitle_fmt()
+
+2021-12-05 - xx - lavu 57.11.100 - subfmt.h
+  Add enum AVSubtitleType (moved from lavc), add new values, deprecate existing
+
+2021-11-xx - xx - lavfi 8.19.100 - avfilter.h
 2022-01-04 - 78dc21b123e - lavu 57.16.100 - frame.h
   Add AV_FRAME_DATA_DOVI_METADATA.
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index a46fb05f1a..b5867ad041 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  59
-#define LIBAVCODEC_VERSION_MINOR  20
+#define LIBAVCODEC_VERSION_MINOR  21
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavutil/version.h b/libavutil/version.h
index 5bf48f6304..168e24f410 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  57
-#define LIBAVUTIL_VERSION_MINOR  18
+#define LIBAVUTIL_VERSION_MINOR  19
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
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 23/24] avcodec/webvttenc: convert hard-space tags to

2022-01-13 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/webvttenc.c   |  6 ++
 tests/ref/fate/sub-webvttenc | 10 +-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c
index c0436f5739..48945dcb8e 100644
--- a/libavcodec/webvttenc.c
+++ b/libavcodec/webvttenc.c
@@ -123,6 +123,11 @@ static void webvtt_new_line_cb(void *priv, int forced)
 webvtt_print(priv, "\n");
 }
 
+static void webvtt_hard_space_cb(void *priv)
+{
+webvtt_print(priv, "");
+}
+
 static void webvtt_style_cb(void *priv, char style, int close)
 {
 if (style == 's') // strikethrough unsupported
@@ -147,6 +152,7 @@ static void webvtt_end_cb(void *priv)
 static const ASSCodesCallbacks webvtt_callbacks = {
 .text = webvtt_text_cb,
 .new_line = webvtt_new_line_cb,
+.hard_space   = webvtt_hard_space_cb,
 .style= webvtt_style_cb,
 .color= NULL,
 .font_name= NULL,
diff --git a/tests/ref/fate/sub-webvttenc b/tests/ref/fate/sub-webvttenc
index f4172dcc84..ee9de2859e 100644
--- a/tests/ref/fate/sub-webvttenc
+++ b/tests/ref/fate/sub-webvttenc
@@ -132,26 +132,26 @@ but show this: {normal text}
 \ N is a forced line break
 \ h is a hard space
 Normal spaces at the start and at the end of the line are trimmed while hard 
spaces are not trimmed.
-The line will never break automatically right before or after a hard space. :-D
+Thelinewillneverbreakautomaticallyrightbeforeorafterahardspace.:-D
 
 00:54.501 --> 00:56.500
 
- A (05 hard spaces followed by a letter)
+A (05 hard spaces followed by a letter)
 A (Normal  spaces followed by a letter)
 A (No hard spaces followed by a letter)
 
 00:56.501 --> 00:58.500
- A (05 hard spaces followed by a letter)
+A (05 hard spaces followed by a letter)
 A (Normal  spaces followed by a letter)
 A (No hard spaces followed by a letter)
 Show this: \TEST and this: \-)
 
 00:58.501 --> 01:00.500
 
-A letter followed by 05 hard spaces: A 
+A letter followed by 05 hard spaces: A
 A letter followed by normal  spaces: A
 A letter followed by no hard spaces: A
-05 hard  spaces between letters: A A
+05 hard  spaces between letters: AA
 5 normal spaces between letters: A A
 
 ^--Forced line break
-- 
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 22/24] avutil/ass_split: Add parsing of hard-space tags (\h)

2022-01-13 Thread ffmpegagent
From: softworkz 

The \h tag in ASS/SSA is indicating a non-breaking space. See
https://github.com/Aegisub/aegisite/blob/master/source/docs/3.2/
ASS_Tags.html.md

The ass_split implementation is used by almost all text subtitle
encoders and it didn't handle this tag. Interestingly, several
tests are testing for \h parsing and had incorrect reference data
for those tests.

The \h tag is specific to ASS and doesn't have any meaning outside
of ASS.
Still, the reference data for ttmlenc, textenc and webvttenc were
full of \h tags even though this tag doesn't have a meaning there.

Signed-off-by: softworkz 
---
 libavutil/ass_split.c|  7 +++
 tests/ref/fate/mov-mp4-ttml-dfxp |  8 
 tests/ref/fate/mov-mp4-ttml-stpp |  8 
 tests/ref/fate/sub-textenc   | 10 +-
 tests/ref/fate/sub-ttmlenc   |  8 
 tests/ref/fate/sub-webvttenc | 10 +-
 6 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/libavutil/ass_split.c b/libavutil/ass_split.c
index c5963351fc..30512dfc74 100644
--- a/libavutil/ass_split.c
+++ b/libavutil/ass_split.c
@@ -484,6 +484,7 @@ int avpriv_ass_split_override_codes(const ASSCodesCallbacks 
*callbacks, void *pr
 while (buf && *buf) {
 if (text && callbacks->text &&
 (sscanf(buf, "\\%1[nN]", new_line) == 1 ||
+ sscanf(buf, "\\%1[hH]", new_line) == 1 ||
  !strncmp(buf, "{\\", 2))) {
 callbacks->text(priv, text, text_len);
 text = NULL;
@@ -492,6 +493,12 @@ int avpriv_ass_split_override_codes(const 
ASSCodesCallbacks *callbacks, void *pr
 if (callbacks->new_line)
 callbacks->new_line(priv, new_line[0] == 'N');
 buf += 2;
+} else if (sscanf(buf, "\\%1[hH]", new_line) == 1) {
+if (callbacks->hard_space)
+callbacks->hard_space(priv);
+else if (callbacks->text)
+callbacks->text(priv, " ", 1);
+buf += 2;
 } else if (!strncmp(buf, "{\\", 2)) {
 buf++;
 while (*buf == '\\') {
diff --git a/tests/ref/fate/mov-mp4-ttml-dfxp b/tests/ref/fate/mov-mp4-ttml-dfxp
index e24b5d618b..e565ffa1f6 100644
--- a/tests/ref/fate/mov-mp4-ttml-dfxp
+++ b/tests/ref/fate/mov-mp4-ttml-dfxp
@@ -1,9 +1,9 @@
-2e7e01c821c111466e7a2844826b7f6d *tests/data/fate/mov-mp4-ttml-dfxp.mp4
-8519 tests/data/fate/mov-mp4-ttml-dfxp.mp4
+658884e1b789e75c454b25bdf71283c9 *tests/data/fate/mov-mp4-ttml-dfxp.mp4
+8486 tests/data/fate/mov-mp4-ttml-dfxp.mp4
 #tb 0: 1/1000
 #media_type 0: data
 #codec_id 0: none
-0,  0,  0,68500, 7866, 0x456c36b7
+0,  0,  0,68500, 7833, 0x31b22193
 {
 "packets": [
 {
@@ -15,7 +15,7 @@
 "dts_time": "0.00",
 "duration": 68500,
 "duration_time": "68.50",
-"size": "7866",
+"size": "7833",
 "pos": "44",
 "flags": "K_"
 }
diff --git a/tests/ref/fate/mov-mp4-ttml-stpp b/tests/ref/fate/mov-mp4-ttml-stpp
index 77bd23b7bf..f25b5b2d28 100644
--- a/tests/ref/fate/mov-mp4-ttml-stpp
+++ b/tests/ref/fate/mov-mp4-ttml-stpp
@@ -1,9 +1,9 @@
-cbd2c7ff864a663b0d893deac5a0caec *tests/data/fate/mov-mp4-ttml-stpp.mp4
-8547 tests/data/fate/mov-mp4-ttml-stpp.mp4
+c9570de0ccebc858b0c662a7e449582c *tests/data/fate/mov-mp4-ttml-stpp.mp4
+8514 tests/data/fate/mov-mp4-ttml-stpp.mp4
 #tb 0: 1/1000
 #media_type 0: data
 #codec_id 0: none
-0,  0,  0,68500, 7866, 0x456c36b7
+0,  0,  0,68500, 7833, 0x31b22193
 {
 "packets": [
 {
@@ -15,7 +15,7 @@ cbd2c7ff864a663b0d893deac5a0caec 
*tests/data/fate/mov-mp4-ttml-stpp.mp4
 "dts_time": "0.00",
 "duration": 68500,
 "duration_time": "68.50",
-"size": "7866",
+"size": "7833",
 "pos": "44",
 "flags": "K_"
 }
diff --git a/tests/ref/fate/sub-textenc b/tests/ref/fate/sub-textenc
index 3ea56b38f0..910ca3d6e3 100644
--- a/tests/ref/fate/sub-textenc
+++ b/tests/ref/fate/sub-textenc
@@ -160,18 +160,18 @@ but show this: {normal text}
 \ N is a forced line break
 \ h is a hard space
 Normal spaces at the start and at the end of the line are trimmed while hard 
spaces are not trimmed.
-The\hline\hwill\hnever\hbreak\hautomatically\hright\hbefore\hor\hafter\ha\hhard\hspace.\h:-D
+The line will never break automatically right before or after a hard space. :-D
 
 31
 00:00:54,501 --> 00:00:56,500
 
-\h\h\h\h\hA (05 hard spaces followed by a letter)
+ A (05 hard spaces followed by a letter)
 A (Normal  spaces followed by a letter)
 A (No hard spaces followed by a letter)
 
 32
 00:00:56,501 --> 00:00:58,500
-\h\h\h\h\hA (05 hard spaces followed by a letter)
+ A (05 hard spaces followed by a letter)
 A (Normal  spaces followed by a letter)
 A (No hard spaces followed by a letter)
 Show this: \TEST and this: \-)
@@ 

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

2022-01-13 Thread ffmpegagent
From: softworkz 

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

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 0e3e48613e..5711c7770b 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -570,6 +570,7 @@ OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
 OBJS-$(CONFIG_SPLITCC_FILTER)+= sf_splitcc.o
 OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 OBJS-$(CONFIG_SUBSCALE_FILTER)   += sf_subscale.o
+OBJS-$(CONFIG_SUBFEED_FILTER)+= sf_subfeed.o
 
 # multimedia filters
 OBJS-$(CONFIG_ABITSCOPE_FILTER)  += avf_abitscope.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 8e4f2feca3..10b14b7b8e 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -553,6 +553,7 @@ extern const AVFilter ff_sf_showspeaker;
 extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_subscale;
+extern const AVFilter ff_sf_subfeed;
 extern const AVFilter ff_sf_textmod;
 extern const AVFilter ff_svf_graphicsub2video;
 extern const AVFilter ff_svf_textsub2video;
diff --git a/libavfilter/sf_subfeed.c b/libavfilter/sf_subfeed.c
new file mode 100644
index 00..8a7ac5528b
--- /dev/null
+++ b/libavfilter/sf_subfeed.c
@@ -0,0 +1,366 @@
+/*
+ * 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)
+

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

2022-01-13 Thread ffmpegagent
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 ee7afffb05..a8b7ce8a26 100755
--- a/configure
+++ b/configure
@@ -3731,6 +3731,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 7bc02b9415..ee6e184882 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -26303,6 +26303,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 18/24] avfilter/graphicsub2text: Add new graphicsub2text filter (OCR)

2022-01-13 Thread ffmpegagent
From: softworkz 

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

diff --git a/configure b/configure
index c1d2bc41c2..ee7afffb05 100755
--- a/configure
+++ b/configure
@@ -3665,6 +3665,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 265a267e9d..7bc02b9415 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25897,6 +25897,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 ffmpeg -loglevel verbose -i 
"https://streams.videolan.org/streams/ts/video_subs_ttxt%2Bdvbsub.ts; 
-filter_complex "[0:13]graphicsub2text=ocr_mode=both" -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 c6a4a4f5ae..ead3e38507 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -299,6 +299,8 @@ OBJS-$(CONFIG_GBLUR_VULKAN_FILTER)   += 
vf_gblur_vulkan.o vulkan.o vulka
 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_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
 OBJS-$(CONFIG_GREYEDGE_FILTER)   += vf_colorconstancy.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 50498e8ec4..34576016ce 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -548,6 +548,7 @@ extern const AVFilter ff_avf_showwaves;
 extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 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..fcabb19892
--- /dev/null
+++ b/libavfilter/sf_graphicsub2text.c
@@ -0,0 +1,1132 @@
+/*
+ * 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 

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

2022-01-13 Thread ffmpegagent
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 | 385 +++
 5 files changed, 451 insertions(+)
 create mode 100644 libavfilter/sf_splitcc.c

diff --git a/configure b/configure
index 340a198fa6..c1d2bc41c2 100755
--- a/configure
+++ b/configure
@@ -3729,6 +3729,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 c0f0fe13e7..265a267e9d 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -26131,6 +26131,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 d330020f67..c6a4a4f5ae 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -565,6 +565,7 @@ OBJS-$(CONFIG_NULLSINK_FILTER)   += 
vsink_nullsink.o
 OBJS-$(CONFIG_CENSOR_FILTER) += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)   += sf_textmod.o
 OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
+OBJS-$(CONFIG_SPLITCC_FILTER)+= sf_splitcc.o
 OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 
 # multimedia filters
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index b0c12595af..50498e8ec4 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -549,6 +549,7 @@ extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 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;
 extern const AVFilter ff_svf_graphicsub2video;
diff --git a/libavfilter/sf_splitcc.c b/libavfilter/sf_splitcc.c
new file mode 100644
index 00..084f5f6969
--- /dev/null
+++ b/libavfilter/sf_splitcc.c
@@ -0,0 +1,385 @@
+/*
+ * 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] [PATCH 16/24] avfilter/stripstyles: Add stripstyles filter

2022-01-13 Thread ffmpegagent
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 | 209 +++
 4 files changed, 248 insertions(+)
 create mode 100644 libavfilter/sf_stripstyles.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 494ee6f062..c0f0fe13e7 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25781,6 +25781,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 1af4f4b9bc..d330020f67 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -565,6 +565,7 @@ OBJS-$(CONFIG_NULLSINK_FILTER)   += 
vsink_nullsink.o
 OBJS-$(CONFIG_CENSOR_FILTER) += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)   += sf_textmod.o
 OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
+OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 
 # multimedia filters
 OBJS-$(CONFIG_ABITSCOPE_FILTER)  += avf_abitscope.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index ac7d71547b..b0c12595af 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -549,6 +549,7 @@ extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 extern const AVFilter ff_sf_censor;
 extern const AVFilter ff_sf_showspeaker;
+extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_textmod;
 extern const AVFilter ff_svf_graphicsub2video;
 extern const AVFilter ff_svf_textsub2video;
diff --git a/libavfilter/sf_stripstyles.c b/libavfilter/sf_stripstyles.c
new file mode 100644
index 00..bbd731cc03
--- /dev/null
+++ b/libavfilter/sf_stripstyles.c
@@ -0,0 +1,209 @@
+/*
+ * 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_split_internal.h"
+#include "libavutil/bprint.h"
+
+typedef struct StripStylesContext {
+const AVClass *class;
+enum AVSubtitleType format;
+int remove_animated;
+int select_layer;
+} StripStylesContext;
+
+typedef struct DialogContext {
+StripStylesContext* ss_ctx;
+AVBPrint buffer;
+int drawing_scale;
+int is_animated;
+} 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))
+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)
+av_bprint_append_data(>buffer, forced ? "\\N" : "\\n", 2);
+}
+

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

2022-01-13 Thread ffmpegagent
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 |   3 +
 libavfilter/sf_textmod.c | 710 +++
 4 files changed, 924 insertions(+)
 create mode 100644 libavfilter/sf_textmod.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 51771f88e4..494ee6f062 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25721,6 +25721,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 14/24] avfilter/overlaytextsubs: Add overlaytextsubs and textsubs2video filters

2022-01-13 Thread ffmpegagent
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 |   4 +-
 libavfilter/vf_overlaytextsubs.c | 671 +++
 5 files changed, 791 insertions(+), 1 deletion(-)
 create mode 100644 libavfilter/vf_overlaytextsubs.c

diff --git a/configure b/configure
index 7c2931bd50..340a198fa6 100755
--- a/configure
+++ b/configure
@@ -3691,6 +3691,7 @@ overlay_opencl_filter_deps="opencl"
 overlay_qsv_filter_deps="libmfx"
 overlay_qsv_filter_select="qsvvpp"
 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"
@@ -3735,6 +3736,7 @@ superequalizer_filter_deps="avcodec"
 superequalizer_filter_select="rdft"
 surround_filter_deps="avcodec"
 surround_filter_select="rdft"
+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 4fc4a57dbb..51771f88e4 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25829,6 +25829,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 
overlay_textsubs 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
 
 @chapter Multimedia Filters

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

2022-01-13 Thread ffmpegagent
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 05d4b1a56e..4fc4a57dbb 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25713,6 +25713,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 
'overlay_graphicsubs' 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 overlay_graphicsubs)
+@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 283dd436cd..a372effc12 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -298,6 +298,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
 

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

2022-01-13 Thread ffmpegagent
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 e7b20be76b..94286eb678 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -152,7 +152,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 */
@@ -586,7 +585,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 (;;) {
@@ -620,6 +619,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;
@@ -652,25 +654,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);
 }
 }
 }
@@ -683,7 +671,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)
@@ -981,7 +968,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];
@@ -993,25 +980,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 07/24] avcodec/subtitles: Replace deprecated enum values

2022-01-13 Thread ffmpegagent
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 7802a44e71..fd321e7004 100644
--- a/libavcodec/assdec.c
+++ b/libavcodec/assdec.c
@@ -54,7 +54,7 @@ static int ass_decode_frame(AVCodecContext *avctx, void 
*data, int *got_sub_ptr,
 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 bc741a1de6..0d64c6e71c 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -795,7 +795,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 52259f0730..b39b3d1838 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -406,7 +406,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 84f2a544f0..ff21e75ef3 100644
--- a/libavcodec/dvdsubenc.c
+++ b/libavcodec/dvdsubenc.c
@@ -274,7 +274,7 @@ static int encode_dvd_subtitles(AVCodecContext* avctx, 
AVPacket* avpkt,
 return AVERROR(EINVAL);
 
 for (i = 0; i < rects; i++)
-if (frame->subtitle_areas[i]->type != SUBTITLE_BITMAP) {
+if (frame->subtitle_areas[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 bdd20c914b..22b6616f9b 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -535,7 +535,7 @@ static int display_end_segment(AVCodecContext *avctx, void 
*data,
 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 85cd7d1c20..a4be18a1d8 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -107,7 +107,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_sub_ptr,
 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 06/24] avcodec/subtitles: Migrate subtitle encoders to frame-based API

2022-01-13 Thread ffmpegagent
From: softworkz 

and provide a compatibility shim for the legacy api

Signed-off-by: softworkz 
---
 libavcodec/assenc.c| 189 ++---
 libavcodec/avcodec.h   |   5 +-
 libavcodec/dvbsubenc.c |  96 ++-
 libavcodec/dvdsubenc.c | 102 
 libavcodec/encode.c|  57 ++-
 libavcodec/movtextenc.c| 114 --
 libavcodec/srtenc.c| 108 ++---
 libavcodec/tests/avcodec.c |   2 -
 libavcodec/ttmlenc.c   | 101 +++-
 libavcodec/webvttenc.c |  86 -
 libavcodec/xsubenc.c   |  88 ++---
 11 files changed, 685 insertions(+), 263 deletions(-)

diff --git a/libavcodec/assenc.c b/libavcodec/assenc.c
index b0e475834b..e1401b1ac5 100644
--- a/libavcodec/assenc.c
+++ b/libavcodec/assenc.c
@@ -22,70 +22,195 @@
 #include 
 
 #include "avcodec.h"
+#include "encode.h"
 #include "libavutil/ass_internal.h"
 #include "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 *avpkt)
 {
-int i, len, total_len = 0;
+AssEncContext *s = avctx->priv_data;

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

2022-01-13 Thread ffmpegagent
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 1413122d87..7c2931bd50 100755
--- a/configure
+++ b/configure
@@ -7854,7 +7854,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 4325a3e557..8a3bd03924 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -556,8 +556,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 c0215669e7..0b268c2fa4 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -29,6 +29,8 @@
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
 
+#include "libavcodec/avcodec.h"
+
 #define FF_INTERNAL_FIELDS 1
 #include "framequeue.h"
 
@@ -57,6 +59,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;
 
@@ -305,6 +311,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_subtitle_type(, 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[] = {
@@ -322,9 +350,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[] = {
 {
@@ -363,3 +398,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 69ed0f29a8..11905abdc5 100644
--- a/libavfilter/buffersink.h
+++ b/libavfilter/buffersink.h
@@ -129,6 +129,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 b0611872f1..d2362999a2 100644
--- a/libavfilter/buffersrc.c

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

2022-01-13 Thread ffmpegagent
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 75d5e86539..aa9aa71f53 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -463,7 +463,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;
 
@@ -472,8 +472,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));
@@ -1172,6 +1172,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) {
@@ -1181,7 +1189,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;
 }
@@ -1218,7 +1226,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 05/24] avcodec, avutil: Move ass helper functions to avutil as avpriv_ and extend ass dialog parsing

2022-01-13 Thread ffmpegagent
From: softworkz 

Also add

- hard_space callback (for upcoming fix)
- extensible callback (for future extension)

Signed-off-by: softworkz 
---
 libavcodec/Makefile   |  56 +++
 libavcodec/ass.h  | 144 ++
 libavcodec/assdec.c   |   2 +-
 libavcodec/assenc.c   |   2 +-
 libavcodec/ccaption_dec.c |  19 +--
 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   |  91 +--
 libavutil/ass_internal.h  | 135 
 {libavcodec => libavutil}/ass_split.c |  30 ++--
 .../ass_split_internal.h  |  32 ++--
 26 files changed, 355 insertions(+), 269 deletions(-)
 rename {libavcodec => libavutil}/ass.c (65%)
 create mode 100644 libavutil/ass_internal.h
 rename {libavcodec => libavutil}/ass_split.c (94%)
 rename libavcodec/ass_split.h => libavutil/ass_split_internal.h (86%)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index cfc70a3eaf..80bf8ff2d2 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -215,10 +215,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
@@ -259,7 +259,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
@@ -434,7 +434,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 \
@@ -456,7 +456,7 @@ OBJS-$(CONFIG_MAGICYUV_ENCODER)+= magicyuvenc.o
 OBJS-$(CONFIG_MDEC_DECODER)+= mdec.o mpeg12.o mpeg12data.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_MJPEG_DECODER)   += mjpegdec.o mjpegdec_common.o
 OBJS-$(CONFIG_MJPEG_QSV_DECODER)   += qsvdec.o
@@ -471,8 +471,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

[FFmpeg-devel] [PATCH 10/24] avfilter/avfilter: Handle subtitle frames

2022-01-13 Thread ffmpegagent
From: softworkz 

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

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index df5b8f483c..75d5e86539 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -56,7 +56,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,
@@ -64,12 +65,13 @@ 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:
 ff_tlog(ctx, " cl:%"PRId64"d n:%d r:%d",
 ref->channel_layout,
 ref->nb_samples,
 ref->sample_rate);
+break;
 }
 
 ff_tlog(ctx, "]%s", end ? "\n" : "");
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index b105dc3159..9f917deb41 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.h"
@@ -343,6 +344,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.
  */
@@ -351,6 +358,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 b8b432e98b..f4987654af 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -311,6 +311,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");
 }
@@ -441,6 +443,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 ba62f73248..5c972bb183 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/subfmt.h"
 #include "libavutil/avassert.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
@@ -431,6 +432,12 @@ int ff_add_channel_layout(AVFilterChannelLayouts **l, 
uint64_t channel_layout)
 return 0;
 }
 
+int ff_add_subtitle_type(AVFilterFormats **avff, int64_t fmt)
+{
+ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
+return 0;
+}
+
 AVFilterFormats *ff_make_formats_list_singleton(int fmt)
 {
 int fmts[2] = { fmt, -1 };
@@ -450,6 +457,13 @@ AVFilterFormats *ff_all_formats(enum AVMediaType type)
 return NULL;
 fmt++;
 }
+} else if (type == AVMEDIA_TYPE_SUBTITLE) {
+if (ff_add_subtitle_type(, AV_SUBTITLE_FMT_BITMAP) < 0)
+return NULL;
+if (ff_add_subtitle_type(, AV_SUBTITLE_FMT_ASS) < 0)
+return NULL;
+if (ff_add_subtitle_type(, AV_SUBTITLE_FMT_TEXT) < 0)
+return NULL;
 }
 
 return ret;
@@ -724,6 +738,10 @@ int ff_default_query_formats(AVFilterContext *ctx)
 type= 

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

2022-01-13 Thread ffmpegagent
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 1adbea75bd..283dd436cd 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -19,6 +19,7 @@ OBJS = allfilters.o   
  \
framequeue.o \
graphdump.o  \
graphparser.o\
+   subtitles.o  \
video.o  \
 
 OBJS-$(HAVE_THREADS) += pthread.o
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 7362bcdab5..df5b8f483c 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"
 
 #include "libavutil/ffversion.h"
 const char av_filter_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
@@ -1475,6 +1476,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 1099b82b4b..fc09ef574c 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -90,6 +90,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 

[FFmpeg-devel] [PATCH 04/24] avfilter/subtitles: Update vf_subtitles to use new decoding api

2022-01-13 Thread ffmpegagent
From: softworkz 

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

diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
index 3fc4eeb63d..25e217e845 100644
--- a/libavfilter/vf_subtitles.c
+++ b/libavfilter/vf_subtitles.c
@@ -35,14 +35,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;
@@ -292,6 +290,29 @@ 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 av_cold int init_subtitles(AVFilterContext *ctx)
@@ -306,6 +327,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);
@@ -386,13 +408,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 = avcodec_descriptor_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);
 
@@ -448,27 +474,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 03/24] avcodec/subtitles: Introduce new frame-based subtitle decoding API

2022-01-13 Thread ffmpegagent
From: softworkz 

- Add avcodec_decode_subtitle3 which takes subtitle frames,
  serving as compatibility shim to legacy subtitle decoding
- Add additional methods for conversion between old and new API

Signed-off-by: softworkz 
---
 libavcodec/avcodec.h|   8 +-
 libavcodec/codec_desc.c |  11 +++
 libavcodec/codec_desc.h |   8 ++
 libavcodec/decode.c |  56 ++--
 libavcodec/internal.h   |  22 +
 libavcodec/utils.c  | 184 
 6 files changed, 280 insertions(+), 9 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index fe5a83cf85..9d59f6e840 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1675,7 +1675,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())
@@ -2415,7 +2415,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);
 
 /**
@@ -2508,7 +2511,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/codec_desc.c b/libavcodec/codec_desc.c
index 0974ee03de..e48e4532ba 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3548,3 +3548,14 @@ enum AVMediaType avcodec_get_type(enum AVCodecID 
codec_id)
 const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
 return desc ? desc->type : AVMEDIA_TYPE_UNKNOWN;
 }
+
+enum AVSubtitleType avcodec_descriptor_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;
+}
diff --git a/libavcodec/codec_desc.h b/libavcodec/codec_desc.h
index 126b52df47..ba68d24e0e 100644
--- a/libavcodec/codec_desc.h
+++ b/libavcodec/codec_desc.h
@@ -121,6 +121,14 @@ const AVCodecDescriptor *avcodec_descriptor_next(const 
AVCodecDescriptor *prev);
  */
 const AVCodecDescriptor *avcodec_descriptor_get_by_name(const char *name);
 
+/**
+ * Return subtitle format from a codec descriptor
+ *
+ * @param codec_descriptor codec descriptor
+ * @return the subtitle type (e.g. bitmap, text)
+ */
+enum AVSubtitleType avcodec_descriptor_get_subtitle_format(const 
AVCodecDescriptor *codec_descriptor);
+
 /**
  * @}
  */
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0912f86a14..ab8a6ea6ff 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -576,6 +576,39 @@ static int decode_receive_frame_internal(AVCodecContext 
*avctx, AVFrame *frame)
 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;
@@ -590,6 +623,9 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext 
*avctx, const AVPacke
 if (avpkt && !avpkt->size && avpkt->data)
 return AVERROR(EINVAL);
 
+if 

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

2022-01-13 Thread ffmpegagent
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  | 211 -
 libavutil/frame.h  |  85 +-
 libavutil/subfmt.c |  45 ++
 libavutil/subfmt.h |  47 ++
 5 files changed, 364 insertions(+), 25 deletions(-)
 create mode 100644 libavutil/subfmt.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index ce644f4d48..8bc0a14942 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -160,6 +160,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 8997c85e35..2b95830b6f 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"
 
 #define CHECK_CHANNELS_CONSISTENCY(frame) \
@@ -50,6 +51,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));
@@ -70,7 +74,12 @@ static void get_frame_defaults(AVFrame *frame)
 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)
@@ -240,23 +249,55 @@ static int get_audio_buffer(AVFrame *frame, int align)
 
 }
 
+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->width > 0 && frame->height > 0)
+frame->type = AVMEDIA_TYPE_VIDEO;
+else if (frame->nb_samples > 0 && (frame->channel_layout || 
frame->channels > 0))
+frame->type = AVMEDIA_TYPE_AUDIO;
+
+return av_frame_get_buffer2(frame, align);
+}
+
+int av_frame_get_buffer2(AVFrame *frame, int align)
 {
 if (frame->format < 0)
 return AVERROR(EINVAL);
 
-if (frame->width > 0 && frame->height > 0)
+switch(frame->type) {
+case AVMEDIA_TYPE_VIDEO:
 return get_video_buffer(frame, align);
-else if (frame->nb_samples > 0 && (frame->channel_layout || 
frame->channels > 0))
+case AVMEDIA_TYPE_AUDIO:
 return get_audio_buffer(frame, align);
-
-return AVERROR(EINVAL);
+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;
@@ -288,6 +329,12 @@ static int frame_copy_props(AVFrame *dst, const AVFrame 
*src, int force_copy)
 dst->colorspace = src->colorspace;
 dst->color_range= src->color_range;
 dst->chroma_location= src->chroma_location;
+dst->repeat_sub = src->repeat_sub;
+dst->subtitle_timing.start_pts = src->subtitle_timing.start_pts;
+  

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

2022-01-13 Thread ffmpegagent
From: softworkz 

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

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index ec1a0566a4..fe5a83cf85 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"
@@ -2238,24 +2239,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 d17876df1a..ce644f4d48 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -74,6 +74,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 953aac9d94..5bf48f6304 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -110,6 +110,7 @@
 #define FF_API_COLORSPACE_NAME  (LIBAVUTIL_VERSION_MAJOR < 58)
 #define FF_API_AV_MALLOCZ_ARRAY (LIBAVUTIL_VERSION_MAJOR < 58)
 #define FF_API_FIFO_PEEK2   (LIBAVUTIL_VERSION_MAJOR < 58)
+#define FF_API_OLD_SUBTITLES(LIBAVUTIL_VERSION_MAJOR < 58)
 
 /**
  * @}
-- 
ffmpeg-codebot

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

To unsubscribe, visit link above, or 

[FFmpeg-devel] [PATCH 00/24] Subtitle Filtering 2022

2022-01-13 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 v2 update).

The update also includes major improvements to graphicsub2text and lots of
other details.

Versioning is restarting at v1 due to the new submission procedure.

All 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 'subtitle_timing.duration'
 * Change both fields to (fixed) time_base AV_TIMEBASE
 * add repeat_sub field provides a clear indication whether a subtitle frame
   is an actual subtitle event or a repeated subtitle frame in a filter
   graph


Heartbeat Removal
=

 * completely removed the earlier heartbeat implementation
 * filtering arbitration is now implemented in a new filter: 'subfeed'
 * subfeed will be auto-inserted for compatiblity with sub2video command
   lines
 * the new behavior is not exactly identical to the earlier behavior, but it
   basically allows to achieve the same results


New 'subfeed' Filter


 * a versatile filter for solving all kinds of problems with subtile frame
   flow in filter graphs
 * Can be inserted at any position in a graph
 * Auto-inserted for sub2video command lines (in repeat-mode)
 * Allows duration fixup delay input frames with unknown duration and infer
   duration from start of subsequent frame
 * Provides multiple modes of operation:
   * repeat mode (default) Queues input frames Outputs frames at a fixed
 (configurable) rate Either sends a matching input frame (repeatedly) or
 empty frames otherwise
   * scatter mode similar to repeat mode, but splits input frames by
 duration into small segments with same content
   * forward mode No fixed output rate Useful in combination with duration
 fixup or overlap fixup


ffmpeg Tool Changes
===

 * delay subtitle output stream initialization (like for audio and video)
   This is needed for example when a format header depends on having
   received an initial frame to derive certain header values from
 * decoding: set subtitle frame size from decoding context
 * re-init graph when subtitle size changes
 * always insert subscale filter for sub2video command lines (to ensure
   correct scaling)


Subtitle Encoding
=

 * ignore repeated frames for encoding based on repeat_sub field in AVFrame
 * support multi-area encoding for text subtitles Subtitle OCR can create
   multiple areas at different positions. Previously, the texts were always
   squashed into a single area ('subtitle rect'), which was not ideal.
   Multiple text areas are now generally supported:
   * ASS Encoder Changed to use the 'receive_packet' encoding API A single
 frame with multiple text areas will create multiple packets now
   * All other text subtitle encoders A newline is inserted between the text
 from multiple areas


graphicsub2text (OCR)
=

 * enhanced preprocessing
   * using elbg algorithm for color quantization
   * detection and removal of text outlines
   * map-based identification of colors per word (text, outline, background)
 * add option for duration fixup
 * add option to dump preprocessing bitmaps
 * Recognize formatting and apply as ASS inline styles
   * per word(!)
   * paragraph alignment
   * positioning
   * font names
   * font size
   * font style (italic, underline, bold)
   * text color, outline color


Other Filter Changes


 * all: Make sure to forward all link properties (time base, frame rate, w,
   h) where appropriate
 * overlaytextsubs: request frames on the subtitle input
 * overlaytextsubs: disable read-order checking
 * overlaytextsubs: improve implementation of render_latest_only
 * overlaytextsubs: ensure equal in/out video formats
 * splitcc: derive framerate from realtime_latency
 * graphicsub2video: implement caching of converted frames
 * 

Re: [FFmpeg-devel] [PATCH 3/3] avcodec/libopenh264enc: set iEntropyCodingModeFlag by coder option

2022-01-13 Thread Martin Storsjö

On Thu, 13 Jan 2022, lance.lmw...@gmail.com wrote:


From: Limin Wang 

ffmpeg -y -f lavfi -i testsrc -c:v libopenh264 -profile:v main -coder cavlc 
-frames:v 1 -bsf trace_headers -f null -

before the patch:
entropy_coding_mode_flag0 = 1

after the patch:
entropy_coding_mode_flag0 = 0


I don't understand what this bit in the commit message tries to say?


Doesn't this patch have the effect, that if I only specify "-profile 
high", I'll end up with CAVLC unless I specifically pass "-coder cabac" 
too? If coder wasn't specified, I think we should still default to CABAC 
for main/high.


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


Re: [FFmpeg-devel] [PATCH 2/3] avcodec/libopenh264enc: make the profile configuablable correctly

2022-01-13 Thread Martin Storsjö

On Thu, 13 Jan 2022, lance.lmw...@gmail.com wrote:


From: Limin Wang 

If the version of libopenh264 >= 1.8, we can't configured main profile as
expected, below is the testing cli:

ffmpeg -y -f lavfi -i testsrc -c:v libopenh264 -profile:v main -frames:v 1 
test.ts
It'll report:
[libopenh264 @ 0x5638300] Unsupported profile, select EProfileIdc PRO_BASELINE 
in libopenh264.

Signed-off-by: Limin Wang 
---
libavcodec/libopenh264enc.c | 8 +---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index a55bef8..995ee37 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -220,26 +220,27 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
#endif

switch (s->profile) {
-#if OPENH264_VER_AT_LEAST(1, 8)
case FF_PROFILE_H264_HIGH:
+s->profile = PRO_HIGH;


I don't think we should reuse the s->profile field for this value here.

In practice, both FF_PROFILE_H264_HIGH and PRO_HIGH have the same values, 
but they're enums from different namespaces, so would it be clearer to use 
one variable for profiles set with FF_PROFILE_* and one with the PRO_* 
values?



param.iEntropyCodingModeFlag = 1;
av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
"select EProfileIdc PRO_HIGH in libopenh264.\n");
break;
-#else
case FF_PROFILE_H264_MAIN:
+s->profile = PRO_MAIN;
param.iEntropyCodingModeFlag = 1;
av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
"select EProfileIdc PRO_MAIN in libopenh264.\n");
break;
-#endif
case FF_PROFILE_H264_CONSTRAINED_BASELINE:
case FF_PROFILE_UNKNOWN:
+s->profile = PRO_BASELINE;
param.iEntropyCodingModeFlag = 0;
av_log(avctx, AV_LOG_VERBOSE, "Using CAVLC, "
   "select EProfileIdc PRO_BASELINE in libopenh264.\n");
break;
default:
+s->profile = PRO_BASELINE;
param.iEntropyCodingModeFlag = 0;
av_log(avctx, AV_LOG_WARNING, "Unsupported profile, "
   "select EProfileIdc PRO_BASELINE in libopenh264.\n");
@@ -251,6 +252,7 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
param.sSpatialLayers[0].fFrameRate  = param.fMaxFrameRate;
param.sSpatialLayers[0].iSpatialBitrate = param.iTargetBitrate;
param.sSpatialLayers[0].iMaxSpatialBitrate  = param.iMaxBitrate;
+param.sSpatialLayers[0].uiProfileIdc= s->profile;


So this assignment is what was missing, and was what caused the incorrect 
conclusion in d3a7bdd4ac54349aea9150a234478635d50ebd87? I think it'd be 
good to explicitly spell this out in the commit message, saying that 
d3a7bdd4ac54349aea9150a234478635d50ebd87 was based on incorrect 
conclusions because we had missed to set uiProfileIdc.


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


Re: [FFmpeg-devel] [PATCH 1/3] avcodec/libopenh264enc: support for colorspace and range information

2022-01-13 Thread Martin Storsjö

On Thu, 13 Jan 2022, lance.lmw...@gmail.com wrote:


From: Limin Wang 

Signed-off-by: Limin Wang 
---
libavcodec/libopenh264enc.c | 15 +++
1 file changed, 15 insertions(+)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index de4b85c..a55bef8 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -330,6 +330,21 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
}
}

+#if OPENH264_VER_AT_LEAST(1, 6)
+param.sSpatialLayers[0].uiVideoFormat = VF_UNDEF;
+param.sSpatialLayers[0].bVideoSignalTypePresent = true;


What does this flag do, and why do we set it unconditionally while we 
didn't use to before?



+if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED)
+param.sSpatialLayers[0].bFullRange = (avctx->color_range == 
AVCOL_RANGE_JPEG);
+
+param.sSpatialLayers[0].bColorDescriptionPresent = true;


Ditto - what does this do and why do we set it even if we wouldn't set any 
of the other fields?


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


Re: [FFmpeg-devel] [PATCH 277/281] ffmpeg: convert to new channel layout-API

2022-01-13 Thread James Almer



On 1/13/2022 3:40 PM, James Almer wrote:

On 1/13/2022 3:29 PM, Michael Niedermayer wrote:

On Wed, Jan 12, 2022 at 11:09:09PM -0300, James Almer wrote:

Signed-off-by: James Almer 
---
  fftools/cmdutils.c    | 42 +++-
  fftools/cmdutils.h    |  8 -
  fftools/ffmpeg.c  | 47 --
  fftools/ffmpeg.h  |  7 ++--
  fftools/ffmpeg_filter.c   | 52 ++---
  fftools/ffmpeg_opt.c  | 62 ++-
  tests/fate/aac.mak    |  2 +-
  tests/fate/lavf-container.mak |  2 +-
  8 files changed, 155 insertions(+), 67 deletions(-)


This or a prior patch introduces crashes (it bisected to this but this 
is my

2nd testcase the first did not reproduce reliably at all)

Thread 1 "ffmpeg_g" received signal SIGSEGV, Segmentation fault.
0x566ed811 in av_vlog (avcl=0x577400c0, level=24, 
fmt=0x568249e8 "%d frames left in the queue on closing\n", 
vl=0x7fffda50) at libavutil/log.c:428


av_vlog() is where it crashes?


428    if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&
(gdb) bt
#0  0x566ed811 in av_vlog (avcl=0x577400c0, level=24, 
fmt=0x568249e8 "%d frames left in the queue on closing\n", 
vl=0x7fffda50) at libavutil/log.c:428
#1  0x566ed6bd in av_log (avcl=0x577400c0, level=24, 
fmt=0x568249e8 "%d frames left in the queue on closing\n") at 
libavutil/log.c:411
#2  0x55c320b9 in ff_af_queue_close (afq=0x576c47c8) at 
libavcodec/audio_frame_queue.c:39
#3  0x55e84c06 in mp3lame_encode_close (avctx=0x576bf180) 
at libavcodec/libmp3lame.c:86
#4  0x55c373f7 in avcodec_close (avctx=0x576bf180) at 
libavcodec/avcodec.c:489
#5  0x55f7feab in avcodec_free_context (pavctx=0x576a8858) 
at libavcodec/options.c:163

#6  0x5569cfe3 in ffmpeg_cleanup (ret=1) at fftools/ffmpeg.c:608
#7  0x55694817 in exit_program (ret=1) at fftools/cmdutils.c:131
#8  0x5569ef1f in do_audio_out (of=0x576ae2c0, 
ost=0x576a8800, frame=0x576bf580) at fftools/ffmpeg.c:1056

#9  0x556a117a in reap_filters (flush=0) at fftools/ffmpeg.c:1546
#10 0x556ad8e5 in transcode_step () at fftools/ffmpeg.c:4643
#11 0x556ad9e7 in transcode () at fftools/ffmpeg.c:4687
#12 0x556ae45c in main (argc=12, argv=0x7fffe1c8) at 
fftools/ffmpeg.c:4903

(gdb) print avc->version
Cannot access memory at address 0xc1528eb7c0ea0157

make -j32 && gdb --args ./ffmpeg_g -ss 8 -i NeroRecodeSample.mp4 
-bitexact -t 3 -filter_complex '[0:2]scale=720:576[v];[v][0:5]overlay' 
-y file-whitesubs.avi


it appears this file is at:
https://samples.ffmpeg.org/MPEG-4/NeroRecodeSample-MP4/


I can't reproduce this on mingw64.


Does the following fix it for you?


diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index 36ae57eb83..728005b840 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -344,9 +344,15 @@ const AVCodec ff_libmp3lame_encoder = {
  
AV_SAMPLE_FMT_S16P,
  
AV_SAMPLE_FMT_NONE },
 .supported_samplerates = libmp3lame_sample_rates,
+#if FF_API_OLD_CHANNEL_LAYOUT
 .channel_layouts   = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
   AV_CH_LAYOUT_STEREO,
   0 },
+#endif
+.ch_layouts= (const AVChannelLayout[]) { 
AV_CHANNEL_LAYOUT_MONO,
+ 
AV_CHANNEL_LAYOUT_STEREO,
+ { 0 },
+},
 .priv_class= _class,
 .defaults  = libmp3lame_defaults,
 .wrapper_name  = "libmp3lame",

___
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 31/35] lavu/threadmessage: switch to new FIFO API

2022-01-13 Thread Andreas Rheinhardt
Anton Khirnov:
> ---
>  libavutil/threadmessage.c | 34 +-
>  1 file changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/libavutil/threadmessage.c b/libavutil/threadmessage.c
> index 764b7fb813..39d3525a78 100644
> --- a/libavutil/threadmessage.c
> +++ b/libavutil/threadmessage.c
> @@ -64,7 +64,7 @@ int av_thread_message_queue_alloc(AVThreadMessageQueue **mq,
>  av_free(rmq);
>  return AVERROR(ret);
>  }
> -if (!(rmq->fifo = av_fifo_alloc(elsize * nelem))) {
> +if (!(rmq->fifo = av_fifo_alloc2(nelem, elsize, 0))) {
>  pthread_cond_destroy(>cond_send);
>  pthread_cond_destroy(>cond_recv);
>  pthread_mutex_destroy(>lock);
> @@ -107,9 +107,9 @@ int av_thread_message_queue_nb_elems(AVThreadMessageQueue 
> *mq)
>  #if HAVE_THREADS
>  int ret;
>  pthread_mutex_lock(>lock);
> -ret = av_fifo_size(mq->fifo);
> +ret = av_fifo_can_read(mq->fifo);
>  pthread_mutex_unlock(>lock);
> -return ret / mq->elsize;
> +return ret;
>  #else
>  return AVERROR(ENOSYS);
>  #endif
> @@ -121,14 +121,14 @@ static int 
> av_thread_message_queue_send_locked(AVThreadMessageQueue *mq,
> void *msg,
> unsigned flags)
>  {
> -while (!mq->err_send && av_fifo_space(mq->fifo) < mq->elsize) {
> +while (!mq->err_send && !av_fifo_can_write(mq->fifo)) {
>  if ((flags & AV_THREAD_MESSAGE_NONBLOCK))
>  return AVERROR(EAGAIN);
>  pthread_cond_wait(>cond_send, >lock);
>  }
>  if (mq->err_send)
>  return mq->err_send;
> -av_fifo_generic_write(mq->fifo, msg, mq->elsize, NULL);
> +av_fifo_write(mq->fifo, msg, 1);
>  /* one message is sent, signal one receiver */
>  pthread_cond_signal(>cond_recv);
>  return 0;
> @@ -138,14 +138,14 @@ static int 
> av_thread_message_queue_recv_locked(AVThreadMessageQueue *mq,
> void *msg,
> unsigned flags)
>  {
> -while (!mq->err_recv && av_fifo_size(mq->fifo) < mq->elsize) {
> +while (!mq->err_recv && !av_fifo_can_read(mq->fifo)) {
>  if ((flags & AV_THREAD_MESSAGE_NONBLOCK))
>  return AVERROR(EAGAIN);
>  pthread_cond_wait(>cond_recv, >lock);
>  }
> -if (av_fifo_size(mq->fifo) < mq->elsize)
> +if (!av_fifo_can_read(mq->fifo))
>  return mq->err_recv;
> -av_fifo_generic_read(mq->fifo, msg, mq->elsize, NULL);
> +av_fifo_read(mq->fifo, msg, 1);
>  /* one message space appeared, signal one sender */
>  pthread_cond_signal(>cond_send);
>  return 0;
> @@ -208,25 +208,25 @@ void 
> av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq,
>  }
>  
>  #if HAVE_THREADS
> -static void free_func_wrap(void *arg, void *msg, int size)
> +static int free_func_wrap(void *arg, void *buf, size_t *nb_elems)
>  {
>  AVThreadMessageQueue *mq = arg;
> -mq->free_func(msg);
> +uint8_t *msg = buf;
> +for (size_t i = 0; i < *nb_elems; i++)
> +mq->free_func(msg + i * mq->elsize);
> +return 0;

This function (like most nontrivial callbacks) relies on buf being
suitably aligned for whatever type msg is. Therefore one should document
that the src/dst in the callbacks is always suitable aligned for all
non-over-aligned types.

>  }
>  #endif
>  
>  void av_thread_message_flush(AVThreadMessageQueue *mq)
>  {
>  #if HAVE_THREADS
> -int used, off;
> -void *free_func = mq->free_func;
> +size_t used;
>  
>  pthread_mutex_lock(>lock);
> -used = av_fifo_size(mq->fifo);
> -if (free_func)
> -for (off = 0; off < used; off += mq->elsize)
> -av_fifo_generic_peek_at(mq->fifo, mq, off, mq->elsize, 
> free_func_wrap);
> -av_fifo_drain(mq->fifo, used);
> +used = av_fifo_can_read(mq->fifo);
> +if (mq->free_func)
> +av_fifo_read_to_cb(mq->fifo, free_func_wrap, mq, );
>  /* only the senders need to be notified since the queue is empty and 
> there
>   * is nothing to read */
>  pthread_cond_broadcast(>cond_send);
> 

___
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 26/35] lavf/udp: switch to new FIFO API

2022-01-13 Thread Andreas Rheinhardt
Anton Khirnov:
> ---
>  libavformat/udp.c | 28 ++--
>  1 file changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/libavformat/udp.c b/libavformat/udp.c
> index 83c042d079..4c8f104d9d 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -500,7 +500,7 @@ static void *circular_buffer_task_rx( void *_URLContext)
>  continue;
>  AV_WL32(s->tmp, len);
>  
> -if(av_fifo_space(s->fifo) < len + 4) {
> +if (av_fifo_can_write(s->fifo) < len + 4) {
>  /* No Space left */
>  if (s->overrun_nonfatal) {
>  av_log(h, AV_LOG_WARNING, "Circular buffer overrun. "
> @@ -514,7 +514,7 @@ static void *circular_buffer_task_rx( void *_URLContext)
>  goto end;
>  }
>  }
> -av_fifo_generic_write(s->fifo, s->tmp, len+4, NULL);
> +av_fifo_write(s->fifo, s->tmp, len + 4);
>  pthread_cond_signal(>cond);
>  }
>  
> @@ -548,22 +548,22 @@ static void *circular_buffer_task_tx( void *_URLContext)
>  uint8_t tmp[4];
>  int64_t timestamp;
>  
> -len = av_fifo_size(s->fifo);
> +len = av_fifo_can_read(s->fifo);

len should be made size_t (although the values always fit into an int).

>  
>  while (len<4) {
>  if (s->close_req)
>  goto end;
>  pthread_cond_wait(>cond, >mutex);
> -len = av_fifo_size(s->fifo);
> +len = av_fifo_can_read(s->fifo);
>  }
>  
> -av_fifo_generic_read(s->fifo, tmp, 4, NULL);
> +av_fifo_read(s->fifo, tmp, 4);
>  len = AV_RL32(tmp);
>  
>  av_assert0(len >= 0);
>  av_assert0(len <= sizeof(s->tmp));
>  
> -av_fifo_generic_read(s->fifo, s->tmp, len, NULL);
> +av_fifo_read(s->fifo, s->tmp, len);
>  
>  pthread_mutex_unlock(>mutex);
>  
> @@ -906,7 +906,7 @@ static int udp_open(URLContext *h, const char *uri, int 
> flags)
>  
>  if ((!is_output && s->circular_buffer_size) || (is_output && s->bitrate 
> && s->circular_buffer_size)) {
>  /* start the task going */
> -s->fifo = av_fifo_alloc(s->circular_buffer_size);
> +s->fifo = av_fifo_alloc2(s->circular_buffer_size, 1, 0);
>  if (!s->fifo) {
>  ret = AVERROR(ENOMEM);
>  goto fail;
> @@ -970,19 +970,19 @@ static int udp_read(URLContext *h, uint8_t *buf, int 
> size)
>  if (s->fifo) {
>  pthread_mutex_lock(>mutex);
>  do {
> -avail = av_fifo_size(s->fifo);
> +avail = av_fifo_can_read(s->fifo);
>  if (avail) { // >=size) {
>  uint8_t tmp[4];
>  
> -av_fifo_generic_read(s->fifo, tmp, 4, NULL);
> +av_fifo_read(s->fifo, tmp, 4);
>  avail = AV_RL32(tmp);
>  if(avail > size){
>  av_log(h, AV_LOG_WARNING, "Part of datagram lost due to 
> insufficient buffer size\n");
>  avail = size;
>  }
>  
> -av_fifo_generic_read(s->fifo, buf, avail, NULL);
> -av_fifo_drain(s->fifo, AV_RL32(tmp) - avail);
> +av_fifo_read(s->fifo, buf, avail);
> +av_fifo_drain2(s->fifo, AV_RL32(tmp) - avail);
>  pthread_mutex_unlock(>mutex);
>  return avail;
>  } else if(s->circular_buffer_error){
> @@ -1043,14 +1043,14 @@ static int udp_write(URLContext *h, const uint8_t 
> *buf, int size)
>  return err;
>  }
>  
> -if(av_fifo_space(s->fifo) < size + 4) {
> +if (av_fifo_can_write(s->fifo) < size + 4) {
>  /* What about a partial packet tx ? */
>  pthread_mutex_unlock(>mutex);
>  return AVERROR(ENOMEM);
>  }
>  AV_WL32(tmp, size);
> -av_fifo_generic_write(s->fifo, tmp, 4, NULL); /* size of packet */
> -av_fifo_generic_write(s->fifo, (uint8_t *)buf, size, NULL); /* the 
> data */
> +av_fifo_write(s->fifo, tmp, 4); /* size of packet */
> +av_fifo_write(s->fifo, (uint8_t *)buf, size); /* the data */

The cast can now be dropped.

>  pthread_cond_signal(>cond);
>  pthread_mutex_unlock(>mutex);
>  return size;
> 

___
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/rawvideodec: check packet size

2022-01-13 Thread Michael Niedermayer
On Fri, Jan 07, 2022 at 05:51:11PM +0100, Michael Niedermayer wrote:
> Fixes: division by zero
> Fixes: integer overflow
> Fixes: 
> 43347/clusterfuzz-testcase-minimized-ffmpeg_dem_V210X_fuzzer-5846911637127168
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/rawvideodec.c | 7 +++
>  1 file changed, 7 insertions(+)

will apply
thx for the reviews

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The bravest are surely those who have the clearest vision
of what is before them, glory and danger alike, and yet
notwithstanding go out to meet it. -- Thucydides


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


Re: [FFmpeg-devel] [PATCH 277/281] ffmpeg: convert to new channel layout-API

2022-01-13 Thread James Almer

On 1/13/2022 3:29 PM, Michael Niedermayer wrote:

On Wed, Jan 12, 2022 at 11:09:09PM -0300, James Almer wrote:

Signed-off-by: James Almer 
---
  fftools/cmdutils.c| 42 +++-
  fftools/cmdutils.h|  8 -
  fftools/ffmpeg.c  | 47 --
  fftools/ffmpeg.h  |  7 ++--
  fftools/ffmpeg_filter.c   | 52 ++---
  fftools/ffmpeg_opt.c  | 62 ++-
  tests/fate/aac.mak|  2 +-
  tests/fate/lavf-container.mak |  2 +-
  8 files changed, 155 insertions(+), 67 deletions(-)


This or a prior patch introduces crashes (it bisected to this but this is my
2nd testcase the first did not reproduce reliably at all)

Thread 1 "ffmpeg_g" received signal SIGSEGV, Segmentation fault.
0x566ed811 in av_vlog (avcl=0x577400c0, level=24, fmt=0x568249e8 "%d 
frames left in the queue on closing\n", vl=0x7fffda50) at libavutil/log.c:428


av_vlog() is where it crashes?


428 if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&
(gdb) bt
#0  0x566ed811 in av_vlog (avcl=0x577400c0, level=24, fmt=0x568249e8 
"%d frames left in the queue on closing\n", vl=0x7fffda50) at 
libavutil/log.c:428
#1  0x566ed6bd in av_log (avcl=0x577400c0, level=24, fmt=0x568249e8 
"%d frames left in the queue on closing\n") at libavutil/log.c:411
#2  0x55c320b9 in ff_af_queue_close (afq=0x576c47c8) at 
libavcodec/audio_frame_queue.c:39
#3  0x55e84c06 in mp3lame_encode_close (avctx=0x576bf180) at 
libavcodec/libmp3lame.c:86
#4  0x55c373f7 in avcodec_close (avctx=0x576bf180) at 
libavcodec/avcodec.c:489
#5  0x55f7feab in avcodec_free_context (pavctx=0x576a8858) at 
libavcodec/options.c:163
#6  0x5569cfe3 in ffmpeg_cleanup (ret=1) at fftools/ffmpeg.c:608
#7  0x55694817 in exit_program (ret=1) at fftools/cmdutils.c:131
#8  0x5569ef1f in do_audio_out (of=0x576ae2c0, ost=0x576a8800, 
frame=0x576bf580) at fftools/ffmpeg.c:1056
#9  0x556a117a in reap_filters (flush=0) at fftools/ffmpeg.c:1546
#10 0x556ad8e5 in transcode_step () at fftools/ffmpeg.c:4643
#11 0x556ad9e7 in transcode () at fftools/ffmpeg.c:4687
#12 0x556ae45c in main (argc=12, argv=0x7fffe1c8) at 
fftools/ffmpeg.c:4903
(gdb) print avc->version
Cannot access memory at address 0xc1528eb7c0ea0157

make -j32 && gdb --args ./ffmpeg_g -ss 8 -i NeroRecodeSample.mp4 -bitexact -t 3 
-filter_complex '[0:2]scale=720:576[v];[v][0:5]overlay' -y file-whitesubs.avi

it appears this file is at:
https://samples.ffmpeg.org/MPEG-4/NeroRecodeSample-MP4/


I can't reproduce this on mingw64.
___
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 277/281] ffmpeg: convert to new channel layout-API

2022-01-13 Thread Michael Niedermayer
On Wed, Jan 12, 2022 at 11:09:09PM -0300, James Almer wrote:
> Signed-off-by: James Almer 
> ---
>  fftools/cmdutils.c| 42 +++-
>  fftools/cmdutils.h|  8 -
>  fftools/ffmpeg.c  | 47 --
>  fftools/ffmpeg.h  |  7 ++--
>  fftools/ffmpeg_filter.c   | 52 ++---
>  fftools/ffmpeg_opt.c  | 62 ++-
>  tests/fate/aac.mak|  2 +-
>  tests/fate/lavf-container.mak |  2 +-
>  8 files changed, 155 insertions(+), 67 deletions(-)

This or a prior patch introduces crashes (it bisected to this but this is my
2nd testcase the first did not reproduce reliably at all)

Thread 1 "ffmpeg_g" received signal SIGSEGV, Segmentation fault.
0x566ed811 in av_vlog (avcl=0x577400c0, level=24, 
fmt=0x568249e8 "%d frames left in the queue on closing\n", 
vl=0x7fffda50) at libavutil/log.c:428
428 if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&
(gdb) bt
#0  0x566ed811 in av_vlog (avcl=0x577400c0, level=24, 
fmt=0x568249e8 "%d frames left in the queue on closing\n", 
vl=0x7fffda50) at libavutil/log.c:428
#1  0x566ed6bd in av_log (avcl=0x577400c0, level=24, 
fmt=0x568249e8 "%d frames left in the queue on closing\n") at 
libavutil/log.c:411
#2  0x55c320b9 in ff_af_queue_close (afq=0x576c47c8) at 
libavcodec/audio_frame_queue.c:39
#3  0x55e84c06 in mp3lame_encode_close (avctx=0x576bf180) at 
libavcodec/libmp3lame.c:86
#4  0x55c373f7 in avcodec_close (avctx=0x576bf180) at 
libavcodec/avcodec.c:489
#5  0x55f7feab in avcodec_free_context (pavctx=0x576a8858) at 
libavcodec/options.c:163
#6  0x5569cfe3 in ffmpeg_cleanup (ret=1) at fftools/ffmpeg.c:608
#7  0x55694817 in exit_program (ret=1) at fftools/cmdutils.c:131
#8  0x5569ef1f in do_audio_out (of=0x576ae2c0, ost=0x576a8800, 
frame=0x576bf580) at fftools/ffmpeg.c:1056
#9  0x556a117a in reap_filters (flush=0) at fftools/ffmpeg.c:1546
#10 0x556ad8e5 in transcode_step () at fftools/ffmpeg.c:4643
#11 0x556ad9e7 in transcode () at fftools/ffmpeg.c:4687
#12 0x556ae45c in main (argc=12, argv=0x7fffe1c8) at 
fftools/ffmpeg.c:4903
(gdb) print avc->version
Cannot access memory at address 0xc1528eb7c0ea0157

make -j32 && gdb --args ./ffmpeg_g -ss 8 -i NeroRecodeSample.mp4 -bitexact -t 3 
-filter_complex '[0:2]scale=720:576[v];[v][0:5]overlay' -y file-whitesubs.avi

it appears this file is at:
https://samples.ffmpeg.org/MPEG-4/NeroRecodeSample-MP4/


Press [q] to stop, [?] for help
[aac @ 0x16fb3540] This stream seems to incorrectly report its last channel as 
SCE[1], mapping to LFE[0]
[aac @ 0x16fb3540] env_facs_q 253 is invalid
==21617==at 0x12A09F8: VALGRIND_PRINTF_BACKTRACE (valgrind.h:6303)
==21617==by 0x12A15B6: av_log_default_callback (log.c:397)
==21617==by 0x12A185D: av_vlog (log.c:432)
==21617==by 0x12A16BC: av_log (log.c:411)
==21617==by 0xEED8B6: read_sbr_envelope (aacsbr_template.c:865)
==21617==by 0xEEE22F: read_sbr_single_channel_element 
(aacsbr_template.c:983)
==21617==by 0xEEE762: read_sbr_data (aacsbr_template.c:1055)
==21617==by 0xEEEAFD: ff_decode_sbr_extension (aacsbr_template.c:1144)
==21617==by 0xECD082: decode_extension_payload (aacdec_template.c:2582)
==21617==by 0xED029B: aac_decode_frame_int (aacdec_template.c:3372)
==21617==by 0xED0842: aac_decode_frame (aacdec_template.c:3500)
==21617==by 0x8ABF66: decode_simple_internal (decode.c:329)
==21617==by 0x8ACB62: decode_simple_receive_frame (decode.c:528)
==21617==by 0x8ACC5C: decode_receive_frame_internal (decode.c:548)
==21617==by 0x8ACF38: avcodec_send_packet (decode.c:615)
==21617==by 0x258160: decode (ffmpeg.c:2276)
==21617==by 0x258354: decode_audio (ffmpeg.c:2319)
==21617==by 0x259949: process_input_packet (ffmpeg.c:2638)
==21617==by 0x26138A: process_input (ffmpeg.c:4493)
==21617==by 0x26187E: transcode_step (ffmpeg.c:4633)
[aac @ 0x16fb3540] env_facs_q 252 is invalid
==21617==at 0x12A09F8: VALGRIND_PRINTF_BACKTRACE (valgrind.h:6303)
==21617==by 0x12A15B6: av_log_default_callback (log.c:397)
==21617==by 0x12A185D: av_vlog (log.c:432)
==21617==by 0x12A16BC: av_log (log.c:411)
==21617==by 0xEED8B6: read_sbr_envelope (aacsbr_template.c:865)
==21617==by 0xEEE5AC: read_sbr_channel_pair_element (aacsbr_template.c:1028)
==21617==by 0xEEE7A7: read_sbr_data (aacsbr_template.c:1060)
==21617==by 0xEEEAFD: ff_decode_sbr_extension (aacsbr_template.c:1144)
==21617==by 0xECD082: decode_extension_payload (aacdec_template.c:2582)
==21617==by 0xED029B: aac_decode_frame_int (aacdec_template.c:3372)
==21617==by 0xED0842: aac_decode_frame (aacdec_template.c:3500)
==21617==by 0x8ABF66: decode_simple_internal (decode.c:329)
==21617==by 0x8ACB62: 

Re: [FFmpeg-devel] [PATCH 12/35] lavc/avcodec: switch to new FIFO API

2022-01-13 Thread Andreas Rheinhardt
Anton Khirnov:
> ---
>  libavcodec/avcodec.c | 15 ++-
>  libavcodec/decode.c  | 22 --
>  2 files changed, 14 insertions(+), 23 deletions(-)
> 
> diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
> index c00a9b2af8..a75bbe721f 100644
> --- a/libavcodec/avcodec.c
> +++ b/libavcodec/avcodec.c
> @@ -183,7 +183,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
> *avctx, const AVCodec *code
>  avci->es.in_frame = av_frame_alloc();
>  avci->in_pkt = av_packet_alloc();
>  avci->last_pkt_props = av_packet_alloc();
> -avci->pkt_props = av_fifo_alloc(sizeof(*avci->last_pkt_props));
> +avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props),
> + AV_FIFO_FLAG_AUTO_GROW);
>  if (!avci->buffer_frame || !avci->buffer_pkt  ||
>  !avci->es.in_frame  || !avci->in_pkt ||
>  !avci->last_pkt_props || !avci->pkt_props) {
> @@ -399,13 +400,10 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
>  av_packet_unref(avci->buffer_pkt);
>  
>  av_packet_unref(avci->last_pkt_props);
> -while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) {
> -av_fifo_generic_read(avci->pkt_props,
> - avci->last_pkt_props, 
> sizeof(*avci->last_pkt_props),
> - NULL);
> +while (av_fifo_can_read(avci->pkt_props)) {
> +av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1);
>  av_packet_unref(avci->last_pkt_props);

Could be simplified to
do {
av_packet_unref(avci->last_pkt_props);
} while (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) >= 0);

The same goes for other loop below and probably more loops in the next
patches.
(This of course presumes that one is allowed to call av_fifo_read() to
tentatively read more elements than are currently available. I think
this should be allowed.)

>  }
> -av_fifo_reset(avci->pkt_props);
>  
>  av_frame_unref(avci->es.in_frame);
>  av_packet_unref(avci->in_pkt);
> @@ -464,10 +462,9 @@ av_cold int avcodec_close(AVCodecContext *avctx)
>  av_frame_free(>buffer_frame);
>  av_packet_free(>buffer_pkt);
>  if (avci->pkt_props) {
> -while (av_fifo_size(avci->pkt_props) >= 
> sizeof(*avci->last_pkt_props)) {
> +while (av_fifo_can_read(avci->pkt_props)) {
>  av_packet_unref(avci->last_pkt_props);
> -av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props,
> - sizeof(*avci->last_pkt_props), NULL);
> +av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1);
>  }
>  av_fifo_freep(>pkt_props);
>  }
> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> index 0912f86a14..9f6f2e7fa6 100644
> --- a/libavcodec/decode.c
> +++ b/libavcodec/decode.c
> @@ -165,26 +165,21 @@ static int extract_packet_props(AVCodecInternal *avci, 
> const AVPacket *pkt)
>  int ret = 0;
>  
>  if (IS_EMPTY(avci->last_pkt_props)) {
> -if (av_fifo_size(avci->pkt_props) >= sizeof(*pkt)) {
> -av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props,
> - sizeof(*avci->last_pkt_props), NULL);
> +if (av_fifo_can_read(avci->pkt_props)) {
> +av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1);
>  } else

if (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) < 0)

>  return copy_packet_props(avci->last_pkt_props, pkt);
>  }
>  
> -if (av_fifo_space(avci->pkt_props) < sizeof(*pkt)) {
> -ret = av_fifo_grow(avci->pkt_props, sizeof(*pkt));
> -if (ret < 0)
> -return ret;
> -}
> -
>  ret = copy_packet_props(, pkt);
>  if (ret < 0)
>  return ret;
>  
> -av_fifo_generic_write(avci->pkt_props, , sizeof(tmp), NULL);
> +ret = av_fifo_write(avci->pkt_props, , 1);
> +if (ret < 0)
> +av_packet_unref();
>  
> -return 0;
> +return ret;
>  }
>  
>  static int decode_bsfs_init(AVCodecContext *avctx)
> @@ -543,9 +538,8 @@ static int decode_receive_frame_internal(AVCodecContext 
> *avctx, AVFrame *frame)
>  avci->draining_done = 1;
>  
>  if (!(avctx->codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS) &&
> -IS_EMPTY(avci->last_pkt_props) && av_fifo_size(avci->pkt_props) >= 
> sizeof(*avci->last_pkt_props))
> -av_fifo_generic_read(avci->pkt_props,
> - avci->last_pkt_props, 
> sizeof(*avci->last_pkt_props), NULL);
> +IS_EMPTY(avci->last_pkt_props) && av_fifo_can_read(avci->pkt_props))

The av_fifo_can_read() check could be dropped.

> +av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1);
>  
>  if (!ret) {
>  frame->best_effort_timestamp = guess_correct_pts(avctx,
> 

___
ffmpeg-devel mailing list

Re: [FFmpeg-devel] [PATCH 09/35] lavu/fifo: add a flag for automatically growing the FIFO as needed

2022-01-13 Thread Andreas Rheinhardt
Anton Khirnov:
> This will not increase the FIFO beyond 1MB, unless the caller explicitly
> specifies otherwise.
> ---
>  doc/APIchanges   |  3 ++-
>  libavutil/fifo.c | 41 +++--
>  libavutil/fifo.h | 15 ++-
>  3 files changed, 55 insertions(+), 4 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index f64759d69d..52b42762ea 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -20,7 +20,8 @@ API changes, most recent first:
>rather than bytes.
>Add av_fifo_elem_size(), av_fifo_can_read(), av_fifo_can_write(),
>av_fifo_grow2(), av_fifo_drain2(), av_fifo_write(), 
> av_fifo_write_from_cb(),
> -  av_fifo_read(), av_fifo_read_to_cb(), av_fifo_peek(), av_fifo_peek_to_cb().
> +  av_fifo_read(), av_fifo_read_to_cb(), av_fifo_peek(), av_fifo_peek_to_cb(),
> +  av_fifo_auto_grow_limit().
>  
>  2022-01-xx - xx - lavu fifo.h
>Access to all AVFifoBuffer members is deprecated. The struct will
> diff --git a/libavutil/fifo.c b/libavutil/fifo.c
> index ea944bc936..2c15df5d5c 100644
> --- a/libavutil/fifo.c
> +++ b/libavutil/fifo.c
> @@ -34,6 +34,9 @@
>  # define CTX_STRUCT_NAME AVFifoBuffer
>  #endif
>  
> +// by default the FIFO can be auto-grown to 1MB
> +#define AUTO_GROW_DEFAULT_BYTES (1024 * 1024)
> +
>  typedef struct CTX_STRUCT_NAME {
>  // These fields must match then contents of AVFifoBuffer in fifo.h
>  // until FF_API_FIFO_PUBLIC is removed
> @@ -48,6 +51,9 @@ typedef struct CTX_STRUCT_NAME {
>  size_t offset_r, offset_w;
>  // distinguishes the ambigous situation offset_r == offset_w
>  intis_empty;
> +
> +unsigned int flags;
> +size_t   auto_grow_limit;
>  } FifoBuffer;
>  
>  AVFifoBuffer *av_fifo_alloc2(size_t nb_elems, size_t elem_size,
> @@ -75,10 +81,19 @@ AVFifoBuffer *av_fifo_alloc2(size_t nb_elems, size_t 
> elem_size,
>  f->nb_elems  = nb_elems;
>  f->elem_size = elem_size;
>  
> +f->flags   = flags;
> +f->auto_grow_limit = FFMAX(AUTO_GROW_DEFAULT_BYTES / elem_size, 1);
> +
>  av_fifo_reset((AVFifoBuffer*)f);
>  return (AVFifoBuffer*)f;
>  }
>  
> +void av_fifo_auto_grow_limit(AVFifoBuffer *f, size_t max_elems)
> +{
> +FifoBuffer *fb = (FifoBuffer*)f;
> +fb->auto_grow_limit = max_elems;
> +}
> +
>  AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size)
>  {
>  if (nmemb > SIZE_MAX / size)
> @@ -207,6 +222,27 @@ void av_fifo_drain2(AVFifoBuffer *f, size_t size)
>  #endif
>  }
>  
> +static int fifo_check_space(AVFifoBuffer *f, size_t to_write)
> +{
> +FifoBuffer *fb = (FifoBuffer*)f;
> +const size_t can_write = av_fifo_can_write(f);
> +const size_t need_grow = to_write > can_write ? to_write - can_write : 0;
> +size_t can_grow;
> +
> +if (!need_grow)
> +return 0;
> +
> +can_grow = fb->auto_grow_limit > fb->nb_elems ?
> +   fb->auto_grow_limit - fb->nb_elems : 0;
> +if ((fb->flags & AV_FIFO_FLAG_AUTO_GROW) && need_grow <= can_grow) {
> +// allocate a bit more than necessary, if we can
> +const size_t inc = (need_grow < can_grow / 2 ) ? need_grow * 2 : 
> can_grow;

This is still linear if one always writes a fixed amount of elements.
Using av_fast_realloc_array() would actually fit very well in here.
Shall I resend a size_t version?

> +return av_fifo_grow2(f, inc);
> +}
> +
> +return AVERROR(ENOSPC);
> +}
> +
>  static int fifo_write_common(AVFifoBuffer *f, const uint8_t *buf, size_t 
> *nb_elems,
>   AVFifoCB read_cb, void *opaque)
>  {
> @@ -218,8 +254,9 @@ static int fifo_write_common(AVFifoBuffer *f, const 
> uint8_t *buf, size_t *nb_ele
>  uint32_t wndx= f->wndx;
>  #endif
>  
> -if (to_write > av_fifo_can_write(f))
> -return AVERROR(ENOSPC);
> +ret = fifo_check_space(f, to_write);
> +if (ret < 0)
> +return ret;
>  
>  do {
>  size_tlen = FFMIN(fb->nb_elems - offset_w, to_write);
> diff --git a/libavutil/fifo.h b/libavutil/fifo.h
> index c7be5e8f7d..11eb36944a 100644
> --- a/libavutil/fifo.h
> +++ b/libavutil/fifo.h
> @@ -83,6 +83,13 @@ AVFifoBuffer *av_fifo_alloc(unsigned int size);
>   */
>  AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size);
>  
> +/**
> + * Automatically resize the FIFO on writes, so that the data fits. This
> + * automatic resizing happens up to a limit that can be modified with
> + * av_fifo_auto_grow_limit().
> + */
> +#define AV_FIFO_FLAG_AUTO_GROW  (1 << 0)
> +
>  /**
>   * Allocate and initialize an AVFifoBuffer with a given element size.
>   *
> @@ -90,7 +97,7 @@ AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t 
> size);
>   * @param nb_elems initial number of elements that can be stored in the FIFO
>   * @param elem_size Size in bytes of a single element. Further operations on
>   *  the returned FIFO will implicitly use this element size.
> - * @param flags currently unused, must be 0
> + * 

Re: [FFmpeg-devel] [PATCH 08/35] lavu/fifo: add new FIFO read/peek functions

2022-01-13 Thread Andreas Rheinhardt
Anton Khirnov:
> As for writing, use separate functions for reading to a buffer and a
> callback. Allow the callbacks to limit the amount of data read,
> similarly to what is done for writing.
> 
> Consistently use size_t for sizes.
> ---
>  doc/APIchanges   |  3 ++-
>  libavutil/fifo.c | 68 
>  libavutil/fifo.h | 60 ++
>  3 files changed, 130 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 0b179c30e5..f64759d69d 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -19,7 +19,8 @@ API changes, most recent first:
>Operations on FIFOs created with this function on these elements
>rather than bytes.
>Add av_fifo_elem_size(), av_fifo_can_read(), av_fifo_can_write(),
> -  av_fifo_grow2(), av_fifo_drain2(), av_fifo_write(), 
> av_fifo_write_from_cb().
> +  av_fifo_grow2(), av_fifo_drain2(), av_fifo_write(), 
> av_fifo_write_from_cb(),
> +  av_fifo_read(), av_fifo_read_to_cb(), av_fifo_peek(), av_fifo_peek_to_cb().
>  
>  2022-01-xx - xx - lavu fifo.h
>Access to all AVFifoBuffer members is deprecated. The struct will
> diff --git a/libavutil/fifo.c b/libavutil/fifo.c
> index 1d94fff457..ea944bc936 100644
> --- a/libavutil/fifo.c
> +++ b/libavutil/fifo.c
> @@ -265,6 +265,74 @@ int av_fifo_write_from_cb(AVFifoBuffer *f, AVFifoCB 
> read_cb,
>  return fifo_write_common(f, NULL, nb_elems, read_cb, opaque);
>  }
>  
> +static int fifo_peek_common(const AVFifoBuffer *f, uint8_t *buf, size_t 
> *nb_elems,
> +size_t offset, AVFifoCB write_cb, void *opaque)
> +{
> +const FifoBuffer *fb = (FifoBuffer*)f;
> +size_t   to_read = *nb_elems;
> +size_t  offset_r = fb->offset_r;
> +int  ret = 0;
> +
> +if (offset > av_fifo_can_read(f) ||
> +to_read > av_fifo_can_read(f) - offset) {

You are calling av_fifo_can_read() multiple times.

> +*nb_elems = 0;
> +return AVERROR(EINVAL);
> +}
> +
> +if (offset_r >= fb->nb_elems - offset)
> +offset_r -= fb->nb_elems - offset;
> +else
> +offset_r += offset;
> +
> +do {

Shouldn't this be a while loop?

> +size_tlen = FFMIN(fb->nb_elems - offset_r, to_read);
> +uint8_t *rptr = f->buffer + offset_r * fb->elem_size;
> +
> +if (write_cb) {
> +ret = write_cb(opaque, rptr, );
> +if (ret < 0 || len == 0)
> +break;
> +} else {
> +memcpy(buf, rptr, len * fb->elem_size);
> +buf += len * fb->elem_size;
> +}
> +offset_r += len;
> +if (offset_r >= fb->nb_elems)
> +offset_r = 0;
> +to_read -= len;
> +} while (to_read > 0);
> +
> +*nb_elems -= to_read;
> +
> +return ret;
> +}
> +
> +int av_fifo_read(AVFifoBuffer *f, void *buf, size_t nb_elems)
> +{
> +int ret = fifo_peek_common(f, buf, _elems, 0, NULL, NULL);
> +av_fifo_drain2(f, nb_elems);

In contrast to the current av_fifo_generic_read() the callback will
still see the non-drained FIFO if the callback is called multiple times.
I don't know whether this slight behaviour change can cause problems
when updating.

> +return ret;
> +}
> +
> +int av_fifo_read_to_cb(AVFifoBuffer *f, AVFifoCB write_cb,
> +   void *opaque, size_t *nb_elems)
> +{
> +int ret = fifo_peek_common(f, NULL, nb_elems, 0, write_cb, opaque);
> +av_fifo_drain2(f, *nb_elems);
> +return ret;
> +}
> +
> +int av_fifo_peek(AVFifoBuffer *f, void *buf, size_t nb_elems, size_t offset)
> +{
> +return fifo_peek_common(f, buf, _elems, offset, NULL, NULL);
> +}
> +
> +int av_fifo_peek_to_cb(AVFifoBuffer *f, AVFifoCB write_cb, void *opaque,
> +   size_t *nb_elems, size_t offset)
> +{
> +return fifo_peek_common(f, NULL, nb_elems, offset, write_cb, opaque);
> +}
> +
>  int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
>  {
>  FifoBuffer *fb = (FifoBuffer*)f;
> diff --git a/libavutil/fifo.h b/libavutil/fifo.h
> index ac1245ff39..c7be5e8f7d 100644
> --- a/libavutil/fifo.h
> +++ b/libavutil/fifo.h
> @@ -189,6 +189,66 @@ int av_fifo_write(AVFifoBuffer *f, const void *buf, 
> size_t nb_elems);
>  int av_fifo_write_from_cb(AVFifoBuffer *f, AVFifoCB read_cb,
>void *opaque, size_t *nb_elems);
>  
> +/**
> + * Read data from a FIFO.
> + *
> + * @param f the FIFO buffer
> + * @param buf Buffer to store the data. nb_elems * av_fifo_elem_size(f) bytes
> + *will be written into buf.
> + * @param nb_elems number of elements to read from FIFO
> + *
> + * @return a non-negative number on success, a negative error code on failure
> + */
> +int av_fifo_read(AVFifoBuffer *f, void *buf, size_t nb_elems);
> +
> +/**
> + * Feed data from a FIFO into a user-provided callback.
> + *
> + * @param f the FIFO buffer
> + * @param write_cb Callback the data will be supplied 

Re: [FFmpeg-devel] [PATCH 07/35] lavu/fifo: add new FIFO writing functions

2022-01-13 Thread Andreas Rheinhardt
Anton Khirnov:
> Use separate functions for writing from a buffer and a callback, since
> the overwhelming majority of callers use a buffer and should not be
> forced to pass extra NULL parameters or use a longer name.
> 
> Consistently use size_t for sizes.
> ---
>  doc/APIchanges   |  2 +-
>  libavutil/fifo.c | 58 
>  libavutil/fifo.h | 46 ++
>  3 files changed, 105 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index f2769d4165..0b179c30e5 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -19,7 +19,7 @@ API changes, most recent first:
>Operations on FIFOs created with this function on these elements
>rather than bytes.
>Add av_fifo_elem_size(), av_fifo_can_read(), av_fifo_can_write(),
> -  av_fifo_grow2(), av_fifo_drain2().
> +  av_fifo_grow2(), av_fifo_drain2(), av_fifo_write(), 
> av_fifo_write_from_cb().
>  
>  2022-01-xx - xx - lavu fifo.h
>Access to all AVFifoBuffer members is deprecated. The struct will
> diff --git a/libavutil/fifo.c b/libavutil/fifo.c
> index e9f439e219..1d94fff457 100644
> --- a/libavutil/fifo.c
> +++ b/libavutil/fifo.c
> @@ -207,6 +207,64 @@ void av_fifo_drain2(AVFifoBuffer *f, size_t size)
>  #endif
>  }
>  
> +static int fifo_write_common(AVFifoBuffer *f, const uint8_t *buf, size_t 
> *nb_elems,
> + AVFifoCB read_cb, void *opaque)

Should be write_cb.

> +{
> +FifoBuffer  *fb = (FifoBuffer*)f;
> +size_t to_write = *nb_elems;

How about calling this "left"?

> +size_t offset_w = fb->offset_w;
> +int ret = 0;
> +#if FF_API_FIFO_PUBLIC
> +uint32_t wndx= f->wndx;
> +#endif
> +
> +if (to_write > av_fifo_can_write(f))
> +return AVERROR(ENOSPC);
> +
> +do {
> +size_tlen = FFMIN(fb->nb_elems - offset_w, to_write);
> +uint8_t *wptr = f->buffer + offset_w * fb->elem_size;
> +
> +if (read_cb) {
> +ret = read_cb(opaque, wptr, );
> +if (ret < 0 || len == 0)
> +break;
> +} else {
> +memcpy(wptr, buf, len * fb->elem_size);
> +buf += len * fb->elem_size;
> +}
> +offset_w += len;
> +if (offset_w >= fb->nb_elems)
> +offset_w = 0;
> +#if FF_API_FIFO_PUBLIC
> +wndx+= len;
> +#endif
> +to_write-= len;
> +} while (to_write > 0);
> +#if FF_API_FIFO_PUBLIC
> +f->wndx= wndx;
> +f->wptr= f->buffer + offset_w * fb->elem_size;
> +#endif
> +fb->offset_w = offset_w;
> +
> +if (*nb_elems - to_write > 0)

to_write < *nb_elems

> +fb->is_empty = 0;
> +*nb_elems -= to_write;
> +
> +return ret;
> +}
> +
> +int av_fifo_write(AVFifoBuffer *f, const void *buf, size_t nb_elems)
> +{
> +return fifo_write_common(f, buf, _elems, NULL, NULL);
> +}
> +
> +int av_fifo_write_from_cb(AVFifoBuffer *f, AVFifoCB read_cb,
> +  void *opaque, size_t *nb_elems)
> +{
> +return fifo_write_common(f, NULL, nb_elems, read_cb, opaque);
> +}
> +
>  int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
>  {
>  FifoBuffer *fb = (FifoBuffer*)f;
> diff --git a/libavutil/fifo.h b/libavutil/fifo.h
> index d593304edb..ac1245ff39 100644
> --- a/libavutil/fifo.h
> +++ b/libavutil/fifo.h
> @@ -44,6 +44,24 @@ typedef struct AVFifoBuffer
>  #endif
>  AVFifoBuffer;
>  
> +/**
> + * Callback for writing or reading from a FIFO, passed to (and invoked from) 
> the
> + * av_fifo_*_cb() functions. It may be invoked multiple times from a single
> + * av_fifo_*_cb() call and may process less data than the maximum size 
> indicated
> + * by nb_elems.
> + *
> + * @param opaque the opaque pointer provided to the av_fifo_*_cb() function
> + * @param buf the buffer for reading or writing the data, depending on which
> + *av_fifo_*_cb function is called
> + * @param nb_elems On entry contains the maximum number of elements that can 
> be
> + * read from / written into buf. On success, the callback 
> should
> + * update it to contain the number of elements actually 
> written.

The last sentence is write-only, although this callback is also used for
reading.

> + *
> + * @return 0 on success, a negative error code on failure (will be returned 
> from
> + * the invoking av_fifo_*_cb() function)
> + */
> +typedef int AVFifoCB(void *opaque, void *buf, size_t *nb_elems);
> +
>  /**
>   * Initialize an AVFifoBuffer.
>   * @param size of FIFO
> @@ -143,6 +161,34 @@ size_t av_fifo_can_write(const AVFifoBuffer *f);
>   */
>  int av_fifo_grow2(AVFifoBuffer *f, size_t inc);
>  
> +/**
> + * Write data into a FIFO.
> + *
> + * @param f the FIFO buffer
> + * @param buf Data to be written. nb_elems * av_fifo_elem_size(f) bytes will 
> be
> + *read from buf.
> + * @param nb_elems number of elements to write into FIFO
> + *
> + * @return a non-negative number 

Re: [FFmpeg-devel] [PATCH 05/35] lavu/fifo: add a new FIFO grow function

2022-01-13 Thread James Almer




On 1/11/2022 5:45 PM, Anton Khirnov wrote:

Consistently use size_t for sizes.

Unlike av_fifo_grow(), which addds to the currently used size, this
function adds to the allocated size.

No new function is provided for a generic realloc, since the current code
only supports increasing the FIFO size.
---
  doc/APIchanges   |  3 ++-
  libavutil/fifo.c | 61 +++-
  libavutil/fifo.h | 14 +++
  3 files changed, 50 insertions(+), 28 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 9400c5147a..98eae55719 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -18,7 +18,8 @@ API changes, most recent first:
Add av_fifo_alloc2(), which allows setting a FIFO element size.
Operations on FIFOs created with this function on these elements
rather than bytes.
-  Add av_fifo_elem_size(), av_fifo_can_read(), av_fifo_can_write().
+  Add av_fifo_elem_size(), av_fifo_can_read(), av_fifo_can_write(),
+  av_fifo_grow2().
  
  2022-01-xx - xx - lavu fifo.h

Access to all AVFifoBuffer members is deprecated. The struct will
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 8cde2c20e1..28d6d1b2e6 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -150,41 +150,48 @@ int av_fifo_space(const AVFifoBuffer *f)
  return av_fifo_can_write(f);
  }
  
-int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)

+int av_fifo_grow2(AVFifoBuffer *f, size_t inc)
  {
  FifoBuffer *fb = (FifoBuffer*)f;
+uint8_t *tmp;
  
-if (new_size > FIFO_SIZE_MAX)

+if (inc > FIFO_SIZE_MAX - fb->nb_elems)
  return AVERROR(EINVAL);
  
-if (fb->nb_elems < new_size) {

-uint8_t *tmp;
-
-tmp = av_realloc_array(f->buffer, new_size, fb->elem_size);
-if (!tmp)
-return AVERROR(ENOMEM);
-
-// move the data from the beginning of the ring buffer
-// to the newly allocated space
-if (fb->offset_w <= fb->offset_r && !fb->is_empty) {
-const size_t copy = FFMIN(new_size - fb->nb_elems, fb->offset_w);
-memcpy(tmp + fb->nb_elems * fb->elem_size, tmp, copy * 
fb->elem_size);
-if (copy < fb->offset_w) {
-memmove(tmp, tmp + copy * fb->elem_size,
-(fb->offset_w - copy) * fb->elem_size);
-fb->offset_w -= copy;
-} else
-fb->offset_w = fb->nb_elems + copy;
-}
+tmp = av_realloc_array(f->buffer, fb->nb_elems + inc, fb->elem_size);


This sounds like a good opportunity to introduce av_fast_realloc_array() 
in mem.h, with FifoBuffer being a private struct where you can safely 
store the required buffer size field.


av_realloc_array() can be slow in an auto-grow scenario if there's a lot 
of buffering before stuff starts being drained.



+if (!tmp)
+return AVERROR(ENOMEM);
+
+// move the data from the beginning of the ring buffer
+// to the newly allocated space
+if (fb->offset_w <= fb->offset_r && !fb->is_empty) {
+const size_t copy = FFMIN(inc, fb->offset_w);
+memcpy(tmp + fb->nb_elems * fb->elem_size, tmp, copy * fb->elem_size);
+if (copy < fb->offset_w) {
+memmove(tmp, tmp + copy * fb->elem_size,
+(fb->offset_w - copy) * fb->elem_size);
+fb->offset_w -= copy;
+} else
+fb->offset_w = fb->nb_elems + copy;
+}
+
+f->buffer = tmp;
+fb->nb_elems += inc;
  
-f->buffer = tmp;

  #if FF_API_FIFO_PUBLIC
-f->end= f->buffer + new_size;
-f->rptr   = f->buffer + fb->offset_r * fb->elem_size;
-f->wptr   = f->buffer + fb->offset_w * fb->elem_size;
+f->end= f->buffer + fb->nb_elems * fb->elem_size;
+f->rptr   = f->buffer + fb->offset_r * fb->elem_size;
+f->wptr   = f->buffer + fb->offset_w * fb->elem_size;
  #endif
-fb->nb_elems = new_size;
-}
+
+return 0;
+}
+
+int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
+{
+FifoBuffer *fb = (FifoBuffer*)f;
+if (fb->nb_elems < new_size)
+return av_fifo_grow2(f, new_size - fb->nb_elems);
  return 0;
  }
  
diff --git a/libavutil/fifo.h b/libavutil/fifo.h

index 9e78082b3b..375d0d133b 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -129,6 +129,20 @@ size_t av_fifo_can_read(const AVFifoBuffer *f);
   */
  size_t av_fifo_can_write(const AVFifoBuffer *f);
  
+/**

+ * Enlarge an AVFifoBuffer.
+ *
+ * On success, the FIFO will be large enough to hold exactly
+ * inc + av_fifo_can_read() + av_fifo_can_write()
+ * elements. In case of failure, the old FIFO is kept unchanged.
+ *
+ * @param f AVFifoBuffer to resize
+ * @param inc number of elements to allocate for, in addition to the current
+ *allocated size
+ * @return a non-negative number on success, a negative error code on failure
+ */
+int av_fifo_grow2(AVFifoBuffer *f, size_t inc);
+
  /**
   * Feed data at specific position from an AVFifoBuffer to 

Re: [FFmpeg-devel] [PATCH 03/35] lavu/fifo: introduce the notion of element size

2022-01-13 Thread James Almer




On 1/11/2022 5:45 PM, Anton Khirnov wrote:

+/**
+ * Allocate and initialize an AVFifoBuffer with a given element size.
+ *
+ * @param f pointer to the newly-allocated FIFO will be written here on success
+ * @param nb_elems initial number of elements that can be stored in the FIFO
+ * @param elem_size Size in bytes of a single element. Further operations on
+ *  the returned FIFO will implicitly use this element size.
+ * @param flags currently unused, must be 0
+ *
+ * @return newly-allocated AVFifoBuffer on success, a negative error code on 
failure
+ */
+AVFifoBuffer *av_fifo_alloc2(size_t elems, size_t elem_size,
+ unsigned int flags);


The documentation doesn't match the 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".


Re: [FFmpeg-devel] [PATCH 03/35] lavu/fifo: introduce the notion of element size

2022-01-13 Thread Andreas Rheinhardt
Anton Khirnov:
> Many AVFifoBuffer users operate on fixed-size elements (e.g. pointers),
> but the current FIFO API deals exclusively in bytes, requiring extra
> complexity in all these callers.
> 
> Add a new AVFifoBuffer constructor creating a FIFO with an element size
> that may be larger than a byte. All operations on such a FIFO then
> operate on complete elements.
> ---
>  doc/APIchanges  |   6 ++
>  libavutil/fifo.c| 194 ++--
>  libavutil/fifo.h|  53 +---
>  libavutil/version.h |   2 +-
>  4 files changed, 179 insertions(+), 76 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 21fa02ae9d..5646cf2278 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -14,6 +14,12 @@ libavutil: 2021-04-27
>  
>  API changes, most recent first:
>  
> +2022-01-xx - xx - lavu 57.19.100 - fifo.h
> +  Add av_fifo_alloc2(), which allows setting a FIFO element size.
> +  Operations on FIFOs created with this function on these elements
> +  rather than bytes.
> +  Add av_fifo_elem_size().
> +
>  2022-01-xx - xx - lavu fifo.h
>Access to all AVFifoBuffer members is deprecated. The struct will
>become an incomplete type in a future major libavutil version.
> diff --git a/libavutil/fifo.c b/libavutil/fifo.c
> index aaade01333..fc7c93470f 100644
> --- a/libavutil/fifo.c
> +++ b/libavutil/fifo.c
> @@ -38,20 +38,28 @@ typedef struct CTX_STRUCT_NAME {
>  // These fields must match then contents of AVFifoBuffer in fifo.h
>  // until FF_API_FIFO_PUBLIC is removed
>  uint8_t *buffer;
> +#if FF_API_FIFO_PUBLIC
>  uint8_t *rptr, *wptr, *end;
>  uint32_t rndx, wndx;
> +#endif
>  /
> +
> +size_t elem_size, nb_elems;
> +size_t offset_r, offset_w;
> +// distinguishes the ambigous situation offset_r == offset_w

ambiguous

> +intis_empty;
>  } FifoBuffer;
>  
> -AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size)
> +AVFifoBuffer *av_fifo_alloc2(size_t nb_elems, size_t elem_size,
> + unsigned int flags)
>  {
>  FifoBuffer *f;
>  void *buffer;
>  
> -if (nmemb > FIFO_SIZE_MAX / size)
> +if (nb_elems > FIFO_SIZE_MAX / elem_size)
>  return NULL;
>  
> -buffer = av_realloc_array(NULL, nmemb, size);
> +buffer = av_realloc_array(NULL, nb_elems, elem_size);
>  if (!buffer)
>  return NULL;
>  f = av_mallocz(sizeof(*f));
> @@ -60,11 +68,24 @@ AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t 
> size)
>  return NULL;
>  }
>  f->buffer = buffer;
> -f->end= f->buffer + nmemb * size;
> +#if FF_API_FIFO_PUBLIC
> +f->end= f->buffer + nb_elems * elem_size;
> +#endif
> +
> +f->nb_elems  = nb_elems;
> +f->elem_size = elem_size;
> +
>  av_fifo_reset((AVFifoBuffer*)f);
>  return (AVFifoBuffer*)f;
>  }
>  
> +AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size)
> +{
> +if (nmemb > SIZE_MAX / size)
> +return NULL;
> +return av_fifo_alloc2(nmemb * size, 1, 0);
> +}
> +
>  AVFifoBuffer *av_fifo_alloc(unsigned int size)
>  {
>  return av_fifo_alloc_array(size, 1);
> @@ -88,67 +109,85 @@ void av_fifo_freep(AVFifoBuffer **f)
>  
>  void av_fifo_reset(AVFifoBuffer *f)
>  {
> +FifoBuffer *fb = (FifoBuffer*)f;
> +
> +fb->offset_r = 0;
> +fb->offset_w = 0;
> +fb->is_empty = 1;
> +#if FF_API_FIFO_PUBLIC
>  f->wptr = f->rptr = f->buffer;
>  f->wndx = f->rndx = 0;
> +#endif
> +}
> +
> +size_t av_fifo_elem_size(const AVFifoBuffer *f)
> +{
> +const FifoBuffer *fb = (const FifoBuffer*)f;
> +return fb->elem_size;
>  }
>  
>  int av_fifo_size(const AVFifoBuffer *f)
>  {
> -return (uint32_t)(f->wndx - f->rndx);
> +const FifoBuffer *fb = (const FifoBuffer*)f;
> +if (fb->offset_w <= fb->offset_r && !fb->is_empty)
> +return fb->nb_elems - fb->offset_r + fb->offset_w;
> +return fb->offset_w - fb->offset_r;
>  }
>  
>  int av_fifo_space(const AVFifoBuffer *f)
>  {
> -return f->end - f->buffer - av_fifo_size(f);
> +const FifoBuffer *fb = (const FifoBuffer*)f;
> +return fb->nb_elems - av_fifo_size(f);
>  }
>  
>  int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
>  {
> -unsigned int old_size = f->end - f->buffer;
> +FifoBuffer *fb = (FifoBuffer*)f;
>  
>  if (new_size > FIFO_SIZE_MAX)
>  return AVERROR(EINVAL);
>  
> -if (old_size < new_size) {
> -size_t offset_r = f->rptr - f->buffer;
> -size_t offset_w = f->wptr - f->buffer;
> +if (fb->nb_elems < new_size) {
>  uint8_t *tmp;
>  
> -tmp = av_realloc(f->buffer, new_size);
> +tmp = av_realloc_array(f->buffer, new_size, fb->elem_size);
>  if (!tmp)
>  return AVERROR(ENOMEM);
>  
>  // move the data from the beginning of the ring buffer
>  // to the newly allocated space
> -// the second 

[FFmpeg-devel] [PATCH] avutil/fifo: Use av_fifo_generic_peek_at() for av_fifo_generic_peek()

2022-01-13 Thread Andreas Rheinhardt
Avoids code duplication. It furthermore properly checks
for buf_size to be > 0 before doing anything.

Signed-off-by: Andreas Rheinhardt 
---
It also avoids having to update yet another function when
the FIFO implementation is updated.
I pondered changing av_fifo_generic_read() to

int ret = av_fifo_generic_peek();
if (ret < 0)
return ret;
av_fifo_drain(f, buf_size);
return 0;

but decided against it because the current implementation already
drains the FIFO after each call to the read function, so that
the user may already see the FIFO internals updated on the second
call to the read function.
Of course, one could use a common backend for all three functions.

 libavutil/fifo.c | 21 +
 1 file changed, 1 insertion(+), 20 deletions(-)

diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index d741bdd395..e1f2175530 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -194,26 +194,7 @@ int av_fifo_generic_peek_at(AVFifoBuffer *f, void *dest, 
int offset, int buf_siz
 int av_fifo_generic_peek(AVFifoBuffer *f, void *dest, int buf_size,
  void (*func)(void *, void *, int))
 {
-uint8_t *rptr = f->rptr;
-
-if (buf_size > av_fifo_size(f))
-return AVERROR(EINVAL);
-
-do {
-int len = FFMIN(f->end - rptr, buf_size);
-if (func)
-func(dest, rptr, len);
-else {
-memcpy(dest, rptr, len);
-dest = (uint8_t *)dest + len;
-}
-rptr += len;
-if (rptr >= f->end)
-rptr -= f->end - f->buffer;
-buf_size -= len;
-} while (buf_size > 0);
-
-return 0;
+return av_fifo_generic_peek_at(f, dest, 0, buf_size, func);
 }
 
 int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size,
-- 
2.32.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".


Re: [FFmpeg-devel] [PATCH 01/35] lavu/fifo: disallow overly large fifo sizes

2022-01-13 Thread Andreas Rheinhardt
Anton Khirnov:
> Quoting Andreas Rheinhardt (2022-01-13 14:59:49)
>> Anton Khirnov:
>>> The API currently allows creating FIFOs up to
>>> - UINT_MAX: av_fifo_alloc(), av_fifo_realloc(), av_fifo_grow()
>>> - SIZE_MAX: av_fifo_alloc_array()
>>> However the usable limit is determined by
>>> - rndx/wndx being uint32_t
>>> - av_fifo_[size,space] returning int
>>> so no FIFO should be larger than the smallest of
>>> - INT_MAX
>>> - UINT32_MAX
>>> - SIZE_MAX
>>> (which should be INT_MAX an all commonly used platforms).
>>> Return an error on trying to allocate FIFOs larger than this limit.
>>> ---
>>>  libavutil/fifo.c | 14 +-
>>>  1 file changed, 13 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/libavutil/fifo.c b/libavutil/fifo.c
>>> index d741bdd395..f2f046b1f3 100644
>>> --- a/libavutil/fifo.c
>>> +++ b/libavutil/fifo.c
>>> @@ -20,14 +20,23 @@
>>>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
>>> 02110-1301 USA
>>>   */
>>>  
>>> +#include 
>>> +
>>>  #include "avassert.h"
>>>  #include "common.h"
>>>  #include "fifo.h"
>>>  
>>> +#define FIFO_SIZE_MAX FFMIN3((uint64_t)INT_MAX, (uint64_t)UINT32_MAX, 
>>> (uint64_t)SIZE_MAX)
>>
>> Aren't these casts unnecessary?
> 
> Possibly yes. I mainly added them so that FIFO_SIZE_MAX is always the
> same type, which might prevent surprises. I can drop the casts if you
> think they are never necessary.
> 

FIFO_SIZE is the type that results after integer promotions of an
expression involving an int, an uint32_t and a size_t parameter; all
three constants are representable in it and FIFO_SIZE is representable
in an int, an uint32_t and size_t. Given that it denotes a size I think
you should cast it to size_t if you want to avoid surprises.

>> And actually dangerous? (They add the implicit requirement that
>> INT_MAX and SIZE_MAX fit into an uint64_t.)
> 
> I'll grant you _theoretically_ dangerous - I've never heard of a
> posix-compliant platform with sizeof(int) > 64.

sizeof(int) > 8 you mean? (Or even better: UINT_MAX > UINT64_MAX.)

> 
> And in any case that macro should be gone with the old API (was going to
> include a patch scheduling its removal, but apparently forgot - will
> send it later).
> 

___
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/35] lavu/fifo: disallow overly large fifo sizes

2022-01-13 Thread Anton Khirnov
Quoting Andreas Rheinhardt (2022-01-13 14:59:49)
> Anton Khirnov:
> > The API currently allows creating FIFOs up to
> > - UINT_MAX: av_fifo_alloc(), av_fifo_realloc(), av_fifo_grow()
> > - SIZE_MAX: av_fifo_alloc_array()
> > However the usable limit is determined by
> > - rndx/wndx being uint32_t
> > - av_fifo_[size,space] returning int
> > so no FIFO should be larger than the smallest of
> > - INT_MAX
> > - UINT32_MAX
> > - SIZE_MAX
> > (which should be INT_MAX an all commonly used platforms).
> > Return an error on trying to allocate FIFOs larger than this limit.
> > ---
> >  libavutil/fifo.c | 14 +-
> >  1 file changed, 13 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavutil/fifo.c b/libavutil/fifo.c
> > index d741bdd395..f2f046b1f3 100644
> > --- a/libavutil/fifo.c
> > +++ b/libavutil/fifo.c
> > @@ -20,14 +20,23 @@
> >   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
> > 02110-1301 USA
> >   */
> >  
> > +#include 
> > +
> >  #include "avassert.h"
> >  #include "common.h"
> >  #include "fifo.h"
> >  
> > +#define FIFO_SIZE_MAX FFMIN3((uint64_t)INT_MAX, (uint64_t)UINT32_MAX, 
> > (uint64_t)SIZE_MAX)
> 
> Aren't these casts unnecessary?

Possibly yes. I mainly added them so that FIFO_SIZE_MAX is always the
same type, which might prevent surprises. I can drop the casts if you
think they are never necessary.

> And actually dangerous? (They add the implicit requirement that
> INT_MAX and SIZE_MAX fit into an uint64_t.)

I'll grant you _theoretically_ dangerous - I've never heard of a
posix-compliant platform with sizeof(int) > 64.

And in any case that macro should be gone with the old API (was going to
include a patch scheduling its removal, but apparently forgot - will
send it later).

-- 
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 02/35] lavu/fifo: make the contents of AVFifoBuffer private on next major bump

2022-01-13 Thread Andreas Rheinhardt
Anton Khirnov:
> There should be no good reason for the callers to access any of its
> contents.
> 
> Define a new type for the internal struct that currently matches
> AVFifoBuffer. This will allow adding new private fields without waiting
> for the major bump and will be useful in the following commits.
> 
> Unfortunately AVFifoBuffer fields cannot be marked as deprecated because
> it would trigger a warning wherever fifo.h is #included, due to
> inlined av_fifo_peek2().
> ---
>  doc/APIchanges |  4 
>  libavutil/fifo.c   | 23 +++
>  libavutil/fifo.h   | 14 --
>  libavutil/tests/fifo.c |  2 +-
>  libavutil/version.h|  1 +
>  5 files changed, 37 insertions(+), 7 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 8df0364e4c..21fa02ae9d 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -14,6 +14,10 @@ libavutil: 2021-04-27
>  
>  API changes, most recent first:
>  
> +2022-01-xx - xx - lavu fifo.h
> +  Access to all AVFifoBuffer members is deprecated. The struct will
> +  become an incomplete type in a future major libavutil version.
> +
>  2022-01-04 - 78dc21b123e - lavu 57.16.100 - frame.h
>Add AV_FRAME_DATA_DOVI_METADATA.
>  
> diff --git a/libavutil/fifo.c b/libavutil/fifo.c
> index f2f046b1f3..aaade01333 100644
> --- a/libavutil/fifo.c
> +++ b/libavutil/fifo.c
> @@ -28,9 +28,24 @@
>  
>  #define FIFO_SIZE_MAX FFMIN3((uint64_t)INT_MAX, (uint64_t)UINT32_MAX, 
> (uint64_t)SIZE_MAX)
>  
> +#if FF_API_FIFO_PUBLIC
> +# define CTX_STRUCT_NAME FifoBuffer
> +#else
> +# define CTX_STRUCT_NAME AVFifoBuffer

This is invalid in pre-C11 (and will lead to compilation failures on old
GCC versions): Pre-C11, typedefs were subject to the ODR, yet you
already typedef AVFifoBuffer in fifo.h.

> +#endif
> +
> +typedef struct CTX_STRUCT_NAME {
> +// These fields must match then contents of AVFifoBuffer in fifo.h

the contents

> +// until FF_API_FIFO_PUBLIC is removed

The actual spec-compliant way for this is to add an AVFifoBuffer at the
start of this struct; it will also avoid the casts from FifoBuffer to
AVFifoBuffer. This will make the accesses to it a bit more cumbersome
and will mean more changes when FF_API_FIFO_PUBLIC is removed. (This
would not be an issue if we required support for anonymous structs
(mandatory in C11, supported by GCC and others long before that).)

> +uint8_t *buffer;
> +uint8_t *rptr, *wptr, *end;
> +uint32_t rndx, wndx;
> +/
> +} FifoBuffer;
> +
>  AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size)
>  {
> -AVFifoBuffer *f;
> +FifoBuffer *f;
>  void *buffer;
>  
>  if (nmemb > FIFO_SIZE_MAX / size)
> @@ -39,15 +54,15 @@ AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t 
> size)
>  buffer = av_realloc_array(NULL, nmemb, size);
>  if (!buffer)
>  return NULL;
> -f = av_mallocz(sizeof(AVFifoBuffer));
> +f = av_mallocz(sizeof(*f));
>  if (!f) {
>  av_free(buffer);
>  return NULL;
>  }
>  f->buffer = buffer;
>  f->end= f->buffer + nmemb * size;
> -av_fifo_reset(f);
> -return f;
> +av_fifo_reset((AVFifoBuffer*)f);
> +return (AVFifoBuffer*)f;
>  }
>  
>  AVFifoBuffer *av_fifo_alloc(unsigned int size)
> diff --git a/libavutil/fifo.h b/libavutil/fifo.h
> index f4fd291e59..ca4e7fe060 100644
> --- a/libavutil/fifo.h
> +++ b/libavutil/fifo.h
> @@ -28,11 +28,21 @@
>  #include "avutil.h"
>  #include "attributes.h"
>  
> -typedef struct AVFifoBuffer {
> +#if FF_API_FIFO_PUBLIC
> +/**
> + * The contents of the struct are private and should not be accessed by the
> + * callers in any way.
> + */
> +#endif
> +typedef struct AVFifoBuffer
> +#if FF_API_FIFO_PUBLIC
> +{
>  uint8_t *buffer;
>  uint8_t *rptr, *wptr, *end;
>  uint32_t rndx, wndx;
> -} AVFifoBuffer;
> +}
> +#endif
> +AVFifoBuffer;
>  
>  /**
>   * Initialize an AVFifoBuffer.
> diff --git a/libavutil/tests/fifo.c b/libavutil/tests/fifo.c
> index a17d913233..e5aa88d252 100644
> --- a/libavutil/tests/fifo.c
> +++ b/libavutil/tests/fifo.c
> @@ -18,7 +18,7 @@
>  
>  #include 
>  #include 
> -#include "libavutil/fifo.h"
> +#include "libavutil/fifo.c"
>  
>  int main(void)
>  {
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 953aac9d94..7c031f547e 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -110,6 +110,7 @@
>  #define FF_API_COLORSPACE_NAME  (LIBAVUTIL_VERSION_MAJOR < 58)
>  #define FF_API_AV_MALLOCZ_ARRAY (LIBAVUTIL_VERSION_MAJOR < 58)
>  #define FF_API_FIFO_PEEK2   (LIBAVUTIL_VERSION_MAJOR < 58)
> +#define FF_API_FIFO_PUBLIC  (LIBAVUTIL_VERSION_MAJOR < 58)
>  
>  /**
>   * @}
> 

___
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 

Re: [FFmpeg-devel] [PATCH 13/35] lavc/amfenc: switch to new FIFO API

2022-01-13 Thread Michael Niedermayer
On Wed, Jan 12, 2022 at 08:29:54PM +0100, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2022-01-12 15:46:45)
> > On Tue, Jan 11, 2022 at 09:45:48PM +0100, Anton Khirnov wrote:
> > > ---
> > >  fftools/ffmpeg_mux.c | 22 +++---
> > 
> > This doesnt seem to apply to git master without some other patches
> 
> sorry, should have mentioned this is on top of my ffmpeg.c patchset
> 
> You can look at the tree at
> git://git.khirnov.net/libav
> branch fifo

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Take away the freedom of one citizen and you will be jailed, take away
the freedom of all citizens and you will be congratulated by your peers
in Parliament.


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


Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API

2022-01-13 Thread Lynne
13 Jan 2022, 02:49 by jamr...@gmail.com:

> From: Anton Khirnov 
>
> The new API is more extensible and allows for custom layouts.
> More accurate information is exported, eg for decoders that do not
> set a channel layout, lavc will not make one up for them.
>
> Deprecate the old API working with just uint64_t bitmasks.
>
> Expanded and completed by Vittorio Giovara 
> and James Almer .
> Signed-off-by: Vittorio Giovara 
> Signed-off-by: James Almer 
> ---
>  libavutil/channel_layout.c | 629 -
>  libavutil/channel_layout.h | 542 ++--
>  libavutil/version.h|   1 +
>  3 files changed, 1069 insertions(+), 103 deletions(-)
>

API looks good to me now.
___
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/35] lavu/fifo: disallow overly large fifo sizes

2022-01-13 Thread Andreas Rheinhardt
Anton Khirnov:
> The API currently allows creating FIFOs up to
> - UINT_MAX: av_fifo_alloc(), av_fifo_realloc(), av_fifo_grow()
> - SIZE_MAX: av_fifo_alloc_array()
> However the usable limit is determined by
> - rndx/wndx being uint32_t
> - av_fifo_[size,space] returning int
> so no FIFO should be larger than the smallest of
> - INT_MAX
> - UINT32_MAX
> - SIZE_MAX
> (which should be INT_MAX an all commonly used platforms).
> Return an error on trying to allocate FIFOs larger than this limit.
> ---
>  libavutil/fifo.c | 14 +-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/fifo.c b/libavutil/fifo.c
> index d741bdd395..f2f046b1f3 100644
> --- a/libavutil/fifo.c
> +++ b/libavutil/fifo.c
> @@ -20,14 +20,23 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
>   */
>  
> +#include 
> +
>  #include "avassert.h"
>  #include "common.h"
>  #include "fifo.h"
>  
> +#define FIFO_SIZE_MAX FFMIN3((uint64_t)INT_MAX, (uint64_t)UINT32_MAX, 
> (uint64_t)SIZE_MAX)

Aren't these casts unnecessary? And actually dangerous? (They add the
implicit requirement that INT_MAX and SIZE_MAX fit into an uint64_t.)

> +
>  AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size)
>  {
>  AVFifoBuffer *f;
> -void *buffer = av_realloc_array(NULL, nmemb, size);
> +void *buffer;
> +
> +if (nmemb > FIFO_SIZE_MAX / size)
> +return NULL;
> +
> +buffer = av_realloc_array(NULL, nmemb, size);
>  if (!buffer)
>  return NULL;
>  f = av_mallocz(sizeof(AVFifoBuffer));
> @@ -82,6 +91,9 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
>  {
>  unsigned int old_size = f->end - f->buffer;
>  
> +if (new_size > FIFO_SIZE_MAX)
> +return AVERROR(EINVAL);
> +
>  if (old_size < new_size) {
>  size_t offset_r = f->rptr - f->buffer;
>  size_t offset_w = f->wptr - f->buffer;
> 

___
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] 5.0 blocking issues

2022-01-13 Thread James Almer




On 1/13/2022 1:02 AM, Xiang, Haihao wrote:

On Wed, 2022-01-12 at 21:35 +, Soft Works wrote:

-Original Message-
From: ffmpeg-devel  On Behalf Of Michael
Niedermayer
Sent: Wednesday, January 12, 2022 5:31 PM
To: FFmpeg development discussions and patches 
Subject: Re: [FFmpeg-devel] 5.0 blocking issues

On Wed, Jan 12, 2022 at 07:37:03AM +0100, Lynne wrote:

8 Jan 2022, 17:30 by mich...@niedermayer.cc:


Hi all

This is a simple go/no go call
if you know of something that still should go into 5.0 please reply here
with a list of what you are working on and a timelimit until when you
will be done with it

if you think everything is ready for the release, then too feel free to
reply (assuming few others said ok yet) this is not supposed to become a
100 reply thread with oks, just maybe 2-3 people confirming that noone
is aware of things missing.

I intend to do the release within 2-3 days of all "no go" things being
resolved or timeouting

thx



Both of elenril and mkver's patches got merged, isn't it
time to tag and make archives already?


something is not working efficiently here
There have been more replies here than from elenril and mkver
also there have been over the ML multiple requests for backports
to 5.0 today. (which may or may not be all unimportant)
We do need a better way to detect when a branch is ready for release
or master is ready to be branched.
Iam really bad at keeping track of everything everyone asks to be
included and then notice when it was included fully with nothing
missing and no amendmends.
Maybe we could put a RELEASE_BLOCKER file in release branches in the future
and everyone can list in it what needs to be done before the release
and when something is done the person pushing would also remove that
line from the file.

for 5.0 now, i guess this is a 2nd go/no go call here
anything else that I should wait for ?
if not i will make the release _probably_ in the next 2-3 days or so
(if nothing interferes)



[PATCH v4] avfilter/vpp_qsv: fix regression on older api versions (e.g. 1.11)

Published-As:
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-15%2Fsoftworkz%2Fqsv_vpp_regression-v4
  
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/15

Patchwork:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/pull.15.v4.ffstaging.ffmpeg.1641538891098.ffmpegag...@gmail.com/

=> Has been merged in to master



It would be better to include this fix in 5.0 release. May I cherry-pick this
patch to the release branch ?


It's a bug fix, not a feature addition or behavior change, so it matches 
the criteria for backporting. Feel free to do it.




Thanks
Haihao




[PATCH] avcodec/dvdsubdec: fix incorrect yellow appearance of dvd subtitles

Published-As:
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-16%2Fsoftworkz%2Fpatch_dvdsubdec_fix-v1
  
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/16

Patchwork:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/pull.16.ffstaging.ffmpeg.1641262759164.ffmpegag...@gmail.com/

=> not merged yet


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

___
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 24/28] ffmpeg_mux: drop a useless check and reduce indentation

2022-01-13 Thread Andreas Rheinhardt
Anton Khirnov:
> do_video_stats() is only ever called for video.
> ---
>  fftools/ffmpeg_mux.c | 42 --
>  1 file changed, 20 insertions(+), 22 deletions(-)
> 
> diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
> index 76d9d4b9c4..8a64661c9c 100644
> --- a/fftools/ffmpeg_mux.c
> +++ b/fftools/ffmpeg_mux.c
> @@ -72,31 +72,29 @@ static void do_video_stats(OutputStream *ost, int 
> frame_size)
>  }
>  
>  enc = ost->enc_ctx;
> -if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
> -frame_number = ost->st->nb_frames;
> -if (vstats_version <= 1) {
> -fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number,
> -ost->quality / (float)FF_QP2LAMBDA);
> -} else  {
> -fprintf(vstats_file, "out= %2d st= %2d frame= %5d q= %2.1f ", 
> ost->file_index, ost->index, frame_number,
> -ost->quality / (float)FF_QP2LAMBDA);
> -}
> +frame_number = ost->st->nb_frames;
> +if (vstats_version <= 1) {
> +fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number,
> +ost->quality / (float)FF_QP2LAMBDA);
> +} else  {
> +fprintf(vstats_file, "out= %2d st= %2d frame= %5d q= %2.1f ", 
> ost->file_index, ost->index, frame_number,
> +ost->quality / (float)FF_QP2LAMBDA);
> +}
>  
> -if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR))
> -fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / 
> (enc->width * enc->height * 255.0 * 255.0)));
> +if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR))
> +fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / 
> (enc->width * enc->height * 255.0 * 255.0)));
>  
> -fprintf(vstats_file,"f_size= %6d ", frame_size);
> -/* compute pts value */
> -ti1 = av_stream_get_end_pts(ost->st) * av_q2d(ost->st->time_base);
> -if (ti1 < 0.01)
> -ti1 = 0.01;
> +fprintf(vstats_file,"f_size= %6d ", frame_size);
> +/* compute pts value */
> +ti1 = av_stream_get_end_pts(ost->st) * av_q2d(ost->st->time_base);
> +if (ti1 < 0.01)
> +ti1 = 0.01;
>  
> -bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;
> -avg_bitrate = (double)(ost->data_size * 8) / ti1 / 1000.0;
> -fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s 
> avg_br= %7.1fkbits/s ",
> -   (double)ost->data_size / 1024, ti1, bitrate, avg_bitrate);
> -fprintf(vstats_file, "type= %c\n", 
> av_get_picture_type_char(ost->pict_type));
> -}
> +bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;
> +avg_bitrate = (double)(ost->data_size * 8) / ti1 / 1000.0;
> +fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s 
> avg_br= %7.1fkbits/s ",
> +   (double)ost->data_size / 1024, ti1, bitrate, avg_bitrate);
> +fprintf(vstats_file, "type= %c\n", 
> av_get_picture_type_char(ost->pict_type));
>  }
>  
>  static void close_all_output_streams(OutputStream *ost, OSTFinished 
> this_stream, OSTFinished others)
> 

LGTM to removing the check, but it would be better if you removed the
check before moving the code to ffmpeg_mux.c and then fixed the
indentation while moving the code to ffmpeg_mux.c.

- 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 17/28] ffmpeg: move the mux queue into muxer private data

2022-01-13 Thread Andreas Rheinhardt
Anton Khirnov:
> The muxing queue currently lives in OutputStream, which is a very large
> struct storing the state for both encoding and muxing. The muxing queue
> is only used by the code in ffmpeg_mux, so it makes sense to restrict it
> to that file.
> 
> This makes the first step towards reducing the scope of OutputStream.
> ---
>  fftools/ffmpeg.c |  9 -
>  fftools/ffmpeg.h |  9 -
>  fftools/ffmpeg_mux.c | 91 
>  fftools/ffmpeg_opt.c |  6 ---
>  4 files changed, 76 insertions(+), 39 deletions(-)
> 
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index 6c774e9615..c1bb3926c4 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -595,15 +595,6 @@ static void ffmpeg_cleanup(int ret)
>  avcodec_free_context(>enc_ctx);
>  avcodec_parameters_free(>ref_par);
>  
> -if (ost->muxing_queue) {
> -while (av_fifo_size(ost->muxing_queue)) {
> -AVPacket *pkt;
> -av_fifo_generic_read(ost->muxing_queue, , sizeof(pkt), 
> NULL);
> -av_packet_free();
> -}
> -av_fifo_freep(>muxing_queue);
> -}
> -
>  av_freep(_streams[i]);
>  }
>  #if HAVE_THREADS
> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
> index e828f71dc0..28df1b179f 100644
> --- a/fftools/ffmpeg.h
> +++ b/fftools/ffmpeg.h
> @@ -555,15 +555,6 @@ typedef struct OutputStream {
>  
>  int max_muxing_queue_size;
>  
> -/* the packets are buffered here until the muxer is ready to be 
> initialized */
> -AVFifoBuffer *muxing_queue;
> -
> -/*
> - * The size of the AVPackets' buffers in queue.
> - * Updated when a packet is either pushed or pulled from the queue.
> - */
> -size_t muxing_queue_data_size;
> -
>  /* Threshold after which max_muxing_queue_size will be in effect */
>  size_t muxing_queue_data_threshold;
>  
> diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
> index f4d76e1533..f03202bbb7 100644
> --- a/fftools/ffmpeg_mux.c
> +++ b/fftools/ffmpeg_mux.c
> @@ -32,7 +32,20 @@
>  #include "libavformat/avformat.h"
>  #include "libavformat/avio.h"
>  
> +typedef struct MuxStream {
> +/* the packets are buffered here until the muxer is ready to be 
> initialized */
> +AVFifoBuffer *muxing_queue;
> +
> +/*
> + * The size of the AVPackets' buffers in queue.
> + * Updated when a packet is either pushed or pulled from the queue.
> + */
> +size_t muxing_queue_data_size;
> +} MuxStream;
> +
>  struct Muxer {
> +MuxStream *streams;
> +
>  /* filesize limit expressed in bytes */
>  int64_t limit_filesize;
>  int64_t final_filesize;
> @@ -55,6 +68,7 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, 
> OutputStream *ost,
>  {
>  AVFormatContext *s = of->ctx;
>  AVStream *st = ost->st;
> +MuxStream *ms = >mux->streams[st->index];
>  int ret;
>  
>  /*
> @@ -76,10 +90,10 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, 
> OutputStream *ost,
>  if (!of->mux->header_written) {
>  AVPacket *tmp_pkt;
>  /* the muxer is not initialized yet, buffer the packet */
> -if (!av_fifo_space(ost->muxing_queue)) {
> -size_t cur_size = av_fifo_size(ost->muxing_queue);
> +if (!av_fifo_space(ms->muxing_queue)) {
> +size_t cur_size = av_fifo_size(ms->muxing_queue);
>  unsigned int are_we_over_size =
> -(ost->muxing_queue_data_size + pkt->size) > 
> ost->muxing_queue_data_threshold;
> +(ms->muxing_queue_data_size + pkt->size) > 
> ost->muxing_queue_data_threshold;
>  size_t limit= are_we_over_size ? ost->max_muxing_queue_size 
> : INT_MAX;
>  size_t new_size = FFMIN(2 * cur_size, limit);
>  
> @@ -89,7 +103,7 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, 
> OutputStream *ost,
> ost->file_index, ost->st->index);
>  exit_program(1);
>  }
> -ret = av_fifo_realloc2(ost->muxing_queue, new_size);
> +ret = av_fifo_realloc2(ms->muxing_queue, new_size);
>  if (ret < 0)
>  exit_program(1);
>  }
> @@ -100,8 +114,8 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, 
> OutputStream *ost,
>  if (!tmp_pkt)
>  exit_program(1);
>  av_packet_move_ref(tmp_pkt, pkt);
> -ost->muxing_queue_data_size += tmp_pkt->size;
> -av_fifo_generic_write(ost->muxing_queue, _pkt, sizeof(tmp_pkt), 
> NULL);
> +ms->muxing_queue_data_size += tmp_pkt->size;
> +av_fifo_generic_write(ms->muxing_queue, _pkt, sizeof(tmp_pkt), 
> NULL);
>  return;
>  }
>  
> @@ -283,16 +297,17 @@ int of_check_init(OutputFile *of)
>  
>  /* flush the muxing queues */
>  for (i = 0; i < of->ctx->nb_streams; i++) {
> +MuxStream *ms = >mux->streams[i];
>  OutputStream *ost = 

[FFmpeg-devel] [PATCH 3/3] avcodec/libopenh264enc: set iEntropyCodingModeFlag by coder option

2022-01-13 Thread lance . lmwang
From: Limin Wang 

ffmpeg -y -f lavfi -i testsrc -c:v libopenh264 -profile:v main -coder cavlc 
-frames:v 1 -bsf trace_headers -f null -

before the patch:
entropy_coding_mode_flag0 = 1

after the patch:
entropy_coding_mode_flag0 = 0

Signed-off-by: Limin Wang 
---
 libavcodec/libopenh264enc.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 995ee37..91deb6c 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -193,7 +193,7 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
 #endif
 param.bPrefixNalAddingCtrl   = 0;
 param.iLoopFilterDisableIdc  = !s->loopfilter;
-param.iEntropyCodingModeFlag = 0;
+param.iEntropyCodingModeFlag = s->coder >= 0 ? s->coder : 0;
 param.iMultipleThreadIdc = avctx->thread_count;
 
 /* Allow specifying the libopenh264 profile through AVCodecContext. */
@@ -222,15 +222,15 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
 switch (s->profile) {
 case FF_PROFILE_H264_HIGH:
 s->profile = PRO_HIGH;
-param.iEntropyCodingModeFlag = 1;
-av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
-"select EProfileIdc PRO_HIGH in libopenh264.\n");
+av_log(avctx, AV_LOG_VERBOSE, "Using %s, "
+"select EProfileIdc PRO_HIGH in libopenh264.\n",
+s->coder == 1 ? "CABAC" : "CAVLC");
 break;
 case FF_PROFILE_H264_MAIN:
 s->profile = PRO_MAIN;
-param.iEntropyCodingModeFlag = 1;
-av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
-"select EProfileIdc PRO_MAIN in libopenh264.\n");
+av_log(avctx, AV_LOG_VERBOSE, "Using %s, "
+"select EProfileIdc PRO_MAIN in libopenh264.\n",
+s->coder == 1 ? "CABAC" : "CAVLC");
 break;
 case FF_PROFILE_H264_CONSTRAINED_BASELINE:
 case FF_PROFILE_UNKNOWN:
-- 
1.8.3.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 2/3] avcodec/libopenh264enc: make the profile configuablable correctly

2022-01-13 Thread lance . lmwang
From: Limin Wang 

If the version of libopenh264 >= 1.8, we can't configured main profile as
expected, below is the testing cli:

ffmpeg -y -f lavfi -i testsrc -c:v libopenh264 -profile:v main -frames:v 1 
test.ts
It'll report:
[libopenh264 @ 0x5638300] Unsupported profile, select EProfileIdc PRO_BASELINE 
in libopenh264.

Signed-off-by: Limin Wang 
---
 libavcodec/libopenh264enc.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index a55bef8..995ee37 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -220,26 +220,27 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
 #endif
 
 switch (s->profile) {
-#if OPENH264_VER_AT_LEAST(1, 8)
 case FF_PROFILE_H264_HIGH:
+s->profile = PRO_HIGH;
 param.iEntropyCodingModeFlag = 1;
 av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
 "select EProfileIdc PRO_HIGH in libopenh264.\n");
 break;
-#else
 case FF_PROFILE_H264_MAIN:
+s->profile = PRO_MAIN;
 param.iEntropyCodingModeFlag = 1;
 av_log(avctx, AV_LOG_VERBOSE, "Using CABAC, "
 "select EProfileIdc PRO_MAIN in libopenh264.\n");
 break;
-#endif
 case FF_PROFILE_H264_CONSTRAINED_BASELINE:
 case FF_PROFILE_UNKNOWN:
+s->profile = PRO_BASELINE;
 param.iEntropyCodingModeFlag = 0;
 av_log(avctx, AV_LOG_VERBOSE, "Using CAVLC, "
"select EProfileIdc PRO_BASELINE in libopenh264.\n");
 break;
 default:
+s->profile = PRO_BASELINE;
 param.iEntropyCodingModeFlag = 0;
 av_log(avctx, AV_LOG_WARNING, "Unsupported profile, "
"select EProfileIdc PRO_BASELINE in libopenh264.\n");
@@ -251,6 +252,7 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
 param.sSpatialLayers[0].fFrameRate  = param.fMaxFrameRate;
 param.sSpatialLayers[0].iSpatialBitrate = param.iTargetBitrate;
 param.sSpatialLayers[0].iMaxSpatialBitrate  = param.iMaxBitrate;
+param.sSpatialLayers[0].uiProfileIdc= s->profile;
 
 #if OPENH264_VER_AT_LEAST(1, 7)
 if (avctx->sample_aspect_ratio.num && avctx->sample_aspect_ratio.den) {
-- 
1.8.3.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 1/3] avcodec/libopenh264enc: support for colorspace and range information

2022-01-13 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavcodec/libopenh264enc.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index de4b85c..a55bef8 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -330,6 +330,21 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
 }
 }
 
+#if OPENH264_VER_AT_LEAST(1, 6)
+param.sSpatialLayers[0].uiVideoFormat = VF_UNDEF;
+param.sSpatialLayers[0].bVideoSignalTypePresent = true;
+if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED)
+param.sSpatialLayers[0].bFullRange = (avctx->color_range == 
AVCOL_RANGE_JPEG);
+
+param.sSpatialLayers[0].bColorDescriptionPresent = true;
+if (avctx->colorspace != AVCOL_SPC_UNSPECIFIED)
+param.sSpatialLayers[0].uiColorMatrix = avctx->colorspace;
+if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED)
+param.sSpatialLayers[0].uiColorPrimaries = avctx->color_primaries;
+if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED)
+param.sSpatialLayers[0].uiTransferCharacteristics = avctx->color_trc;
+#endif
+
 if ((*s->encoder)->InitializeExt(s->encoder, ) != cmResultSuccess) {
 av_log(avctx, AV_LOG_ERROR, "Initialize failed\n");
 return AVERROR_UNKNOWN;
-- 
1.8.3.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 V3 4/4] libavcodec/qsvenc: Add transform skip to hevc_qsv

2022-01-13 Thread Chen, Wenbin
> On Thu, 2022-01-13 at 13:12 +0800, Wenbin Chen wrote:
> > Add transform_skip option to hevc_qsv. By enabling this option,
> > the transform_skip_enabled_flag in PPS will be set to 1.
> > This option is supported on the platform equal or newer than CNL.
> >
> > Signed-off-by: Wenbin Chen 
> > ---
> >  doc/encoders.texi|  4 
> >  libavcodec/qsvenc.c  | 10 +-
> >  libavcodec/qsvenc.h  |  1 +
> >  libavcodec/qsvenc_hevc.c |  3 +++
> >  4 files changed, 17 insertions(+), 1 deletion(-)
> >
> > diff --git a/doc/encoders.texi b/doc/encoders.texi
> > index 3d7c944fba..7714084864 100644
> > --- a/doc/encoders.texi
> > +++ b/doc/encoders.texi
> > @@ -3447,6 +3447,10 @@ Number of rows for tiled encoding.
> >
> >  @item @var{aud}
> >  Insert the Access Unit Delimiter NAL.
> > +
> > +@item @var{transform_skip}
> > +Turn this option ON to enable transformskip. It is supported on platform
> > equal
> > +or newer than CNL.
> >  @end table
> >
> >  @subsection MPEG2 Options
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> > index f2ba0241c6..4e5997c9ed 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -358,6 +358,9 @@ static void dump_video_param(AVCodecContext
> *avctx,
> > QSVEncContext *q,
> >  av_log(avctx, AV_LOG_VERBOSE, "DisableDeblockingIdc: %"PRIu32" \n",
> co2-
> > >DisableDeblockingIdc);
> >  #endif
> >
> > +#if QSV_VERSION_ATLEAST(1, 26)
> > +av_log(avctx, AV_LOG_VERBOSE, "TransformSkip: %s \n",
> > print_threestate(co3->TransformSkip));
> > +#endif
> >  }
> >
> >  static void dump_video_vp9_param(AVCodecContext *avctx,
> QSVEncContext *q,
> > @@ -970,10 +973,15 @@ static int init_video_param(AVCodecContext
> *avctx,
> > QSVEncContext *q)
> >  #endif
> >  }
> >
> > +if (avctx->codec_id == AV_CODEC_ID_HEVC) {
> > +#if QSV_VERSION_ATLEAST(1, 26)
> > +q->extco3.TransformSkip = q->transform_skip ?
> MFX_CODINGOPTION_ON
> > :
> > +  
> > MFX_CODINGOPTION_OF
> > F;
> 
> q->extco3.TransformSkip is set to MFX_CODINGOPTION_ON when q-
> >transform_skip is
> -1, right ? TransformSkip is tri-state flag, we may set it to
> MFX_CODINGOPTION_UNKNOWN when q->transform_skip is -1.
> 
> Thanks
> Haihao

I will fix this in the next submission

Thanks
Wenbin
> 
> 
> > +#endif
> >  #if QSV_HAVE_GPB
> > -if (avctx->codec_id == AV_CODEC_ID_HEVC)
> >  q->extco3.GPB  = q->gpb ? MFX_CODINGOPTION_ON :
> > MFX_CODINGOPTION_OFF;
> >  #endif
> > +}
> >  q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer
> *)
> > >extco3;
> >  #endif
> >  }
> > diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> > index 960604cb9a..5a574ada30 100644
> > --- a/libavcodec/qsvenc.h
> > +++ b/libavcodec/qsvenc.h
> > @@ -200,6 +200,7 @@ typedef struct QSVEncContext {
> >  int repeat_pps;
> >  int low_power;
> >  int gpb;
> > +int transform_skip;
> >
> >  int a53_cc;
> >
> > diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
> > index 08aba3011d..679c09c858 100644
> > --- a/libavcodec/qsvenc_hevc.c
> > +++ b/libavcodec/qsvenc_hevc.c
> > @@ -251,6 +251,9 @@ static const AVOption options[] = {
> >  { "tile_rows",  "Number of rows for tiled
> > encoding",  OFFSET(qsv.tile_rows),AV_OPT_TYPE_INT, { .i64 = 0 }, 0,
> > UINT16_MAX, VE },
> >  { "recovery_point_sei", "Insert recovery point SEI
> > messages",   OFFSET(qsv.recovery_point_sei),  AV_OPT_TYPE_INT,
> { .i64
> > = -1 },   -1,  1, VE },
> >  { "aud", "Insert the Access Unit Delimiter NAL", OFFSET(qsv.aud),
> > AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE},
> > +#if QSV_VERSION_ATLEAST(1, 26)
> > +{ "transform_skip", "Turn this option ON to enable
> > transformskip",   OFFSET(qsv.transform_skip),  AV_OPT_TYPE_INT,{
> > .i64 = -1},   -1, 1,  VE},
> > +#endif
> >
> >  { NULL },
> >  };
> ___
> 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 V3 2/4] libavcodec/qsvenc: Add DisableDeblockingIdc support to qsv

2022-01-13 Thread Chen, Wenbin
> On Thu, 2022-01-13 at 13:12 +0800, Wenbin Chen wrote:
> > Add dblk_idc option to 264_qsv and hevc_qsv. Turining on this opion can
> > disable deblocking.
> >
> > Signed-off-by: Wenbin Chen 
> > ---
> >  doc/encoders.texi   | 6 ++
> >  libavcodec/qsvenc.c | 8 
> >  libavcodec/qsvenc.h | 3 +++
> >  3 files changed, 17 insertions(+)
> >
> > diff --git a/doc/encoders.texi b/doc/encoders.texi
> > index 68921fbd40..6fc94daa11 100644
> > --- a/doc/encoders.texi
> > +++ b/doc/encoders.texi
> > @@ -3299,6 +3299,9 @@ This flag controls changing of frame type from B
> to P.
> >  @item @var{b_strategy}
> >  This option controls usage of B frames as reference.
> >
> > +@item @var{dblk_idc}
> > +This option disable deblocking. It has value in range 0~2.
> > +
> >  @item @var{cavlc}
> >  If set, CAVLC is used; if unset, CABAC is used for encoding.
> >
> > @@ -3391,6 +3394,9 @@ Enable rate distortion optimization.
> >  @item @var{max_frame_size}
> >  Maximum encoded frame size in bytes.
> >
> > +@item @var{dblk_idc}
> > +This option disable deblocking. It has value in range 0~2.
> > +
> >  @item @var{idr_interval}
> >  Distance (in I-frames) between IDR frames.
> >  @table @samp
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> > index b3728d28d5..e87b69369a 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -346,6 +346,10 @@ static void dump_video_param(AVCodecContext
> *avctx,
> > QSVEncContext *q,
> >  av_log(avctx, AV_LOG_VERBOSE, "FrameRateExtD: %"PRIu32";
> FrameRateExtN:
> > %"PRIu32" \n",
> > info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN);
> >
> > +#if QSV_HAVE_DISABLEDEBLOCKIDC
> > +av_log(avctx, AV_LOG_VERBOSE, "DisableDeblockingIdc: %"PRIu32" \n",
> co2-
> > >DisableDeblockingIdc);
> > +#endif
> > +
> >  }
> >
> >  static void dump_video_vp9_param(AVCodecContext *avctx,
> QSVEncContext *q,
> > @@ -889,6 +893,10 @@ static int init_video_param(AVCodecContext
> *avctx,
> > QSVEncContext *q)
> >  q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON :
> > MFX_CODINGOPTION_OFF;
> >  if (q->max_frame_size >= 0)
> >  q->extco2.MaxFrameSize = q->max_frame_size;
> > +#if QSV_HAVE_DISABLEDEBLOCKIDC
> > +if(q->dblk_idc >= 0)
> > +q->extco2.DisableDeblockingIdc = q->dblk_idc;
> > +#endif
> >
> >  #if QSV_VERSION_ATLEAST(1, 9)
> >  if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > 
> > avctx-
> > >qmax) {
> > diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> > index 31516b8e55..aa49b35f07 100644
> > --- a/libavcodec/qsvenc.h
> > +++ b/libavcodec/qsvenc.h
> > @@ -44,6 +44,7 @@
> >
> >  #define QSV_HAVE_TRELLIS QSV_VERSION_ATLEAST(1, 8)
> >  #define QSV_HAVE_MAX_SLICE_SIZE QSV_VERSION_ATLEAST(1, 9)
> > +#define QSV_HAVE_DISABLEDEBLOCKIDC QSV_VERSION_ATLEAST(1, 9)
> >  #define QSV_HAVE_BREF_TYPE  QSV_VERSION_ATLEAST(1, 8)
> >
> >  #define QSV_HAVE_LA QSV_VERSION_ATLEAST(1, 7)
> > @@ -97,6 +98,7 @@
> >  { "b_strategy", "Strategy to choose between I/P/B-frames",
> > OFFSET(qsv.b_strategy),AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, 
> > VE
> > }, \
> >  { "forced_idr", "Forcing I frames as IDR
> > frames", OFFSET(qsv.forced_idr), AV_OPT_TYPE_BOOL,{ .i64 =
> > 0  },  0,  1, VE }, \
> >  { "low_power", "enable low power mode(experimental: many limitations
> by mfx
> > version, BRC modes, etc.)", OFFSET(qsv.low_power), AV_OPT_TYPE_BOOL,
> { .i64 =
> > -1}, -1, 1, VE},\
> > +{ "dblk_idc", "This option disable deblocking. It has value in range
> > 0~2.",   OFFSET(qsv.dblk_idc),   AV_OPT_TYPE_INT,{ .i64 = -1 },   -
> > 1,  2,  VE},\
> 
> 
> The range is 0~2 in the help string, however the minimal value is -1, which
> will
> confuse user. We may set both the default and minimal values to 0 here.
> 
> Thanks
> Haihao

Sorry, I miss your comment. I will fix this.

Thanks
Wenbin

> 
> >
> >  extern const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[];
> >
> > @@ -169,6 +171,7 @@ typedef struct QSVEncContext {
> >  int rdo;
> >  int max_frame_size;
> >  int max_slice_size;
> > +int dblk_idc;
> >
> >  int tile_cols;
> >  int tile_rows;
> ___
> 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".