Re: [FFmpeg-devel] Need help submitting a patch

2022-05-03 Thread Nicolas George
Traian Coza (12022-05-03):
> Hi! I am new to contributing to FFmpeg, and I have a technical question.
> 
> I'm trying to submit a patch, but it's a fairly large patch, which I've
> made in multiple commits. I don't know how to generate the email for this
> patch. The example command given on the website (with format-patch) only
> generates the email for a single commit. I've searched the web and I don't
> really see an easy way to do it. Can someone help me out with this?

First, make sure your multiple commits are really there: check they are
all visible in `git log`.

Then, what is your git format-patch exact command? If it ends in "-1",
then the result you are seeing is normal: the -1 is telling it to take
the last patch.

You need to tell git format-patch the last commit before yours. You can
get it from `git log`. It would be even simpler if you thought of making
a branch: then you just need to specify the name of the branch from
which you branched.

Regards,

-- 
  Nicolas George


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] Need help submitting a patch

2022-05-03 Thread Traian Coza
Thanks. I'll use the ffstaging/FFmpeg repo. I didn't know about that, it
seems much simpler. I've tried using -n (n= number of commits), but it only
generates n emails, I only want 1.

I have another concern before I create a pull request. I ran 'make fate'
like it says on the website for regression testing, and I got the following
error:

TESTsource
--- ./tests/ref/fate/source 2022-05-02 12:57:02.707487436 -0400
+++ tests/data/fate/source 2022-05-03 09:22:31.302681114 -0400
@@ -5,6 +5,8 @@
 libavcodec/interplayacm.c
 libavcodec/log2_tab.c
 libavcodec/reverse.c
+libavcodec/text_to_bitmap.c
+libavcodec/text_to_bitmap.h
 libavdevice/file_open.c
 libavdevice/reverse.c
 libavfilter/af_arnndn.c
@@ -20,6 +22,7 @@
 compat/djgpp/math.h
 compat/float/float.h
 compat/float/limits.h
+libavcodec/text_to_bitmap.h
 tools/decode_simple.h
 Use of av_clip() where av_clip_uintp2() could be used:
 Use of av_clip() where av_clip_intp2() could be used:
Test source failed. Look at tests/data/fate/source.err for details.

The source.err file seems to be empty, however. Should I be concerned about
this? It seems to do with the fact that I've added some files.

On Tue, May 3, 2022 at 3:54 AM Nicolas George  wrote:

> Traian Coza (12022-05-03):
> > Hi! I am new to contributing to FFmpeg, and I have a technical question.
> >
> > I'm trying to submit a patch, but it's a fairly large patch, which I've
> > made in multiple commits. I don't know how to generate the email for this
> > patch. The example command given on the website (with format-patch) only
> > generates the email for a single commit. I've searched the web and I
> don't
> > really see an easy way to do it. Can someone help me out with this?
>
> First, make sure your multiple commits are really there: check they are
> all visible in `git log`.
>
> Then, what is your git format-patch exact command? If it ends in "-1",
> then the result you are seeing is normal: the -1 is telling it to take
> the last patch.
>
> You need to tell git format-patch the last commit before yours. You can
> get it from `git log`. It would be even simpler if you thought of making
> a branch: then you just need to specify the name of the branch from
> which you branched.
>
> Regards,
>
> --
>   Nicolas George
> ___
> 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] Need help submitting a patch

2022-05-03 Thread Andreas Rheinhardt
Traian Coza:
> Thanks. I'll use the ffstaging/FFmpeg repo. I didn't know about that, it
> seems much simpler. I've tried using -n (n= number of commits), but it only
> generates n emails, I only want 1.
> 
> I have another concern before I create a pull request. I ran 'make fate'
> like it says on the website for regression testing, and I got the following
> error:
> 
> TESTsource
> --- ./tests/ref/fate/source 2022-05-02 12:57:02.707487436 -0400
> +++ tests/data/fate/source 2022-05-03 09:22:31.302681114 -0400
> @@ -5,6 +5,8 @@
>  libavcodec/interplayacm.c
>  libavcodec/log2_tab.c
>  libavcodec/reverse.c
> +libavcodec/text_to_bitmap.c
> +libavcodec/text_to_bitmap.h
>  libavdevice/file_open.c
>  libavdevice/reverse.c
>  libavfilter/af_arnndn.c
> @@ -20,6 +22,7 @@
>  compat/djgpp/math.h
>  compat/float/float.h
>  compat/float/limits.h
> +libavcodec/text_to_bitmap.h
>  tools/decode_simple.h
>  Use of av_clip() where av_clip_uintp2() could be used:
>  Use of av_clip() where av_clip_intp2() could be used:
> Test source failed. Look at tests/data/fate/source.err for details.
> 
> The source.err file seems to be empty, however. Should I be concerned about
> this? It seems to do with the fact that I've added some files.

This means that your newly added headers use nonstandard inclusion
guards (if they use inclusion guards at all). Look at
tests/fate/source-check.sh to see how the inclusion guard should be.

- 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] Need help submitting a patch

2022-05-03 Thread Nicolas George
Traian Coza (12022-05-03):
> Thanks. I'll use the ffstaging/FFmpeg repo. I didn't know about that, it
> seems much simpler.

It is not supported by the core of the project.

> I've tried using -n (n= number of commits), but it only
> generates n emails, I only want 1.

Look at how other people submit patches: several commits means several
mails.

> The source.err file seems to be empty, however. Should I be concerned about
> this? It seems to do with the fact that I've added some files.

Yes, you need to fix it.

> On Tue, May 3, 2022 at 3:54 AM Nicolas George  wrote:

Top-posting is strictly forbidden on this mailing-list. If you do not
know what it means, look it up.

Regards,

-- 
  Nicolas George


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] Need help submitting a patch

2022-05-03 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Traian Coza:
>> Thanks. I'll use the ffstaging/FFmpeg repo. I didn't know about that, it
>> seems much simpler. I've tried using -n (n= number of commits), but it only
>> generates n emails, I only want 1.
>>
>> I have another concern before I create a pull request. I ran 'make fate'
>> like it says on the website for regression testing, and I got the following
>> error:
>>
>> TESTsource
>> --- ./tests/ref/fate/source 2022-05-02 12:57:02.707487436 -0400
>> +++ tests/data/fate/source 2022-05-03 09:22:31.302681114 -0400
>> @@ -5,6 +5,8 @@
>>  libavcodec/interplayacm.c
>>  libavcodec/log2_tab.c
>>  libavcodec/reverse.c
>> +libavcodec/text_to_bitmap.c
>> +libavcodec/text_to_bitmap.h
>>  libavdevice/file_open.c
>>  libavdevice/reverse.c
>>  libavfilter/af_arnndn.c
>> @@ -20,6 +22,7 @@
>>  compat/djgpp/math.h
>>  compat/float/float.h
>>  compat/float/limits.h
>> +libavcodec/text_to_bitmap.h
>>  tools/decode_simple.h
>>  Use of av_clip() where av_clip_uintp2() could be used:
>>  Use of av_clip() where av_clip_intp2() could be used:
>> Test source failed. Look at tests/data/fate/source.err for details.
>>
>> The source.err file seems to be empty, however. Should I be concerned about
>> this? It seems to do with the fact that I've added some files.
> 
> This means that your newly added headers use nonstandard inclusion
> guards (if they use inclusion guards at all). Look at
> tests/fate/source-check.sh to see how the inclusion guard should be.

Addendum/Correction: There is only one header; the above two additions
refer to nonstandard license headers.

- 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 4/7] avcodec/codec_internal: Use union for FFCodec decode/encode callbacks

2022-05-03 Thread Andreas Rheinhardt
Michael Niedermayer:
> On Thu, Mar 31, 2022 at 12:49:55AM +0200, Andreas Rheinhardt wrote:
>> This is possible, because every given FFCodec has to implement
>> exactly one of these. Doing so decreases sizeof(FFCodec) and
>> therefore decreases the size of the binary.
>> Notice that in case of position-independent code the decrease
>> is in .data.rel.ro, so that this translates to decreased
>> memory consumption.
> 
> by how much did the space requirement decrease ?

The three patches fb59a42ef, ce7dbd048 and 4243da4ff4 together removed
four pointers from FFCodec; on 64 bit systems this amounts to savings of
32 byte per FFCodec. allcodecs.c contains 796 declarations of FFCodecs,
amounting to savings of at most 25472B. (This number is not attainable
because some codecs are only available for certain platforms.)
I get 488 decoders and 182 encoders in a build without any external
libraries explicitly enabled, leading to savings of 21440B.

> iam asking because while a single such change isnt a issue
> if we accumulate alot of this in the API, the API may become
> actually hard to understand by new developers
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH 4/4] fate/filter-video: Remove intermediate file of meta-4560-rotate0 test

2022-05-03 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 tests/fate/filter-video.mak | 10 ++
 tests/ref/fate/filter-meta-4560-rotate0 |  2 ++
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
index 68f4c084f8..b9f3ef238b 100644
--- a/tests/fate/filter-video.mak
+++ b/tests/fate/filter-video.mak
@@ -856,14 +856,8 @@ FATE_METADATA_FILTER-$(call ALLYES, 
$(AVF_PHASE_METER_DEPS)) += fate-filter-meta
 fate-filter-metadata-avf-aphase-meter-out-of-phase: SRC = 
$(TARGET_SAMPLES)/filter/out-of-phase-1000hz.flac
 fate-filter-metadata-avf-aphase-meter-out-of-phase: CMD = run 
$(FILTER_METADATA_COMMAND) "amovie='$(SRC)',aphasemeter=video=0"
 
-tests/data/file4560-override2rotate0.mov: TAG = GEN
-tests/data/file4560-override2rotate0.mov: ffmpeg$(PROGSSUF)$(EXESUF) | 
tests/data
-   $(M)$(TARGET_EXEC) $(TARGET_PATH)/$< -nostdin \
-   -i $(TARGET_SAMPLES)/filter/sample-in-issue-505.mov -c copy -flags 
+bitexact -metadata:s:v:0 rotate=0 $(TARGET_PATH)/$@ -y 2>/dev/null
-
-FATE_FILTER_SAMPLES-$(call ALLYES, MOV_DEMUXER H264_DECODER AAC_FIXED_DECODER 
PCM_S16LE_ENCODER MOV_MUXER) += fate-filter-meta-4560-rotate0
-fate-filter-meta-4560-rotate0: tests/data/file4560-override2rotate0.mov
-fate-filter-meta-4560-rotate0: CMD = framecrc -auto_conversion_filters -flags 
+bitexact -c:a aac_fixed -i 
$(TARGET_PATH)/tests/data/file4560-override2rotate0.mov
+FATE_FILTER_SAMPLES-$(call TRANSCODE, RAWVIDEO H264, MOV, ARESAMPLE_FILTER  
AAC_FIXED_DECODER) += fate-filter-meta-4560-rotate0
+fate-filter-meta-4560-rotate0: CMD = transcode mov 
$(TARGET_SAMPLES)/filter/sample-in-issue-505.mov mov "-c copy -metadata:s:v:0 
rotate=0" "-af aresample" "" "" "" "-flags +bitexact -c:a aac_fixed"
 
 REFCMP_DEPS = FFMPEG LAVFI_INDEV TESTSRC2_FILTER AVGBLUR_FILTER METADATA_FILTER
 
diff --git a/tests/ref/fate/filter-meta-4560-rotate0 
b/tests/ref/fate/filter-meta-4560-rotate0
index 0c33709b77..82703e009c 100644
--- a/tests/ref/fate/filter-meta-4560-rotate0
+++ b/tests/ref/fate/filter-meta-4560-rotate0
@@ -1,3 +1,5 @@
+dc213aee944a55af2f41950921fd62d7 *tests/data/fate/filter-meta-4560-rotate0.mov
+347433 tests/data/fate/filter-meta-4560-rotate0.mov
 #tb 0: 1/30
 #media_type 0: video
 #codec_id 0: rawvideo
-- 
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".


[FFmpeg-devel] [PATCH 3/4] tests/fate-run: Allow to set dec opts for generated file in transcode

2022-05-03 Thread Andreas Rheinhardt
This can be necessary to e.g. force a fixed-point audio codec.

Signed-off-by: Andreas Rheinhardt 
---
 tests/fate-run.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tests/fate-run.sh b/tests/fate-run.sh
index 4f8988b964..2606fcb917 100755
--- a/tests/fate-run.sh
+++ b/tests/fate-run.sh
@@ -230,9 +230,10 @@ transcode(){
 srcfile=$2
 enc_fmt=$3
 enc_opt=$4
-final_decode=$5
+final_encode=$5
 ffprobe_opts=$7
 additional_input=$8
+final_decode=$9
 test -z "$additional_input" || additional_input="$DEC_OPTS 
$additional_input"
 encfile="${outdir}/${test}.${enc_fmt}"
 test "$6" = -keep || cleanfiles="$cleanfiles $encfile"
@@ -242,7 +243,7 @@ transcode(){
$ENC_OPTS $enc_opt $FLAGS -f $enc_fmt -y $tencfile || return
 do_md5sum $encfile
 echo $(wc -c $encfile)
-ffmpeg $DEC_OPTS -i $tencfile $ENC_OPTS $FLAGS $final_decode \
+ffmpeg $DEC_OPTS $final_decode -i $tencfile $ENC_OPTS $FLAGS $final_encode 
\
 -f framecrc - || return
 test -z $ffprobe_opts || \
 run ffprobe${PROGSUF}${EXECSUF} -bitexact $ffprobe_opts $tencfile || 
return
-- 
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] Need help submitting a patch

2022-05-03 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Nicolas George
> Sent: Tuesday, May 3, 2022 3:31 PM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] Need help submitting a patch
> 
> Traian Coza (12022-05-03):
> > Thanks. I'll use the ffstaging/FFmpeg repo. I didn't know about
> that, it
> > seems much simpler.
> 
> It is not supported by the core of the project.

What it essentially does is to handle all the e-mail creation
and handling for you, also it takes care of versioning 
your patchsets when submitting updates.

Once you comment with the /submit command, it will send your
patchset as emails to the mailing list, which IS supported
by the "core of the project".

Kind regards,
softworkz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] Need help submitting a patch

2022-05-03 Thread Traian Coza
Sounds great, thanks! It's great that there's this functionality somewhere.
I'm not used to this email stuff.

On Tue, May 3, 2022 at 10:08 AM Soft Works  wrote:

>
>
> > -Original Message-
> > From: ffmpeg-devel  On Behalf Of
> > Nicolas George
> > Sent: Tuesday, May 3, 2022 3:31 PM
> > To: FFmpeg development discussions and patches  > de...@ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] Need help submitting a patch
> >
> > Traian Coza (12022-05-03):
> > > Thanks. I'll use the ffstaging/FFmpeg repo. I didn't know about
> > that, it
> > > seems much simpler.
> >
> > It is not supported by the core of the project.
>
> What it essentially does is to handle all the e-mail creation
> and handling for you, also it takes care of versioning
> your patchsets when submitting updates.
>
> Once you comment with the /submit command, it will send your
> patchset as emails to the mailing list, which IS supported
> by the "core of the project".
>
> Kind regards,
> 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".


Re: [FFmpeg-devel] Need help submitting a patch

2022-05-03 Thread Traian Coza
Sorry about the "top posting" my client does it automatically.
___
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] Need help submitting a patch

2022-05-03 Thread Nicolas George
Traian Coza (12022-05-03):
> Sorry about the "top posting" my client does it automatically.

It's a poor craftsman who blames their tools.

-- 
  Nicolas George


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] Need help submitting a patch

2022-05-03 Thread Traian Coza
Hey Softworks, when I try to open a pull request on that repo it says "An
owner of this repository has limited the ability to open a pull request to
users that are collaborators on this repository." So I am not a
collaborator, can you add me as a collaborator so I can do my pull request?
I've seen that you can do pull requests.
___
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] Need help submitting a patch

2022-05-03 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Traian Coza
> Sent: Tuesday, May 3, 2022 5:37 PM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] Need help submitting a patch
> 
> Hey Softworks, when I try to open a pull request on that repo it says
> "An
> owner of this repository has limited the ability to open a pull
> request to
> users that are collaborators on this repository." So I am not a
> collaborator, can you add me as a collaborator so I can do my pull
> request?
> I've seen that you can do pull requests.

You need to create your PR against https://github.com/ffstaging/FFmpeg,
not https://github.com/FFmpeg/FFmpeg

sw
___
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 0/2] JPEG XL Colorspace Fixes

2022-05-03 Thread Leo Izen
Add proper colorspace handling and tagging to the libjxl
decoder and encoder wrappers.

Leo Izen (2):
  avcodec/libjxldec: properly tag output colorspace
  avcodec/libjxlenc: properly read input colorspace

 libavcodec/libjxl.h|   9 +++
 libavcodec/libjxldec.c | 121 +++-
 libavcodec/libjxlenc.c | 152 +
 3 files changed, 251 insertions(+), 31 deletions(-)

-- 
2.36.0

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

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


[FFmpeg-devel] [PATCH 1/2] avcodec/libjxldec: properly tag output colorspace

2022-05-03 Thread Leo Izen
Whether an ICC profile is present or not, the decoder
should now properly tag the colorspace of pixel data
received by the decoder.
---
 libavcodec/libjxl.h|   9 +++
 libavcodec/libjxldec.c | 121 -
 2 files changed, 127 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libjxl.h b/libavcodec/libjxl.h
index 5387c438fd..2b388dc45d 100644
--- a/libavcodec/libjxl.h
+++ b/libavcodec/libjxl.h
@@ -27,8 +27,17 @@
 #ifndef AVCODEC_LIBJXL_H
 #define AVCODEC_LIBJXL_H
 
+#include "libavutil/rational.h"
+
 #include 
 
+#define FF_JXL_WP_D65_X av_make_q(3127, 1)
+#define FF_JXL_WP_D65_Y av_make_q(3290, 1)
+#define FF_JXL_WP_E_X av_make_q(1, 3)
+#define FF_JXL_WP_E_Y av_make_q(1, 3)
+#define FF_JXL_WP_DCI_X av_make_q(314, 1000)
+#define FF_JXL_WP_DCI_Y av_make_q(351, 1000)
+
 /**
  * Transform threadcount in ffmpeg to one used by libjxl.
  *
diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c
index cd4bca3343..bd308590ab 100644
--- a/libavcodec/libjxldec.c
+++ b/libavcodec/libjxldec.c
@@ -28,9 +28,11 @@
 #include "libavutil/buffer.h"
 #include "libavutil/common.h"
 #include "libavutil/error.h"
+#include "libavutil/mastering_display_metadata.h"
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/rational.h"
 #include "libavutil/frame.h"
 
 #include "avcodec.h"
@@ -189,16 +191,129 @@ static int libjxl_decode_frame(AVCodecContext *avctx, 
AVFrame *frame, int *got_f
 continue;
 case JXL_DEC_COLOR_ENCODING:
 av_log(avctx, AV_LOG_DEBUG, "COLOR_ENCODING event emitted\n");
-jret = JxlDecoderGetICCProfileSize(ctx->decoder, &ctx->jxl_pixfmt, 
JXL_COLOR_PROFILE_TARGET_ORIGINAL, &iccp_len);
+jret = JxlDecoderGetICCProfileSize(ctx->decoder, &ctx->jxl_pixfmt, 
JXL_COLOR_PROFILE_TARGET_DATA, &iccp_len);
 if (jret == JXL_DEC_SUCCESS && iccp_len > 0) {
 av_buffer_unref(&ctx->iccp);
 ctx->iccp = av_buffer_alloc(iccp_len);
 if (!ctx->iccp)
 return AVERROR(ENOMEM);
-jret = JxlDecoderGetColorAsICCProfile(ctx->decoder, 
&ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_ORIGINAL, ctx->iccp->data, iccp_len);
-if (jret != JXL_DEC_SUCCESS)
+jret = JxlDecoderGetColorAsICCProfile(ctx->decoder, 
&ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_DATA, ctx->iccp->data, iccp_len);
+if (jret != JXL_DEC_SUCCESS) {
+av_log(avctx, AV_LOG_WARNING, "Unable to obtain ICCP from 
header\n");
 av_buffer_unref(&ctx->iccp);
+}
 }
+avctx->color_range = frame->color_range = AVCOL_RANGE_JPEG;
+if (ctx->iccp) {
+/* if the ICCP is present, libjxl outputs sRGB */
+if (ctx->jxl_pixfmt.num_channels >= 3)
+avctx->color_primaries = AVCOL_PRI_BT709;
+/* linear sRGB if float values, standard sRGB if int values */
+avctx->color_trc = ctx->jxl_pixfmt.data_type == JXL_TYPE_FLOAT 
? AVCOL_TRC_LINEAR : AVCOL_TRC_IEC61966_2_1;
+} else {
+JxlColorEncoding jxl_encoding;
+jret = JxlDecoderGetColorAsEncodedProfile(ctx->decoder, 
&ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_DATA, &jxl_encoding);
+if (jret != JXL_DEC_SUCCESS) {
+av_log(avctx, AV_LOG_WARNING, "Unable to obtain color 
encoding from header\n");
+continue;
+}
+
+if (ctx->jxl_pixfmt.num_channels >= 3) {
+AVMasteringDisplayMetadata *mdm = NULL;
+
+avctx->colorspace = frame->colorspace = AVCOL_SPC_RGB;
+
+/* dont set MDM if D65 white point is used */
+/* unless the custom primaries are set */
+if (jxl_encoding.primaries == JXL_PRIMARIES_CUSTOM ||
+jxl_encoding.white_point != JXL_WHITE_POINT_D65) {
+mdm = 
av_mastering_display_metadata_create_side_data(frame);
+if (!mdm)
+return AVERROR(ENOMEM);
+}
+
+switch (jxl_encoding.primaries) {
+case JXL_PRIMARIES_SRGB:
+avctx->color_primaries = AVCOL_PRI_BT709;
+break;
+case JXL_PRIMARIES_2100:
+avctx->color_primaries = AVCOL_PRI_BT2020;
+break;
+case JXL_PRIMARIES_P3:
+avctx->color_primaries = AVCOL_PRI_SMPTE431;
+break;
+case JXL_PRIMARIES_CUSTOM:
+mdm->display_primaries[0][0] = 
av_d2q(jxl_encoding.primaries_red_xy[0], 10);
+mdm->display_primaries[0][1] = 
av_d2q(jxl_encodi

Re: [FFmpeg-devel] Need help submitting a patch

2022-05-03 Thread Traian Coza
I know, but when I click on "New Pull Request" on ffstaging/FFmpeg, it
automatically sets the "base repository" to FFmpeg/FFmpeg, and I can't
change it to ffstaging/FFmpeg (see image). Am I doing something wrong,
perhaps?

[image: image.png]
___
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/2] avcodec/libjxlenc: properly read input colorspace

2022-05-03 Thread Leo Izen
Whether an ICC profile is present or not, the libjxl
encoder wrapper should now properly read colorspace tags
and forward them to libjxl appropriately, rather than just
assume sRGB as before. It will also print warnings when
colorimetric assumptions are made about the input data.
---
 libavcodec/libjxlenc.c | 152 +
 1 file changed, 124 insertions(+), 28 deletions(-)

diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c
index 8bebec6aeb..02ecdd7dc6 100644
--- a/libavcodec/libjxlenc.c
+++ b/libavcodec/libjxlenc.c
@@ -30,9 +30,11 @@
 #include "libavutil/error.h"
 #include "libavutil/frame.h"
 #include "libavutil/libm.h"
+#include "libavutil/mastering_display_metadata.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/rational.h"
 #include "libavutil/version.h"
 
 #include "avcodec.h"
@@ -117,7 +119,7 @@ static int libjxl_init_jxl_encoder(AVCodecContext *avctx)
 return AVERROR_EXTERNAL;
 }
 
-/* check for negative zero, our default */
+/* check for negative, our default */
 if (ctx->distance < 0.0) {
 /* use ffmpeg.c -q option if passed */
 if (avctx->flags & AV_CODEC_FLAG_QSCALE)
@@ -133,7 +135,8 @@ static int libjxl_init_jxl_encoder(AVCodecContext *avctx)
  */
 if (ctx->distance > 0.0 && ctx->distance < 0.01)
 ctx->distance = 0.01;
-if (JxlEncoderOptionsSetDistance(ctx->options, ctx->distance) != 
JXL_ENC_SUCCESS) {
+
+if (JxlEncoderSetFrameDistance(ctx->options, ctx->distance) != 
JXL_ENC_SUCCESS) {
 av_log(avctx, AV_LOG_ERROR, "Failed to set distance: %f\n", 
ctx->distance);
 return AVERROR_EXTERNAL;
 }
@@ -219,57 +222,150 @@ static int libjxl_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt, const AVFra
 info.num_color_channels = jxl_fmt.num_channels - info.num_extra_channels;
 info.bits_per_sample = av_get_bits_per_pixel(pix_desc) / 
jxl_fmt.num_channels;
 info.alpha_bits = (info.num_extra_channels > 0) * info.bits_per_sample;
+
 if (pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
 info.exponent_bits_per_sample = info.bits_per_sample > 16 ? 8 : 5;
 info.alpha_exponent_bits = info.alpha_bits ? 
info.exponent_bits_per_sample : 0;
 jxl_fmt.data_type = info.bits_per_sample > 16 ? JXL_TYPE_FLOAT : 
JXL_TYPE_FLOAT16;
-JxlColorEncodingSetToLinearSRGB(&jxl_color, info.num_color_channels == 
1);
 } else {
 info.exponent_bits_per_sample = 0;
 info.alpha_exponent_bits = 0;
 jxl_fmt.data_type = info.bits_per_sample <= 8 ? JXL_TYPE_UINT8 : 
JXL_TYPE_UINT16;
-JxlColorEncodingSetToSRGB(&jxl_color, info.num_color_channels == 1);
 }
 
-if (info.bits_per_sample > 16
-|| info.xsize > (1 << 18) || info.ysize > (1 << 18)
-|| (info.xsize << 4) * (info.ysize << 4) > (1 << 20)) {
-/*
- * must upgrade codestream to level 10, from level 5
- * the encoder will not do this automatically
- */
-if (JxlEncoderSetCodestreamLevel(ctx->encoder, 10) != JXL_ENC_SUCCESS) 
{
-av_log(avctx, AV_LOG_ERROR, "Could not upgrade JXL Codestream 
level.\n");
-return AVERROR_EXTERNAL;
+/* JPEG XL format itself does not support partial range */
+if (avctx->color_range == AVCOL_RANGE_MPEG) {
+av_log(avctx, AV_LOG_ERROR, "This encoder does not support partial(tv) 
range, colors will be wrong!\n");
+} else if (avctx->color_range != AVCOL_RANGE_JPEG) {
+av_log(avctx, AV_LOG_WARNING, "Unknown color range, assuming full\n");
+}
+
+/* rendering intent doesn't matter here
+ * but libjxl will whine if we don't set it */
+jxl_color.rendering_intent = JXL_RENDERING_INTENT_RELATIVE;
+
+switch (avctx->color_trc) {
+case AVCOL_TRC_BT709:
+jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_709;
+break;
+case AVCOL_TRC_LINEAR:
+jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
+break;
+case AVCOL_TRC_IEC61966_2_1:
+jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB;
+break;
+case AVCOL_TRC_SMPTE428:
+jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_DCI;
+break;
+case AVCOL_TRC_ARIB_STD_B67:
+jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_HLG;
+break;
+case AVCOL_TRC_GAMMA22:
+jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA;
+jxl_color.gamma = 2.2;
+break;
+case AVCOL_TRC_GAMMA28:
+jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA;
+jxl_color.gamma = 2.8;
+break;
+default:
+if (pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
+av_log(avctx, AV_LOG_WARNING, "Unknown transfer function, assuming 
Linear Light\n");
+jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
+} else {
+av_log(avctx, AV_LOG_WARNING, "Unknown

Re: [FFmpeg-devel] Need help submitting a patch

2022-05-03 Thread Leo Izen

On 5/3/22 00:12, Traian Coza wrote:

Hi! I am new to contributing to FFmpeg, and I have a technical question.

I'm trying to submit a patch, but it's a fairly large patch, which I've
made in multiple commits. I don't know how to generate the email for this
patch. The example command given on the website (with format-patch) only
generates the email for a single commit. I've searched the web and I don't
really see an easy way to do it. Can someone help me out with this?

I find the easiest way to do it for me is to generate the patches with 
"git format-patch" and then send them with "git send-email".


Once you have your patches atop the master branch, you can create a 
directory called outgoing/ and then run something like:


git format-patch -M -o outgoing/ --cover-letter origin/master

In this case, --cover-letter generates a cover letter, which you then 
edit to give a short blurb of what your patch set looks like. Then when 
you run git send-email outgoing/* you will have the patches embedded as 
replies to that cover letter email. "origin/master" is the hash of the 
last commit *before* yours, but it can by any ref, such as 
origin/master, not just a commit hash. You can also just substitute the 
commit hash there if your repositories/branches are named differently.


Since you use Gmail (at least, from your email address), you will need 
to enable Less Secure Apps if you have two-factor authentication 
disabled. If you have it enabled, you will have to generate an App 
Password for git-send-email, and then use that as the account password 
instead of your own.


- Leo Izen (thebombzen)


___
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 00/12] I added text to bitmap subtitle conversion functionality!

2022-05-03 Thread Traian Coza
I added the possibility of converting text-based subtitle tracks (such as 
subrip or ass) to bitmap-based subtitle tracks (such as dvd_subtitle).

I accomplished this by using libass, and basically using the code from 
vf_subtitles.c to render text subtitles and store the images in the AVSubtitle 
structure.

Of course, this functionality will only work when ffmpeg is configured with 
--enable-libass.

Traian Coza (12):
  Implemented text to bitmap subtitles!
  Render only when necessary
  Retreive width and height from video stream!
  Initialize ass library only once!
  Cleaned up
  Wrote proper headers
  Close libass after using
  Added standard headers
  Rearranged files, all tests are passing!
  Rearranged files, all tests are passing!
  Added logging
  Added more logging

 fftools/Makefile |   2 +
 fftools/ffmpeg.c |  35 -
 fftools/text_to_bitmap.c | 300 +++
 fftools/text_to_bitmap.h |  37 +
 libavcodec/avcodec.h |   9 ++
 5 files changed, 382 insertions(+), 1 deletion(-)
 create mode 100644 fftools/text_to_bitmap.c
 create mode 100644 fftools/text_to_bitmap.h

-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 01/12] Implemented text to bitmap subtitles!

2022-05-03 Thread Traian Coza
---
 fftools/ffmpeg.c   |  47 ++-
 libavfilter/vf_subtitles.c | 117 +
 2 files changed, 163 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index a85ed18b08..53717d3ebb 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2325,6 +2325,45 @@ fail:
 return err < 0 ? err : ret;
 }
 
+void render_avsub_ass(InputStream *, AVSubtitle *);
+
+static void print_subtitle(AVSubtitle sub)
+{
+printf("sub.format: %u\n", sub.format);
+printf("sub.start_display_time: %u\n", sub.start_display_time);
+printf("sub.end_display_time: %u\n", sub.end_display_time);
+printf("sub.num_rects: %u\n", sub.num_rects);
+printf("sub.pts: %ld\n", sub.pts);
+for (int i = 0; i < sub.num_rects; i++)
+{
+printf("sub.rects[%d]->type: %d\n", i, sub.rects[i]->type);
+printf("sub.rects[%d]->nb_colors: %d\n", i, sub.rects[i]->nb_colors);
+printf("sub.rects[%d]->(x,y,w,h): (%d,%d,%d,%d)\n", i, 
sub.rects[i]->x, sub.rects[i]->y, sub.rects[i]->w, sub.rects[i]->h);
+printf("sub.rects[%d]->linesize: [%d,%d,%d,%d]\n", i, 
sub.rects[i]->linesize[0], sub.rects[i]->linesize[1], 
sub.rects[i]->linesize[1], sub.rects[i]->linesize[1]);
+switch (sub.rects[i]->type)
+{
+case SUBTITLE_TEXT:
+printf("sub.rects[%d]->text: %s\n", i, sub.rects[i]->text);
+break;
+case SUBTITLE_ASS:
+printf("sub.rects[%d]->ass: %s\n", i, sub.rects[i]->ass);
+break;
+case SUBTITLE_BITMAP:
+for (int c = 0; c < sub.rects[i]->nb_colors; c++)
+printf("color %d: [%u,%u,%u,%u]\n", c,
+   sub.rects[i]->data[1][c * 4 + 0],
+   sub.rects[i]->data[1][c * 4 + 1],
+   sub.rects[i]->data[1][c * 4 + 2],
+   sub.rects[i]->data[1][c * 4 + 3]);
+for (int y = 0; y < sub.rects[i]->h; y++, printf("\n"))
+for (int x = 0; x < sub.rects[i]->w; x++)
+printf("%d", sub.rects[i]->data[0][y * sub.rects[i]->w 
+ x]);
+break;
+}
+}
+printf("\n");
+}
+
 static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int 
*got_output,
int *decode_failed)
 {
@@ -2383,6 +2422,8 @@ static int transcode_subtitles(InputStream *ist, AVPacket 
*pkt, int *got_output,
 goto out;
 
 ist->frames_decoded++;
+
+render_avsub_ass(ist, &subtitle);
 
 for (i = 0; i < nb_output_streams; i++) {
 OutputStream *ost = output_streams[i];
@@ -3213,11 +3254,15 @@ static int init_output_stream(OutputStream *ost, 
AVFrame *frame,
 input_props = input_descriptor->props & 
(AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
 if (output_descriptor)
 output_props = output_descriptor->props & 
(AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
-if (input_props && output_props && input_props != output_props) {
+/*if (input_props && output_props && input_props != output_props) {
 snprintf(error, error_len,
  "Subtitle encoding currently only possible from text 
to text "
  "or bitmap to bitmap");
 return AVERROR_INVALIDDATA;
+}*/
+if (input_props == AV_CODEC_PROP_BITMAP_SUB && output_props == 
AV_CODEC_PROP_TEXT_SUB) {
+snprintf(error, error_len, "Subtitle encoding from bitmap to 
text currently not possible");
+return AVERROR_INVALIDDATA;
 }
 }
 
diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
index 82e140e986..f751786033 100644
--- a/libavfilter/vf_subtitles.c
+++ b/libavfilter/vf_subtitles.c
@@ -181,6 +181,24 @@ static void overlay_ass_image(AssContext *ass, AVFrame 
*picref,
 }
 }
 
+static void print_ass_image(const ASS_Image *image)
+{
+int index = 0;
+for (; image != NULL; image = image->next, index++)
+{
+printf("index: %d\n", index);
+printf("image->(dst_x,dst_y): (%d,%d)\n", image->dst_x, image->dst_y);
+printf("image->(w,h): (%d,%d)\n", image->w, image->h);
+printf("image->stride: %d\n", image->stride);
+printf("image->type: %d\n", image->type);
+printf("image->color: [%u,%u,%u,%u]\n", AR(image->color), 
AG(image->color), AB(image->color), AA(image->color));
+for (int y = 0; y < image->h; y++, printf("\n"))
+for (int x = 0; x < image->w; x++)
+printf("%02X", image->bitmap[y * image->stride + x]);
+printf("\n");
+}
+}
+
 static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
 {
 AVFilterContext *ctx = inlink->dst;
@@ -199,6 +217,105 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*picref)
 return ff_filter_frame

[FFmpeg-devel] [PATCH 02/12] Render only when necessary

2022-05-03 Thread Traian Coza
---
 fftools/ffmpeg.c   | 12 ++--
 libavfilter/vf_subtitles.c |  1 -
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 53717d3ebb..dea2aec2ce 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2422,9 +2422,8 @@ static int transcode_subtitles(InputStream *ist, AVPacket 
*pkt, int *got_output,
 goto out;
 
 ist->frames_decoded++;
-
-render_avsub_ass(ist, &subtitle);
 
+int rendered = 0;
 for (i = 0; i < nb_output_streams; i++) {
 OutputStream *ost = output_streams[i];
 
@@ -2432,6 +2431,15 @@ static int transcode_subtitles(InputStream *ist, 
AVPacket *pkt, int *got_output,
 || ost->enc->type != AVMEDIA_TYPE_SUBTITLE)
 continue;
 
+if (avcodec_descriptor_get(ost->enc_ctx->codec_id)->props & 
AV_CODEC_PROP_BITMAP_SUB)
+if (avcodec_descriptor_get(ist->dec_ctx->codec_id)->props & 
AV_CODEC_PROP_TEXT_SUB)
+if (!rendered) {
+render_avsub_ass(ist, &subtitle);
+for (int r = 0; r < subtitle.num_rects; r++)
+subtitle.rects[r]->type = SUBTITLE_BITMAP;
+rendered = 1;
+}
+
 do_subtitle_out(output_files[ost->file_index], ost, &subtitle);
 }
 
diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
index f751786033..16f9c3fff6 100644
--- a/libavfilter/vf_subtitles.c
+++ b/libavfilter/vf_subtitles.c
@@ -307,7 +307,6 @@ void render_avsub_ass(InputStream *ist, AVSubtitle *sub)
 rect->data[0][y_rect * rect->w + x_rect] = color;
 }
 }
-rect->type = SUBTITLE_BITMAP;
 
 ass_free_track(track);
 }
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 03/12] Retreive width and height from video stream!

2022-05-03 Thread Traian Coza
---
 fftools/ffmpeg.c   | 29 ++---
 libavfilter/vf_subtitles.c |  9 -
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index dea2aec2ce..a74800bb68 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2325,7 +2325,7 @@ fail:
 return err < 0 ? err : ret;
 }
 
-void render_avsub_ass(InputStream *, AVSubtitle *);
+void render_avsub_ass(InputStream *, AVSubtitle *, int, int);
 
 static void print_subtitle(AVSubtitle sub)
 {
@@ -2423,7 +2423,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket 
*pkt, int *got_output,
 
 ist->frames_decoded++;
 
-int rendered = 0;
+int rendered = 0;   // Variable for text to bitmap support
 for (i = 0; i < nb_output_streams; i++) {
 OutputStream *ost = output_streams[i];
 
@@ -2431,10 +2431,33 @@ static int transcode_subtitles(InputStream *ist, 
AVPacket *pkt, int *got_output,
 || ost->enc->type != AVMEDIA_TYPE_SUBTITLE)
 continue;
 
+// Support text to bitmap
 if (avcodec_descriptor_get(ost->enc_ctx->codec_id)->props & 
AV_CODEC_PROP_BITMAP_SUB)
 if (avcodec_descriptor_get(ist->dec_ctx->codec_id)->props & 
AV_CODEC_PROP_TEXT_SUB)
 if (!rendered) {
-render_avsub_ass(ist, &subtitle);
+// Try to get a height and width from a video
+int width = 0, height = 0;
+// Try output streams
+for (int j = 0; j < nb_output_streams; j++)
+if (output_streams[j]->enc_ctx->codec_type == 
AVMEDIA_TYPE_VIDEO)
+{
+width = output_streams[j]->enc_ctx->width;
+height = output_streams[j]->enc_ctx->height;
+break;
+}
+if (width == 0)
+// Try input streams
+for (int j = 0; j < nb_input_streams; j++)
+if (input_streams[j]->dec_ctx->codec_type == 
AVMEDIA_TYPE_VIDEO)
+{
+width = input_streams[j]->dec_ctx->width;
+height = input_streams[j]->dec_ctx->height;
+break;
+}
+if (width == 0) {
+// TODO Error: Cannot render without a video stream
+}
+render_avsub_ass(ist, &subtitle, width, height);
 for (int r = 0; r < subtitle.num_rects; r++)
 subtitle.rects[r]->type = SUBTITLE_BITMAP;
 rendered = 1;
diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
index 16f9c3fff6..7226911f6c 100644
--- a/libavfilter/vf_subtitles.c
+++ b/libavfilter/vf_subtitles.c
@@ -223,16 +223,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*picref)
 
 #define ALPHA_THRESHOLD 0b1000
 
-void render_avsub_ass(InputStream *, AVSubtitle *);
-void render_avsub_ass(InputStream *ist, AVSubtitle *sub)
+void render_avsub_ass(InputStream *, AVSubtitle *, int, int);
+void render_avsub_ass(InputStream *ist, AVSubtitle *sub, int frame_width, int 
frame_height)
 {
 ASS_Library *library = ass_library_init();
 ass_set_extract_fonts(library, 1);
 ASS_Renderer *renderer = ass_renderer_init(library);
-int w = 1920, h = 1080;
-ass_set_frame_size(renderer, w, h);
+ass_set_frame_size(renderer, frame_width, frame_height);
 ass_set_pixel_aspect(renderer, 1);
-ass_set_storage_size(renderer, w, h);
+ass_set_storage_size(renderer, frame_width, frame_height);
 ass_set_shaper(renderer, 0);
 ass_set_fonts(renderer, NULL, NULL, 1, NULL, 1);
 
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 08/12] Added standard headers

2022-05-03 Thread Traian Coza
---
 libavcodec/text_to_bitmap.c | 47 -
 libavcodec/text_to_bitmap.h | 25 +---
 2 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/libavcodec/text_to_bitmap.c b/libavcodec/text_to_bitmap.c
index c419e89c20..52d161d7b1 100644
--- a/libavcodec/text_to_bitmap.c
+++ b/libavcodec/text_to_bitmap.c
@@ -1,4 +1,23 @@
+/*
+ * 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 to bitmap support code.
  *
  * This file contains a function to initiate the functionality for a stream,
@@ -11,6 +30,9 @@
 #include "avcodec.h"
 #include "ass_split.h"
 
+/**
+ * Holds the objects used by the rendering function so they don't have to be 
reinitialized every time
+ */
 struct ASS_Context {
 ASS_Library *library;
 ASS_Renderer *renderer;
@@ -18,6 +40,17 @@ struct ASS_Context {
 ASSSplitContext *ass_split_context;
 };
 
+/**
+ * Initiates the ASS_Context structure and adds it to the input stream decoder 
context.
+ * Does nothing if ist->dec_ctx->ass_context is already set.
+ * It needs all these arguments because it searches for a frame size in all 
the streams
+ * @param input_streams
+ * @param output_streams
+ * @param nb_input_streams
+ * @param nb_output_streams
+ * @param ist_i index of input stream for transcoding
+ * @param ost_i index of output stream for transcoding
+ */
 void init_ass_context(
 InputStream **input_streams,
 OutputStream **output_streams,
@@ -82,12 +115,17 @@ void init_ass_context(
 ass_set_shaper(context->renderer, 0);
 ass_set_fonts(context->renderer, NULL, NULL, 1, NULL, 1);
 
-context->track = ass_read_memory(context->library, (char 
*)ist->dec_ctx->subtitle_header, ist->dec_ctx->subtitle_header_size, NULL);
+context->track = ass_read_memory(context->library,
+(char *)ist->dec_ctx->subtitle_header, 
ist->dec_ctx->subtitle_header_size, NULL);
 context->ass_split_context = ff_ass_split((char 
*)ist->dec_ctx->subtitle_header);
 
 ist->dec_ctx->ass_context = context;
 }
 
+/**
+ * Frees what was allocated in init_ass_context
+ * @param context
+ */
 void free_ass_context(ASS_Context *context) {
 ass_library_done(context->library);
 ass_renderer_done(context->renderer);
@@ -104,6 +142,11 @@ void free_ass_context(ASS_Context *context) {
 
 #define ALPHA_THRESHOLD 0b1000
 
+/**
+ * Renders the AVSubtitle and sets the bitmap data for each AVSubtitleRect
+ * @param context
+ * @param sub
+ */
 void render_avsub_ass(ASS_Context *context, AVSubtitle *sub)
 {
 for (int r = 0; r < sub->num_rects; r++)
@@ -180,6 +223,7 @@ void render_avsub_ass(ASS_Context *context, AVSubtitle *sub)
 }
 }
 
+/*
 static void print_ass_image(const ASS_Image *image)
 {
 int index = 0;
@@ -234,3 +278,4 @@ static void print_subtitle(AVSubtitle sub)
 }
 printf("\n");
 }
+*/
\ No newline at end of file
diff --git a/libavcodec/text_to_bitmap.h b/libavcodec/text_to_bitmap.h
index 0c4689b039..29037150c2 100644
--- a/libavcodec/text_to_bitmap.h
+++ b/libavcodec/text_to_bitmap.h
@@ -1,9 +1,28 @@
+/*
+ * 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_to_bitmap header file
  */
 
-#ifndef FFMPEG_TEXT_TO_BITMAP_H
-#define FFMPEG_TEXT_TO_BITMAP_H
+#ifndef AVCODEC_TEXT_TO_BITMAP_H
+#define AVCODEC_TEXT_TO_BITMAP_H
 
 #include 
 #include "fftools/ffmpeg.h"
@@ -21,4 +40,4 @@ void init_ass_context(
 void render_avsub_ass(ASS_Context *, AVSubtitle *);
 void free_ass_context(ASS_Context *context);
 
-#endif //FFMPEG_TEXT_TO_BITM

[FFmpeg-devel] [PATCH 10/12] Rearranged files, all tests are passing!

2022-05-03 Thread Traian Coza
---
 fftools/Makefile |  2 ++
 fftools/ffmpeg.c |  6 --
 fftools/text_to_bitmap.c | 14 +++---
 fftools/text_to_bitmap.h | 14 --
 libavcodec/Makefile  |  1 -
 libavcodec/avcodec.c |  9 -
 6 files changed, 13 insertions(+), 33 deletions(-)

diff --git a/fftools/Makefile b/fftools/Makefile
index 81ad6c4f4f..f9334a5622 100644
--- a/fftools/Makefile
+++ b/fftools/Makefile
@@ -15,6 +15,8 @@ OBJS-ffmpeg +=  \
 fftools/ffmpeg_mux.o\
 fftools/ffmpeg_opt.o\
 
+OBJS-ffmpeg-$(CONFIG_LIBASS) += fftools/text_to_bitmap.o
+
 define DOFFTOOL
 OBJS-$(1) += fftools/cmdutils.o fftools/opt_common.o fftools/$(1).o 
$(OBJS-$(1)-yes)
 $(1)$(PROGSSUF)_g$(EXESUF): $$(OBJS-$(1))
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index ae622492ee..251a3ce427 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -72,7 +72,7 @@
 # include "libavfilter/buffersink.h"
 
 #if CONFIG_LIBASS
-#include "libavcodec/text_to_bitmap.h"
+#include "fftools/text_to_bitmap.h"
 #endif
 
 #if HAVE_SYS_RESOURCE_H
@@ -3239,7 +3239,7 @@ static int init_output_stream(OutputStream *ost, AVFrame 
*frame,
 return AVERROR_INVALIDDATA;
 }
 if (input_props == AV_CODEC_PROP_TEXT_SUB && output_props == 
AV_CODEC_PROP_BITMAP_SUB)
-init_ass_context(input_streams, output_streams, 
nb_input_streams, nb_output_streams, ost->source_index, ost->index);
+init_ass_context(ist, ost);
 #else
 if (input_props && output_props && input_props != output_props) {
 snprintf(error, error_len,
@@ -4514,6 +4514,8 @@ static int transcode(void)
 ist = input_streams[i];
 if (ist->decoding_needed) {
 avcodec_close(ist->dec_ctx);
+if (ist->dec_ctx->ass_context != NULL) // This really has to 
be done here, sorry
+free_ass_context(ist->dec_ctx->ass_context);
 if (ist->hwaccel_uninit)
 ist->hwaccel_uninit(ist->dec_ctx);
 }
diff --git a/fftools/text_to_bitmap.c b/fftools/text_to_bitmap.c
index 52d161d7b1..b4a0157174 100644
--- a/fftools/text_to_bitmap.c
+++ b/fftools/text_to_bitmap.c
@@ -27,8 +27,8 @@
 #include "text_to_bitmap.h"
 
 #include "fftools/ffmpeg.h"
-#include "avcodec.h"
-#include "ass_split.h"
+#include "../libavcodec/avcodec.h"
+#include "../libavcodec/ass_split.h"
 
 /**
  * Holds the objects used by the rendering function so they don't have to be 
reinitialized every time
@@ -51,16 +51,8 @@ struct ASS_Context {
  * @param ist_i index of input stream for transcoding
  * @param ost_i index of output stream for transcoding
  */
-void init_ass_context(
-InputStream **input_streams,
-OutputStream **output_streams,
-int nb_input_streams,
-int nb_output_streams,
-int ist_i,
-int ost_i)
+void init_ass_context(InputStream *ist, OutputStream *ost)
 {
-InputStream *ist = input_streams[ist_i];
-OutputStream *ost = output_streams[ost_i];
 if (ist->dec_ctx->ass_context) return;
 
 ASS_Context *context = (ASS_Context *)malloc(sizeof(ASS_Context));
diff --git a/fftools/text_to_bitmap.h b/fftools/text_to_bitmap.h
index 29037150c2..a9b48c6cf3 100644
--- a/fftools/text_to_bitmap.h
+++ b/fftools/text_to_bitmap.h
@@ -21,8 +21,8 @@
  * text_to_bitmap header file
  */
 
-#ifndef AVCODEC_TEXT_TO_BITMAP_H
-#define AVCODEC_TEXT_TO_BITMAP_H
+#ifndef FFTOOLS_TEXT_TO_BITMAP_H
+#define FFTOOLS_TEXT_TO_BITMAP_H
 
 #include 
 #include "fftools/ffmpeg.h"
@@ -30,14 +30,8 @@
 struct ASS_Context;
 typedef struct ASS_Context ASS_Context;
 
-void init_ass_context(
-InputStream **input_streams,
-OutputStream **output_streams,
-int nb_input_streams,
-int nb_output_streams,
-int ist_i,
-int ost_i);
+void init_ass_context(InputStream *ist, OutputStream *ost);
 void render_avsub_ass(ASS_Context *, AVSubtitle *);
 void free_ass_context(ASS_Context *context);
 
-#endif //AVCODEC_TEXT_TO_BITMAP_H
+#endif //FFTOOLS_TEXT_TO_BITMAP_H
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 6d28513129..cfaa6f196a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -151,7 +151,6 @@ OBJS-$(CONFIG_RV34DSP) += rv34dsp.o
 OBJS-$(CONFIG_SINEWIN) += sinewin.o
 OBJS-$(CONFIG_SNAPPY)  += snappy.o
 OBJS-$(CONFIG_STARTCODE)   += startcode.o
-OBJS-$(CONFIG_LIBASS)  += text_to_bitmap.o
 OBJS-$(CONFIG_TEXTUREDSP)  += texturedsp.o
 OBJS-$(CONFIG_TEXTUREDSPENC)   += texturedspenc.o
 OBJS-$(CONFIG_TPELDSP) += tpeldsp.o
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 1e308f39c2..d11f035481 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -42,10 +42,6 @@
 #include "thread.h"
 #include "version.h"
 
-#if CONFIG_LIBASS
-#include "libavcodec/text_to_bitmap.h"
-#endif
-
 #include "libavutil/ffversion.

[FFmpeg-devel] [PATCH 09/12] Rearranged files, all tests are passing!

2022-05-03 Thread Traian Coza
---
 {libavcodec => fftools}/text_to_bitmap.c | 0
 {libavcodec => fftools}/text_to_bitmap.h | 0
 2 files changed, 0 insertions(+), 0 deletions(-)
 rename {libavcodec => fftools}/text_to_bitmap.c (100%)
 rename {libavcodec => fftools}/text_to_bitmap.h (100%)

diff --git a/libavcodec/text_to_bitmap.c b/fftools/text_to_bitmap.c
similarity index 100%
rename from libavcodec/text_to_bitmap.c
rename to fftools/text_to_bitmap.c
diff --git a/libavcodec/text_to_bitmap.h b/fftools/text_to_bitmap.h
similarity index 100%
rename from libavcodec/text_to_bitmap.h
rename to fftools/text_to_bitmap.h
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 04/12] Initialize ass library only once!

2022-05-03 Thread Traian Coza
---
 fftools/ffmpeg.c|  50 ---
 libavcodec/Makefile |   1 +
 libavcodec/avcodec.h|   9 ++
 libavcodec/text_to_bitmap.c | 170 
 libavcodec/text_to_bitmap.h |  18 
 libavfilter/vf_subtitles.c  |  97 
 6 files changed, 217 insertions(+), 128 deletions(-)
 create mode 100644 libavcodec/text_to_bitmap.c
 create mode 100644 libavcodec/text_to_bitmap.h

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index a74800bb68..31acf08a6a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -71,6 +71,10 @@
 # include "libavfilter/buffersrc.h"
 # include "libavfilter/buffersink.h"
 
+#if CONFIG_LIBASS
+#include "libavcodec/text_to_bitmap.h"
+#endif
+
 #if HAVE_SYS_RESOURCE_H
 #include 
 #include 
@@ -2325,8 +2329,6 @@ fail:
 return err < 0 ? err : ret;
 }
 
-void render_avsub_ass(InputStream *, AVSubtitle *, int, int);
-
 static void print_subtitle(AVSubtitle sub)
 {
 printf("sub.format: %u\n", sub.format);
@@ -2434,30 +2436,8 @@ static int transcode_subtitles(InputStream *ist, 
AVPacket *pkt, int *got_output,
 // Support text to bitmap
 if (avcodec_descriptor_get(ost->enc_ctx->codec_id)->props & 
AV_CODEC_PROP_BITMAP_SUB)
 if (avcodec_descriptor_get(ist->dec_ctx->codec_id)->props & 
AV_CODEC_PROP_TEXT_SUB)
-if (!rendered) {
-// Try to get a height and width from a video
-int width = 0, height = 0;
-// Try output streams
-for (int j = 0; j < nb_output_streams; j++)
-if (output_streams[j]->enc_ctx->codec_type == 
AVMEDIA_TYPE_VIDEO)
-{
-width = output_streams[j]->enc_ctx->width;
-height = output_streams[j]->enc_ctx->height;
-break;
-}
-if (width == 0)
-// Try input streams
-for (int j = 0; j < nb_input_streams; j++)
-if (input_streams[j]->dec_ctx->codec_type == 
AVMEDIA_TYPE_VIDEO)
-{
-width = input_streams[j]->dec_ctx->width;
-height = input_streams[j]->dec_ctx->height;
-break;
-}
-if (width == 0) {
-// TODO Error: Cannot render without a video stream
-}
-render_avsub_ass(ist, &subtitle, width, height);
+if (!rendered) {// Make sure not to render twice
+render_avsub_ass(ist->dec_ctx->ass_context, &subtitle);
 for (int r = 0; r < subtitle.num_rects; r++)
 subtitle.rects[r]->type = SUBTITLE_BITMAP;
 rendered = 1;
@@ -2757,6 +2737,9 @@ static int init_input_stream(int ist_index, char *error, 
int error_len)
  * audio, and video decoders such as cuvid or mediacodec */
 ist->dec_ctx->pkt_timebase = ist->st->time_base;
 
+// For text to bitmap rendering
+ist->dec_ctx->ass_context = NULL;
+
 if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0))
 av_dict_set(&ist->decoder_opts, "threads", "auto", 0);
 /* Attached pics are sparse, therefore we would not want to delay 
their decoding till EOF. */
@@ -3285,16 +3268,21 @@ static int init_output_stream(OutputStream *ost, 
AVFrame *frame,
 input_props = input_descriptor->props & 
(AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
 if (output_descriptor)
 output_props = output_descriptor->props & 
(AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
-/*if (input_props && output_props && input_props != output_props) {
+#if CONFIG_LIBASS
+if (input_props == AV_CODEC_PROP_BITMAP_SUB && output_props == 
AV_CODEC_PROP_TEXT_SUB) {
+snprintf(error, error_len, "Subtitle encoding from bitmap to 
text currently not possible");
+return AVERROR_INVALIDDATA;
+}
+if (input_props == AV_CODEC_PROP_TEXT_SUB && output_props == 
AV_CODEC_PROP_BITMAP_SUB)
+init_ass_context(ist, ost);
+#else
+if (input_props && output_props && input_props != output_props) {
 snprintf(error, error_len,
  "Subtitle encoding currently only possible from text 
to text "
  "or bitmap to bitmap");
 return AVERROR_INVALIDDATA;
-}*/
-if (input_props == AV_CODEC_PROP_BITMAP_SUB && output_props == 
AV_CODEC_PROP_TEXT_SUB) {
-snprintf(error, error_len, "Subtitle encoding from bitmap to 
text currently not possible");
-return AVERROR_INVALIDDATA;
 }
+#endif
 }

[FFmpeg-devel] [PATCH 05/12] Cleaned up

2022-05-03 Thread Traian Coza
---
 fftools/ffmpeg.c| 39 ++---
 libavcodec/text_to_bitmap.c | 58 +++--
 libavfilter/vf_subtitles.c  | 18 
 3 files changed, 58 insertions(+), 57 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 31acf08a6a..0ff9da7bf4 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2329,43 +2329,6 @@ fail:
 return err < 0 ? err : ret;
 }
 
-static void print_subtitle(AVSubtitle sub)
-{
-printf("sub.format: %u\n", sub.format);
-printf("sub.start_display_time: %u\n", sub.start_display_time);
-printf("sub.end_display_time: %u\n", sub.end_display_time);
-printf("sub.num_rects: %u\n", sub.num_rects);
-printf("sub.pts: %ld\n", sub.pts);
-for (int i = 0; i < sub.num_rects; i++)
-{
-printf("sub.rects[%d]->type: %d\n", i, sub.rects[i]->type);
-printf("sub.rects[%d]->nb_colors: %d\n", i, sub.rects[i]->nb_colors);
-printf("sub.rects[%d]->(x,y,w,h): (%d,%d,%d,%d)\n", i, 
sub.rects[i]->x, sub.rects[i]->y, sub.rects[i]->w, sub.rects[i]->h);
-printf("sub.rects[%d]->linesize: [%d,%d,%d,%d]\n", i, 
sub.rects[i]->linesize[0], sub.rects[i]->linesize[1], 
sub.rects[i]->linesize[1], sub.rects[i]->linesize[1]);
-switch (sub.rects[i]->type)
-{
-case SUBTITLE_TEXT:
-printf("sub.rects[%d]->text: %s\n", i, sub.rects[i]->text);
-break;
-case SUBTITLE_ASS:
-printf("sub.rects[%d]->ass: %s\n", i, sub.rects[i]->ass);
-break;
-case SUBTITLE_BITMAP:
-for (int c = 0; c < sub.rects[i]->nb_colors; c++)
-printf("color %d: [%u,%u,%u,%u]\n", c,
-   sub.rects[i]->data[1][c * 4 + 0],
-   sub.rects[i]->data[1][c * 4 + 1],
-   sub.rects[i]->data[1][c * 4 + 2],
-   sub.rects[i]->data[1][c * 4 + 3]);
-for (int y = 0; y < sub.rects[i]->h; y++, printf("\n"))
-for (int x = 0; x < sub.rects[i]->w; x++)
-printf("%d", sub.rects[i]->data[0][y * sub.rects[i]->w 
+ x]);
-break;
-}
-}
-printf("\n");
-}
-
 static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int 
*got_output,
int *decode_failed)
 {
@@ -2433,6 +2396,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket 
*pkt, int *got_output,
 || ost->enc->type != AVMEDIA_TYPE_SUBTITLE)
 continue;
 
+#if CONFIG_LIBASS
 // Support text to bitmap
 if (avcodec_descriptor_get(ost->enc_ctx->codec_id)->props & 
AV_CODEC_PROP_BITMAP_SUB)
 if (avcodec_descriptor_get(ist->dec_ctx->codec_id)->props & 
AV_CODEC_PROP_TEXT_SUB)
@@ -2442,6 +2406,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket 
*pkt, int *got_output,
 subtitle.rects[r]->type = SUBTITLE_BITMAP;
 rendered = 1;
 }
+#endif
 
 do_subtitle_out(output_files[ost->file_index], ost, &subtitle);
 }
diff --git a/libavcodec/text_to_bitmap.c b/libavcodec/text_to_bitmap.c
index 87c46985d9..50c72afc55 100644
--- a/libavcodec/text_to_bitmap.c
+++ b/libavcodec/text_to_bitmap.c
@@ -94,7 +94,6 @@ void free_ass_context(ASS_Context *context) {
 
 void render_avsub_ass(ASS_Context *context, AVSubtitle *sub)
 {
-printf("render_avsub_ass\n");
 for (int r = 0; r < sub->num_rects; r++)
 {
 AVSubtitleRect *rect = sub->rects[r];
@@ -167,4 +166,59 @@ void render_avsub_ass(ASS_Context *context, AVSubtitle 
*sub)
 }
 }
 }
-}
\ No newline at end of file
+}
+
+static void print_ass_image(const ASS_Image *image)
+{
+int index = 0;
+for (; image != NULL; image = image->next, index++)
+{
+printf("index: %d\n", index);
+printf("image->(dst_x,dst_y): (%d,%d)\n", image->dst_x, image->dst_y);
+printf("image->(w,h): (%d,%d)\n", image->w, image->h);
+printf("image->stride: %d\n", image->stride);
+printf("image->type: %d\n", image->type);
+printf("image->color: [%u,%u,%u,%u]\n", AR(image->color), 
AG(image->color), AB(image->color), AA(image->color));
+for (int y = 0; y < image->h; y++, printf("\n"))
+for (int x = 0; x < image->w; x++)
+printf("%02X", image->bitmap[y * image->stride + x]);
+printf("\n");
+}
+}
+
+static void print_subtitle(AVSubtitle sub)
+{
+printf("sub.format: %u\n", sub.format);
+printf("sub.start_display_time: %u\n", sub.start_display_time);
+printf("sub.end_display_time: %u\n", sub.end_display_time);
+printf("sub.num_rects: %u\n", sub.num_rects);
+printf("sub.pts: %ld\n", sub.pts);
+for (int i = 0; i < sub.num_rects; i++)
+{
+printf("sub.rects[%d]->type: %d\n", i, sub.rects[i]->type);
+printf("sub.rects[%d]->nb_

[FFmpeg-devel] [PATCH 11/12] Added logging

2022-05-03 Thread Traian Coza
---
 fftools/ffmpeg.c |  4 +++-
 fftools/text_to_bitmap.c | 27 ++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 251a3ce427..b4d3d491de 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3244,7 +3244,7 @@ static int init_output_stream(OutputStream *ost, AVFrame 
*frame,
 if (input_props && output_props && input_props != output_props) {
 snprintf(error, error_len,
  "Subtitle encoding currently only possible from text 
to text "
- "or bitmap to bitmap");
+ "or bitmap to bitmap (configure with --enable-libass 
for text to bitmap support)");
 return AVERROR_INVALIDDATA;
 }
 #endif
@@ -4514,8 +4514,10 @@ static int transcode(void)
 ist = input_streams[i];
 if (ist->decoding_needed) {
 avcodec_close(ist->dec_ctx);
+#if CONFIG_LIBASS
 if (ist->dec_ctx->ass_context != NULL) // This really has to 
be done here, sorry
 free_ass_context(ist->dec_ctx->ass_context);
+#endif
 if (ist->hwaccel_uninit)
 ist->hwaccel_uninit(ist->dec_ctx);
 }
diff --git a/fftools/text_to_bitmap.c b/fftools/text_to_bitmap.c
index b4a0157174..0f165e7722 100644
--- a/fftools/text_to_bitmap.c
+++ b/fftools/text_to_bitmap.c
@@ -40,6 +40,30 @@ struct ASS_Context {
 ASSSplitContext *ass_split_context;
 };
 
+// Copied from vf_subtitles.c
+/* libass supports a log level ranging from 0 to 7 */
+static const int ass_libavfilter_log_level_map[] = {
+[0] = AV_LOG_FATAL, /* MSGL_FATAL */
+[1] = AV_LOG_ERROR, /* MSGL_ERR */
+[2] = AV_LOG_WARNING,   /* MSGL_WARN */
+[3] = AV_LOG_WARNING,   /*  */
+[4] = AV_LOG_INFO,  /* MSGL_INFO */
+[5] = AV_LOG_INFO,  /*  */
+[6] = AV_LOG_VERBOSE,   /* MSGL_V */
+[7] = AV_LOG_DEBUG, /* MSGL_DBG2 */
+};
+
+// Also copied
+static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)
+{
+const int ass_level_clip = av_clip(ass_level, 0,
+FF_ARRAY_ELEMS(ass_libavfilter_log_level_map) - 1);
+const int level = ass_libavfilter_log_level_map[ass_level_clip];
+
+av_vlog(NULL, level, fmt, args);
+av_log(NULL, level, "\n");
+}
+
 /**
  * Initiates the ASS_Context structure and adds it to the input stream decoder 
context.
  * Does nothing if ist->dec_ctx->ass_context is already set.
@@ -57,6 +81,7 @@ void init_ass_context(InputStream *ist, OutputStream *ost)
 
 ASS_Context *context = (ASS_Context *)malloc(sizeof(ASS_Context));
 context->library = ass_library_init();
+ass_set_message_cb(context->library, ass_log, NULL);
 ass_set_extract_fonts(context->library, 1);
 // TODO: ass_add_font(context->library, ...);
 
@@ -172,7 +197,7 @@ void render_avsub_ass(ASS_Context *context, AVSubtitle *sub)
 
 ASS_Image *image = ass_render_frame(context->renderer, track,
 track->events[0].Start + track->events[0].Duration / 2, NULL);
-if (image == NULL) printf("WARNING: failed to render ass\n");
+if (image == NULL) av_log(NULL, AV_LOG_WARNING, "failed to render 
ass\n");
 
 rect->x = image ? image->dst_x : 0; rect->w = 0;
 rect->y = image ? image->dst_y : 0; rect->h = 0;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 06/12] Wrote proper headers

2022-05-03 Thread Traian Coza
---
 libavcodec/text_to_bitmap.c | 9 ++---
 libavcodec/text_to_bitmap.h | 6 +++---
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavcodec/text_to_bitmap.c b/libavcodec/text_to_bitmap.c
index 50c72afc55..273564cb67 100644
--- a/libavcodec/text_to_bitmap.c
+++ b/libavcodec/text_to_bitmap.c
@@ -1,6 +1,9 @@
-//
-// Created by traian on 2022-05-02.
-//
+/**
+ * text to bitmap support code.
+ *
+ * This file contains a function to initiate the functionality for a stream,
+ * to render any AVSubtitle structure, and to free the structures allocated at 
the start
+ */
 
 #include "text_to_bitmap.h"
 
diff --git a/libavcodec/text_to_bitmap.h b/libavcodec/text_to_bitmap.h
index 4cba5889f4..37d346ae0c 100644
--- a/libavcodec/text_to_bitmap.h
+++ b/libavcodec/text_to_bitmap.h
@@ -1,6 +1,6 @@
-//
-// Created by traian on 2022-05-02.
-//
+/**
+ * text_to_bitmap header file
+ */
 
 #ifndef FFMPEG_TEXT_TO_BITMAP_H
 #define FFMPEG_TEXT_TO_BITMAP_H
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 12/12] Added more logging

2022-05-03 Thread Traian Coza
---
 fftools/text_to_bitmap.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fftools/text_to_bitmap.c b/fftools/text_to_bitmap.c
index 0f165e7722..e05e485713 100644
--- a/fftools/text_to_bitmap.c
+++ b/fftools/text_to_bitmap.c
@@ -122,7 +122,8 @@ void init_ass_context(InputStream *ist, OutputStream *ost)
 }
 if (width && height) break;
 
-// TODO Error: Cannot render without a width and height
+av_log(NULL, AV_LOG_ERROR, "Cannot render text subtitle without frame 
size\n");
+return;
 } while (0);
 
 context->renderer = ass_renderer_init(context->library);
@@ -197,7 +198,8 @@ void render_avsub_ass(ASS_Context *context, AVSubtitle *sub)
 
 ASS_Image *image = ass_render_frame(context->renderer, track,
 track->events[0].Start + track->events[0].Duration / 2, NULL);
-if (image == NULL) av_log(NULL, AV_LOG_WARNING, "failed to render 
ass\n");
+if (image == NULL) av_log(NULL, AV_LOG_WARNING,
+"failed to render ass: %s\n", rect->ass);
 
 rect->x = image ? image->dst_x : 0; rect->w = 0;
 rect->y = image ? image->dst_y : 0; rect->h = 0;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 07/12] Close libass after using

2022-05-03 Thread Traian Coza
---
 fftools/ffmpeg.c|  2 +-
 libavcodec/avcodec.c|  9 +
 libavcodec/text_to_bitmap.c | 13 +++--
 libavcodec/text_to_bitmap.h |  8 +++-
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 0ff9da7bf4..ae622492ee 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3239,7 +3239,7 @@ static int init_output_stream(OutputStream *ost, AVFrame 
*frame,
 return AVERROR_INVALIDDATA;
 }
 if (input_props == AV_CODEC_PROP_TEXT_SUB && output_props == 
AV_CODEC_PROP_BITMAP_SUB)
-init_ass_context(ist, ost);
+init_ass_context(input_streams, output_streams, 
nb_input_streams, nb_output_streams, ost->source_index, ost->index);
 #else
 if (input_props && output_props && input_props != output_props) {
 snprintf(error, error_len,
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index d11f035481..1e308f39c2 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -42,6 +42,10 @@
 #include "thread.h"
 #include "version.h"
 
+#if CONFIG_LIBASS
+#include "libavcodec/text_to_bitmap.h"
+#endif
+
 #include "libavutil/ffversion.h"
 const char av_codec_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
 
@@ -534,6 +538,11 @@ av_cold int avcodec_close(AVCodecContext *avctx)
 } else if (av_codec_is_decoder(avctx->codec))
 av_freep(&avctx->subtitle_header);
 
+#if CONFIG_LIBASS
+if (av_codec_is_decoder(avctx->codec) && avctx->ass_context != NULL)
+free_ass_context(avctx->ass_context);
+#endif
+
 avctx->codec = NULL;
 avctx->active_thread_type = 0;
 
diff --git a/libavcodec/text_to_bitmap.c b/libavcodec/text_to_bitmap.c
index 273564cb67..c419e89c20 100644
--- a/libavcodec/text_to_bitmap.c
+++ b/libavcodec/text_to_bitmap.c
@@ -18,13 +18,22 @@ struct ASS_Context {
 ASSSplitContext *ass_split_context;
 };
 
-void init_ass_context(InputStream *ist, OutputStream *ost)
+void init_ass_context(
+InputStream **input_streams,
+OutputStream **output_streams,
+int nb_input_streams,
+int nb_output_streams,
+int ist_i,
+int ost_i)
 {
+InputStream *ist = input_streams[ist_i];
+OutputStream *ost = output_streams[ost_i];
 if (ist->dec_ctx->ass_context) return;
+
 ASS_Context *context = (ASS_Context *)malloc(sizeof(ASS_Context));
 context->library = ass_library_init();
 ass_set_extract_fonts(context->library, 1);
-// TODO: ass_add_font(context->library, );
+// TODO: ass_add_font(context->library, ...);
 
 // Try to get a height and width from somewhere
 int width = 0, height = 0;
diff --git a/libavcodec/text_to_bitmap.h b/libavcodec/text_to_bitmap.h
index 37d346ae0c..0c4689b039 100644
--- a/libavcodec/text_to_bitmap.h
+++ b/libavcodec/text_to_bitmap.h
@@ -11,7 +11,13 @@
 struct ASS_Context;
 typedef struct ASS_Context ASS_Context;
 
-void init_ass_context(InputStream *ist, OutputStream *ost);
+void init_ass_context(
+InputStream **input_streams,
+OutputStream **output_streams,
+int nb_input_streams,
+int nb_output_streams,
+int ist_i,
+int ost_i);
 void render_avsub_ass(ASS_Context *, AVSubtitle *);
 void free_ass_context(ASS_Context *context);
 
-- 
2.34.1

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

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


Re: [FFmpeg-devel] Need help submitting a patch

2022-05-03 Thread Traian Coza
Thanks, I finally managed to submit my patch with your instructions.
However, I see that the "Less secure apps" setting will no longer be
available in a month. What do you plan on doing then? (I see you also use
gmail)

On Tue, May 3, 2022 at 11:53 AM Leo Izen  wrote:

> On 5/3/22 00:12, Traian Coza wrote:
> > Hi! I am new to contributing to FFmpeg, and I have a technical question.
> >
> > I'm trying to submit a patch, but it's a fairly large patch, which I've
> > made in multiple commits. I don't know how to generate the email for this
> > patch. The example command given on the website (with format-patch) only
> > generates the email for a single commit. I've searched the web and I
> don't
> > really see an easy way to do it. Can someone help me out with this?
> >
> I find the easiest way to do it for me is to generate the patches with
> "git format-patch" and then send them with "git send-email".
>
> Once you have your patches atop the master branch, you can create a
> directory called outgoing/ and then run something like:
>
> git format-patch -M -o outgoing/ --cover-letter origin/master
>
> In this case, --cover-letter generates a cover letter, which you then
> edit to give a short blurb of what your patch set looks like. Then when
> you run git send-email outgoing/* you will have the patches embedded as
> replies to that cover letter email. "origin/master" is the hash of the
> last commit *before* yours, but it can by any ref, such as
> origin/master, not just a commit hash. You can also just substitute the
> commit hash there if your repositories/branches are named differently.
>
> Since you use Gmail (at least, from your email address), you will need
> to enable Less Secure Apps if you have two-factor authentication
> disabled. If you have it enabled, you will have to generate an App
> Password for git-send-email, and then use that as the account password
> instead of your own.
>
> - Leo Izen (thebombzen)
>
>
> ___
> 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 00/12] I added text to bitmap subtitle conversion functionality!

2022-05-03 Thread Paul B Mahol
On Tue, May 3, 2022 at 6:13 PM Traian Coza  wrote:

> I added the possibility of converting text-based subtitle tracks (such as
> subrip or ass) to bitmap-based subtitle tracks (such as dvd_subtitle).
>
> I accomplished this by using libass, and basically using the code from
> vf_subtitles.c to render text subtitles and store the images in the
> AVSubtitle structure.
>
> Of course, this functionality will only work when ffmpeg is configured
> with --enable-libass.
>
>
Sorry but i think this needs to be in libavfilter instead of libavcodec.

And for libavfilter one needs to add proper, not hacky, subtitle support to
library.



> Traian Coza (12):
>   Implemented text to bitmap subtitles!
>   Render only when necessary
>   Retreive width and height from video stream!
>   Initialize ass library only once!
>   Cleaned up
>   Wrote proper headers
>   Close libass after using
>   Added standard headers
>   Rearranged files, all tests are passing!
>   Rearranged files, all tests are passing!
>   Added logging
>   Added more logging
>
>  fftools/Makefile |   2 +
>  fftools/ffmpeg.c |  35 -
>  fftools/text_to_bitmap.c | 300 +++
>  fftools/text_to_bitmap.h |  37 +
>  libavcodec/avcodec.h |   9 ++
>  5 files changed, 382 insertions(+), 1 deletion(-)
>  create mode 100644 fftools/text_to_bitmap.c
>  create mode 100644 fftools/text_to_bitmap.h
>
> --
> 2.34.1
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel 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 00/12] I added text to bitmap subtitle conversion functionality!

2022-05-03 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Traian Coza
> Sent: Tuesday, May 3, 2022 6:13 PM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Traian Coza 
> Subject: [FFmpeg-devel] [PATCH 00/12] I added text to bitmap subtitle
> conversion functionality!
> 
> I added the possibility of converting text-based subtitle tracks (such
> as subrip or ass) to bitmap-based subtitle tracks (such as
> dvd_subtitle).
> 
> I accomplished this by using libass, and basically using the code from
> vf_subtitles.c to render text subtitles and store the images in the
> AVSubtitle structure.

Have you seen this: https://github.com/ffstaging/FFmpeg/pull/18

sw
___
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/2] avcodec/smacker: Optimize constant 16bit audio output

2022-05-03 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavcodec/smacker.c | 24 ++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
index 179c70f1ee..5d94a54179 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -601,7 +601,7 @@ static int smka_decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 int i, res, ret;
 int unp_size;
 int bits, stereo;
-unsigned pred[2], val;
+unsigned pred[2], val, val2;
 
 if (buf_size <= 4) {
 av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
@@ -672,7 +672,11 @@ static int smka_decode_frame(AVCodecContext *avctx, 
AVFrame *frame,
 pred[i] = av_bswap16(get_bits(&gb, 16));
 for(i = 0; i <= stereo; i++)
 *samples++ = pred[i];
-for(; i < unp_size / 2; i++) {
+unp_size /= 2;
+
+if (vlc[0   ].table || vlc[ 1].table ||
+vlc[2*stereo].table || vlc[2*stereo+1].table) {
+for(; i < unp_size ; i++) {
 unsigned idx = 2 * (i & stereo);
 if (get_bits_left(&gb) < 0) {
 ret = AVERROR_INVALIDDATA;
@@ -691,6 +695,22 @@ static int smka_decode_frame(AVCodecContext *avctx, 
AVFrame *frame,
 pred[idx / 2] += val;
 *samples++ = pred[idx / 2];
 }
+} else if (stereo) {
+val  = 256*values[1] + values[0];
+val2 = 256*values[3] + values[2];
+for(; i < unp_size; i+=2) {
+pred[0] += val;
+pred[1] += val2;
+*samples++ = pred[0];
+*samples++ = pred[1];
+}
+} else {
+val = 256*values[1] + values[0];
+for(; i < unp_size; i++) {
+pred[0] += val;
+*samples++ = pred[0];
+}
+}
 } else { //8-bit data
 for(i = stereo; i >= 0; i--)
 pred[i] = get_bits(&gb, 8);
-- 
2.17.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/2] tools/target_dec_fuzzer: Adjust threshold for smacker audio

2022-05-03 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
47043/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SMACKAUD_fuzzer-4824799337119744

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 tools/target_dec_fuzzer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
index 288aa63313..0eddeaf69a 100644
--- a/tools/target_dec_fuzzer.c
+++ b/tools/target_dec_fuzzer.c
@@ -202,6 +202,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 case AV_CODEC_ID_SANM:maxpixels  /= 16;break;
 case AV_CODEC_ID_SCPR:maxpixels  /= 32;break;
 case AV_CODEC_ID_SCREENPRESSO:maxpixels  /= 64;break;
+case AV_CODEC_ID_SMACKAUDIO:  maxsamples /= 4096;  break;
 case AV_CODEC_ID_SMACKVIDEO:  maxpixels  /= 64;break;
 case AV_CODEC_ID_SNOW:maxpixels  /= 128;   break;
 case AV_CODEC_ID_TARGA:   maxpixels  /= 128;   break;
-- 
2.17.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 00/12] I added text to bitmap subtitle conversion functionality!

2022-05-03 Thread Nicolas George
Paul B Mahol (12022-05-03):
> Sorry but i think this needs to be in libavfilter instead of libavcodec.
> 
> And for libavfilter one needs to add proper, not hacky, subtitle support to
> library.

I completely agree.

Also, the patches neglect a lot of the directives in the developer
documentation, from having self-contained clean commits to the wording
of the commit messages.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v2 0/2] JPEG XL Colorspace Fixes

2022-05-03 Thread Leo Izen
Add proper colorspace handling and tagging to the libjxl
decoder and encoder wrappers.

Changes
v2:
- avoid misusing AVMasteringDisplayMetadata
- ignore custom primaries in header (very rare without iccp)

Leo Izen (2):
  avcodec/libjxldec: properly tag output colorspace
  avcodec/libjxlenc: properly read input colorspace

 libavcodec/libjxldec.c |  84 +++-
 libavcodec/libjxlenc.c | 124 ++---
 2 files changed, 174 insertions(+), 34 deletions(-)

-- 
2.36.0

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

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


[FFmpeg-devel] [PATCH v2 1/2] avcodec/libjxldec: properly tag output colorspace

2022-05-03 Thread Leo Izen
Whether an ICC profile is present or not, the decoder
should now properly tag the colorspace of pixel data
received by the decoder.
---
 libavcodec/libjxldec.c | 84 --
 1 file changed, 81 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c
index cd4bca3343..e6a46288a6 100644
--- a/libavcodec/libjxldec.c
+++ b/libavcodec/libjxldec.c
@@ -189,16 +189,94 @@ static int libjxl_decode_frame(AVCodecContext *avctx, 
AVFrame *frame, int *got_f
 continue;
 case JXL_DEC_COLOR_ENCODING:
 av_log(avctx, AV_LOG_DEBUG, "COLOR_ENCODING event emitted\n");
-jret = JxlDecoderGetICCProfileSize(ctx->decoder, &ctx->jxl_pixfmt, 
JXL_COLOR_PROFILE_TARGET_ORIGINAL, &iccp_len);
+jret = JxlDecoderGetICCProfileSize(ctx->decoder, &ctx->jxl_pixfmt, 
JXL_COLOR_PROFILE_TARGET_DATA, &iccp_len);
 if (jret == JXL_DEC_SUCCESS && iccp_len > 0) {
 av_buffer_unref(&ctx->iccp);
 ctx->iccp = av_buffer_alloc(iccp_len);
 if (!ctx->iccp)
 return AVERROR(ENOMEM);
-jret = JxlDecoderGetColorAsICCProfile(ctx->decoder, 
&ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_ORIGINAL, ctx->iccp->data, iccp_len);
-if (jret != JXL_DEC_SUCCESS)
+jret = JxlDecoderGetColorAsICCProfile(ctx->decoder, 
&ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_DATA, ctx->iccp->data, iccp_len);
+if (jret != JXL_DEC_SUCCESS) {
+av_log(avctx, AV_LOG_WARNING, "Unable to obtain ICCP from 
header\n");
 av_buffer_unref(&ctx->iccp);
+}
 }
+avctx->color_range = frame->color_range = AVCOL_RANGE_JPEG;
+if (ctx->iccp) {
+/* if the ICCP is present, libjxl outputs sRGB */
+if (ctx->jxl_pixfmt.num_channels >= 3) {
+avctx->colorspace = AVCOL_SPC_RGB;
+avctx->color_primaries = AVCOL_PRI_BT709;
+}
+/* linear sRGB if float values, standard sRGB if int values */
+avctx->color_trc = ctx->jxl_pixfmt.data_type == JXL_TYPE_FLOAT 
+|| ctx->jxl_pixfmt.data_type == 
JXL_TYPE_FLOAT16 
+? AVCOL_TRC_LINEAR : 
AVCOL_TRC_IEC61966_2_1;
+} else {
+JxlColorEncoding jxl_encoding;
+jret = JxlDecoderGetColorAsEncodedProfile(ctx->decoder, 
&ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_DATA, &jxl_encoding);
+if (jret != JXL_DEC_SUCCESS) {
+av_log(avctx, AV_LOG_WARNING, "Unable to obtain color 
encoding from header\n");
+continue;
+}
+
+if (ctx->jxl_pixfmt.num_channels >= 3) {
+avctx->colorspace = AVCOL_SPC_RGB;
+switch (jxl_encoding.primaries) {
+case JXL_PRIMARIES_SRGB:
+avctx->color_primaries = AVCOL_PRI_BT709;
+break;
+case JXL_PRIMARIES_2100:
+avctx->color_primaries = AVCOL_PRI_BT2020;
+break;
+case JXL_PRIMARIES_P3:
+avctx->color_primaries = AVCOL_PRI_SMPTE431;
+break;
+case JXL_PRIMARIES_CUSTOM:
+av_log(avctx, AV_LOG_WARNING, "Custom primaries are 
unsupported\n");
+avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;
+break;
+default:
+av_log(avctx, AV_LOG_WARNING, "Unknown JXL color 
primaries: %d\n", jxl_encoding.primaries);
+avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;
+}
+}
+
+switch (jxl_encoding.transfer_function) {
+case JXL_TRANSFER_FUNCTION_709:
+avctx->color_trc = AVCOL_TRC_BT709;
+break;
+case JXL_TRANSFER_FUNCTION_LINEAR:
+avctx->color_trc = AVCOL_TRC_LINEAR;
+break;
+case JXL_TRANSFER_FUNCTION_SRGB:
+avctx->color_trc = AVCOL_TRC_IEC61966_2_1;
+break;
+case JXL_TRANSFER_FUNCTION_PQ:
+case JXL_TRANSFER_FUNCTION_DCI:
+avctx->color_trc = AVCOL_TRC_SMPTE428;
+break;
+case JXL_TRANSFER_FUNCTION_HLG:
+avctx->color_trc = AVCOL_TRC_ARIB_STD_B67;
+break;
+case JXL_TRANSFER_FUNCTION_GAMMA:
+if (jxl_encoding.gamma == 2.2) {
+avctx->color_trc = AVCOL_TRC_GAMMA22;
+} else if (jxl_encoding.gamma == 2.8) {
+avc

[FFmpeg-devel] [PATCH v2 2/2] avcodec/libjxlenc: properly read input colorspace

2022-05-03 Thread Leo Izen
Whether an ICC profile is present or not, the libjxl
encoder wrapper should now properly read colorspace tags
and forward them to libjxl appropriately, rather than just
assume sRGB as before. It will also print warnings when
colorimetric assumptions are made about the input data.
---
 libavcodec/libjxlenc.c | 124 ++---
 1 file changed, 93 insertions(+), 31 deletions(-)

diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c
index 8bebec6aeb..e176435529 100644
--- a/libavcodec/libjxlenc.c
+++ b/libavcodec/libjxlenc.c
@@ -117,7 +117,7 @@ static int libjxl_init_jxl_encoder(AVCodecContext *avctx)
 return AVERROR_EXTERNAL;
 }
 
-/* check for negative zero, our default */
+/* check for negative, our default */
 if (ctx->distance < 0.0) {
 /* use ffmpeg.c -q option if passed */
 if (avctx->flags & AV_CODEC_FLAG_QSCALE)
@@ -133,7 +133,8 @@ static int libjxl_init_jxl_encoder(AVCodecContext *avctx)
  */
 if (ctx->distance > 0.0 && ctx->distance < 0.01)
 ctx->distance = 0.01;
-if (JxlEncoderOptionsSetDistance(ctx->options, ctx->distance) != 
JXL_ENC_SUCCESS) {
+
+if (JxlEncoderSetFrameDistance(ctx->options, ctx->distance) != 
JXL_ENC_SUCCESS) {
 av_log(avctx, AV_LOG_ERROR, "Failed to set distance: %f\n", 
ctx->distance);
 return AVERROR_EXTERNAL;
 }
@@ -219,57 +220,118 @@ static int libjxl_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt, const AVFra
 info.num_color_channels = jxl_fmt.num_channels - info.num_extra_channels;
 info.bits_per_sample = av_get_bits_per_pixel(pix_desc) / 
jxl_fmt.num_channels;
 info.alpha_bits = (info.num_extra_channels > 0) * info.bits_per_sample;
+
 if (pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
 info.exponent_bits_per_sample = info.bits_per_sample > 16 ? 8 : 5;
 info.alpha_exponent_bits = info.alpha_bits ? 
info.exponent_bits_per_sample : 0;
 jxl_fmt.data_type = info.bits_per_sample > 16 ? JXL_TYPE_FLOAT : 
JXL_TYPE_FLOAT16;
-JxlColorEncodingSetToLinearSRGB(&jxl_color, info.num_color_channels == 
1);
 } else {
 info.exponent_bits_per_sample = 0;
 info.alpha_exponent_bits = 0;
 jxl_fmt.data_type = info.bits_per_sample <= 8 ? JXL_TYPE_UINT8 : 
JXL_TYPE_UINT16;
-JxlColorEncodingSetToSRGB(&jxl_color, info.num_color_channels == 1);
 }
 
-if (info.bits_per_sample > 16
-|| info.xsize > (1 << 18) || info.ysize > (1 << 18)
-|| (info.xsize << 4) * (info.ysize << 4) > (1 << 20)) {
-/*
- * must upgrade codestream to level 10, from level 5
- * the encoder will not do this automatically
- */
-if (JxlEncoderSetCodestreamLevel(ctx->encoder, 10) != JXL_ENC_SUCCESS) 
{
-av_log(avctx, AV_LOG_ERROR, "Could not upgrade JXL Codestream 
level.\n");
-return AVERROR_EXTERNAL;
-}
+/* JPEG XL format itself does not support partial range */
+if (avctx->color_range == AVCOL_RANGE_MPEG) {
+av_log(avctx, AV_LOG_ERROR, "This encoder does not support partial(tv) 
range, colors will be wrong!\n");
+} else if (avctx->color_range != AVCOL_RANGE_JPEG) {
+av_log(avctx, AV_LOG_WARNING, "Unknown color range, assuming full\n");
 }
 
-/* bitexact lossless requires there to be no XYB transform */
+ /* bitexact lossless requires there to be no XYB transform */
 info.uses_original_profile = ctx->distance == 0.0;
 
-sd = av_frame_get_side_data(frame, AV_FRAME_DATA_ICC_PROFILE);
-if (sd && sd->size && JxlEncoderSetICCProfile(ctx->encoder, sd->data, 
sd->size) != JXL_ENC_SUCCESS) {
-av_log(avctx, AV_LOG_WARNING, "Could not set ICC Profile\n");
-} else if (info.uses_original_profile) {
-/*
-* the color encoding is not used if uses_original_profile is false
-* this just works around a bug in libjxl 0.7.0 and lower
-*/
-if (JxlEncoderSetColorEncoding(ctx->encoder, &jxl_color) != 
JXL_ENC_SUCCESS) {
-av_log(avctx, AV_LOG_ERROR, "Failed to set JxlColorEncoding\n");
-return AVERROR_EXTERNAL;
-}
-}
-
 if (JxlEncoderSetBasicInfo(ctx->encoder, &info) != JXL_ENC_SUCCESS) {
 av_log(avctx, AV_LOG_ERROR, "Failed to set JxlBasicInfo\n");
 return AVERROR_EXTERNAL;
 }
 
+/* rendering intent doesn't matter here
+ * but libjxl will whine if we don't set it */
+jxl_color.rendering_intent = JXL_RENDERING_INTENT_RELATIVE;
+
+switch (avctx->color_trc) {
+case AVCOL_TRC_BT709:
+jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_709;
+break;
+case AVCOL_TRC_LINEAR:
+jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
+break;
+case AVCOL_TRC_IEC61966_2_1:
+jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB;
+break;
+case AVCOL_TRC_SMPTE428:
+jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_DC

Re: [FFmpeg-devel] [PATCH 00/12] I added text to bitmap subtitle conversion functionality!

2022-05-03 Thread Traian Coza
I already made the commits, tho, what do you suggest I do? Should I modify
the messages?
___
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] Need help submitting a patch

2022-05-03 Thread Leo Izen

On 5/3/22 12:17, Traian Coza wrote:

Thanks, I finally managed to submit my patch with your instructions.
However, I see that the "Less secure apps" setting will no longer be
available in a month. What do you plan on doing then? (I see you also use
gmail)


You'll have to enable two-factor authentication, and then use app passwords.

Also, please stop top-posting, you've been told about this. If your 
email client automatically top-posts then configure it to not do that, 
or move the text manually.


- Leo Izen (thebombzen)


___
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 00/12] I added text to bitmap subtitle conversion functionality!

2022-05-03 Thread Leo Izen

On 5/3/22 13:01, Traian Coza wrote:

I already made the commits, tho, what do you suggest I do? Should I modify
the messages?
___


You'll have to send another patchset. You append -v2 to your "git 
format-patch" command-line to generate a second version of the patch set.


Speaking of which, please read 
https://ffmpeg.org/developer.html#Contributing since it appears you have 
not. For example, you need to rebase your branch before submitting so 
the commits are squashed as necessary. Read up on "git rebase -i" or 
interactive rebase with git.


Leo Izen (thebombzen)


___
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 00/12] I added text to bitmap subtitle conversion functionality!

2022-05-03 Thread Traian Coza
Thanks, I'll do that. I did read a bit of Contributing, but not entirely.
And I read after writing the code, so there are some things I wasn't aware
of at the time of writing the code.
___
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 0/1] Text to Bitmap conversion implemented!

2022-05-03 Thread Traian Coza
I've modified my previous patch to fix a number of aesthetic issues.
First, I have only one commit now.
Second, I have read the Contributing section and I think I respected all the 
conventions mentionned there.
Third, I have rebased my commit to be up-to-date with the central repo.

Tell me if there's anything else I need to do.

Original email body:

I added the possibility of converting text-based subtitle tracks (such as 
subrip or ass) to bitmap-based subtitle tracks (such as dvd_subtitle).

I accomplished this by using libass, and basically using the code from 
vf_subtitles.c to render text subtitles and store the images in the AVSubtitle 
structure.

Of course, this functionality will only work when ffmpeg is configured with 
--enable-libass.

Traian Coza (1):
  fftools: Implemented text to bitmap subtitles!

 fftools/Makefile |   2 +
 fftools/ffmpeg.c |  35 -
 fftools/text_to_bitmap.c | 303 +++
 fftools/text_to_bitmap.h |  37 +
 libavcodec/avcodec.h |   9 ++
 5 files changed, 385 insertions(+), 1 deletion(-)
 create mode 100644 fftools/text_to_bitmap.c
 create mode 100644 fftools/text_to_bitmap.h

-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 1/1] fftools: Implemented text to bitmap subtitles!

2022-05-03 Thread Traian Coza
Used libass to render text-based subtitles in the AVSubtitle structure during 
transcoding.
This enables text to bitmap subtitle track conversion
This only works with --enable-libass. Otherwise, nothing should change.
Minor version bump required (field appended to AVCodecContext).
---
 fftools/Makefile |   2 +
 fftools/ffmpeg.c |  35 -
 fftools/text_to_bitmap.c | 303 +++
 fftools/text_to_bitmap.h |  37 +
 libavcodec/avcodec.h |   9 ++
 5 files changed, 385 insertions(+), 1 deletion(-)
 create mode 100644 fftools/text_to_bitmap.c
 create mode 100644 fftools/text_to_bitmap.h

diff --git a/fftools/Makefile b/fftools/Makefile
index 81ad6c4f4f..f9334a5622 100644
--- a/fftools/Makefile
+++ b/fftools/Makefile
@@ -15,6 +15,8 @@ OBJS-ffmpeg +=  \
 fftools/ffmpeg_mux.o\
 fftools/ffmpeg_opt.o\
 
+OBJS-ffmpeg-$(CONFIG_LIBASS) += fftools/text_to_bitmap.o
+
 define DOFFTOOL
 OBJS-$(1) += fftools/cmdutils.o fftools/opt_common.o fftools/$(1).o 
$(OBJS-$(1)-yes)
 $(1)$(PROGSSUF)_g$(EXESUF): $$(OBJS-$(1))
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index a85ed18b08..60d613e35f 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -71,6 +71,10 @@
 # include "libavfilter/buffersrc.h"
 # include "libavfilter/buffersink.h"
 
+#if CONFIG_LIBASS
+#include "fftools/text_to_bitmap.h"
+#endif
+
 #if HAVE_SYS_RESOURCE_H
 #include 
 #include 
@@ -2332,6 +2336,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket 
*pkt, int *got_output,
 int free_sub = 1;
 int i, ret = avcodec_decode_subtitle2(ist->dec_ctx,
   &subtitle, got_output, pkt);
+int rendered = 0;   // Variable for text to bitmap support
 
 check_decode_result(NULL, got_output, ret);
 
@@ -2391,6 +2396,18 @@ static int transcode_subtitles(InputStream *ist, 
AVPacket *pkt, int *got_output,
 || ost->enc->type != AVMEDIA_TYPE_SUBTITLE)
 continue;
 
+#if CONFIG_LIBASS
+// Support text to bitmap
+if (avcodec_descriptor_get(ost->enc_ctx->codec_id)->props & 
AV_CODEC_PROP_BITMAP_SUB)
+if (avcodec_descriptor_get(ist->dec_ctx->codec_id)->props & 
AV_CODEC_PROP_TEXT_SUB)
+if (!rendered) {// Make sure not to render twice
+avpriv_render_avsub_ass(ist->dec_ctx->ass_context, 
&subtitle);
+for (int r = 0; r < subtitle.num_rects; r++)
+subtitle.rects[r]->type = SUBTITLE_BITMAP;
+rendered = 1;
+}
+#endif
+
 do_subtitle_out(output_files[ost->file_index], ost, &subtitle);
 }
 
@@ -2685,6 +2702,9 @@ static int init_input_stream(int ist_index, char *error, 
int error_len)
  * audio, and video decoders such as cuvid or mediacodec */
 ist->dec_ctx->pkt_timebase = ist->st->time_base;
 
+// For text to bitmap rendering
+ist->dec_ctx->ass_context = NULL;
+
 if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0))
 av_dict_set(&ist->decoder_opts, "threads", "auto", 0);
 /* Attached pics are sparse, therefore we would not want to delay 
their decoding till EOF. */
@@ -3213,12 +3233,21 @@ static int init_output_stream(OutputStream *ost, 
AVFrame *frame,
 input_props = input_descriptor->props & 
(AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
 if (output_descriptor)
 output_props = output_descriptor->props & 
(AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
+#if CONFIG_LIBASS
+if (input_props == AV_CODEC_PROP_BITMAP_SUB && output_props == 
AV_CODEC_PROP_TEXT_SUB) {
+snprintf(error, error_len, "Subtitle encoding from bitmap to 
text currently not possible");
+return AVERROR_INVALIDDATA;
+}
+if (input_props == AV_CODEC_PROP_TEXT_SUB && output_props == 
AV_CODEC_PROP_BITMAP_SUB)
+avpriv_init_ass_context(ist, ost);
+#else
 if (input_props && output_props && input_props != output_props) {
 snprintf(error, error_len,
  "Subtitle encoding currently only possible from text 
to text "
- "or bitmap to bitmap");
+ "or bitmap to bitmap (configure with --enable-libass 
for text to bitmap support)");
 return AVERROR_INVALIDDATA;
 }
+#endif
 }
 
 if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 
0) {
@@ -4485,6 +4514,10 @@ static int transcode(void)
 ist = input_streams[i];
 if (ist->decoding_needed) {
 avcodec_close(ist->dec_ctx);
+#if CONFIG_LIBASS
+if (ist->dec_ctx->ass_context != NULL) // This really has to 
be done here, sorry
+avpriv_free_ass_context(ist->dec_ctx->ass_context);
+#endif
 if (ist->hwaccel_uninit)
 

Re: [FFmpeg-devel] PATCH - libmad MP3 decoding support

2022-05-03 Thread David Fletcher
Following today's posts about help with submitting patches I realised I
sent the libmad patch yesterday in the wrong format. Apologies, I was
not familiar with the git format patches.

Hopefully the attached version is now in the correct format against the
current master branch.

The bug report about why this exists is at the following link, including
a link to sample distorted audio from decoding an mp3 stream on ARMv4
hardware: https://trac.ffmpeg.org/ticket/9764

Best regards, David.
From c7012e7743d245bfc737bd921341a462cd5c843c Mon Sep 17 00:00:00 2001
From: David Fletcher 
Date: Tue, 3 May 2022 19:20:23 +0100
Subject: [PATCH] Patched to work with libmad MP3 decoding codec

Signed-off-by: David Fletcher 
---
 configure  |   4 +
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/codec_id.h  |   1 +
 libavcodec/libmaddec.c | 181 +
 5 files changed, 188 insertions(+)
 create mode 100644 libavcodec/libmaddec.c

diff --git a/configure b/configure
index 196873c4aa..d5f5b79614 100755
--- a/configure
+++ b/configure
@@ -245,6 +245,7 @@ External library support:
   --enable-libklvanc   enable Kernel Labs VANC processing [no]
   --enable-libkvazaar  enable HEVC encoding via libkvazaar [no]
   --enable-liblensfun  enable lensfun lens correction [no]
+  --enable-libmad  enable MP3 decoding via libmad [no]
   --enable-libmodplug  enable ModPlug via libmodplug [no]
   --enable-libmp3lame  enable MP3 encoding via libmp3lame [no]
   --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
@@ -1775,6 +1776,7 @@ EXTERNAL_LIBRARY_GPL_LIST="
 frei0r
 libcdio
 libdavs2
+libmad
 librubberband
 libvidstab
 libx264
@@ -3339,6 +3341,7 @@ libjxl_decoder_deps="libjxl libjxl_threads"
 libjxl_encoder_deps="libjxl libjxl_threads"
 libkvazaar_encoder_deps="libkvazaar"
 libmodplug_demuxer_deps="libmodplug"
+libmad_decoder_deps="libmad"
 libmp3lame_encoder_deps="libmp3lame"
 libmp3lame_encoder_select="audio_frame_queue mpegaudioheader"
 libopencore_amrnb_decoder_deps="libopencore_amrnb"
@@ -6572,6 +6575,7 @@ if enabled libmfx; then
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug libmodplug/modplug.h ModPlug_Load
+enabled libmad&& require libmad "mad.h" mad_decoder_init -lmad
 enabled libmp3lame&& require "libmp3lame >= 3.98.3" lame/lame.h lame_set_VBR_quality -lmp3lame $libm_extralibs
 enabled libmysofa && { check_pkg_config libmysofa libmysofa mysofa.h mysofa_neighborhood_init_withstepdefine ||
require libmysofa mysofa.h mysofa_neighborhood_init_withstepdefine -lmysofa $zlib_extralibs; }
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index cfaa6f196a..1e434222d9 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1065,6 +1065,7 @@ OBJS-$(CONFIG_LIBILBC_ENCODER)+= libilbc.o
 OBJS-$(CONFIG_LIBJXL_DECODER) += libjxldec.o libjxl.o
 OBJS-$(CONFIG_LIBJXL_ENCODER) += libjxlenc.o libjxl.o
 OBJS-$(CONFIG_LIBKVAZAAR_ENCODER) += libkvazaar.o
+OBJS-$(CONFIG_LIBMAD_DECODER) += libmaddec.o
 OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER)  += libopencore-amr.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_ENCODER)  += libopencore-amr.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index c47133aa18..e3df6178c8 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -744,6 +744,7 @@ extern const FFCodec ff_libcodec2_decoder;
 extern const FFCodec ff_libdav1d_decoder;
 extern const FFCodec ff_libdavs2_decoder;
 extern const FFCodec ff_libfdk_aac_encoder;
+extern const AVCodec ff_libmad_decoder;
 extern const FFCodec ff_libfdk_aac_decoder;
 extern const FFCodec ff_libgsm_encoder;
 extern const FFCodec ff_libgsm_decoder;
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index 8b317fa121..be70f4a71c 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -519,6 +519,7 @@ enum AVCodecID {
 AV_CODEC_ID_FASTAUDIO,
 AV_CODEC_ID_MSNSIREN,
 AV_CODEC_ID_DFPWM,
+AV_CODEC_ID_LIBMAD,
 
 /* subtitle codecs */
 AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing at the start of subtitle codecs.
diff --git a/libavcodec/libmaddec.c b/libavcodec/libmaddec.c
new file mode 100644
index 00..7082c53f4d
--- /dev/null
+++ b/libavcodec/libmaddec.c
@@ -0,0 +1,181 @@
+/*
+ * MP3 decoder using libmad
+ * Copyright (c) 2022 David Fletcher
+ *
+ * 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; with

Re: [FFmpeg-devel] PATCH - wolfSSL TLS support

2022-05-03 Thread David Fletcher
Following today's posts about help with submitting patches I realised I
sent the patch yesterday to add wolfSSL as a TLS backend in the wrong
format. Apologies, I was not familiar with the git format patches.

Hopefully the attached version is now in the correct format against the
current master branch.

Best regards, David.
From 3fc91e85b31ce0e5422f6ffe39d7d2287bce5939 Mon Sep 17 00:00:00 2001
From: David Fletcher 
Date: Tue, 3 May 2022 19:23:50 +0100
Subject: [PATCH] Patched to work with wolfSSL as a new TLS backend

Signed-off-by: David Fletcher 
---
 configure |  12 +-
 libavformat/Makefile  |   1 +
 libavformat/network.c |   6 +
 libavformat/tls.h |   3 +
 libavformat/tls_wolfssl.c | 241 ++
 5 files changed, 259 insertions(+), 4 deletions(-)
 create mode 100644 libavformat/tls_wolfssl.c

diff --git a/configure b/configure
index 196873c4aa..b20d94bfbd 100755
--- a/configure
+++ b/configure
@@ -211,7 +211,7 @@ External library support:
   --enable-gmp enable gmp, needed for rtmp(t)e support
if openssl or librtmp is not used [no]
   --enable-gnutls  enable gnutls, needed for https support
-   if openssl, libtls or mbedtls is not used [no]
+   if openssl, libtls, wolfssl or mbedtls is not used [no]
   --disable-iconv  disable iconv [autodetect]
   --enable-jni enable JNI support [no]
   --enable-ladspa  enable LADSPA audio filtering [no]
@@ -278,7 +278,7 @@ External library support:
   --enable-libtesseractenable Tesseract, needed for ocr filter [no]
   --enable-libtheora   enable Theora encoding via libtheora [no]
   --enable-libtls  enable LibreSSL (via libtls), needed for https support
-   if openssl, gnutls or mbedtls is not used [no]
+   if openssl, gnutls, wolfssl or mbedtls is not used [no]
   --enable-libtwolame  enable MP2 encoding via libtwolame [no]
   --enable-libuavs3d   enable AVS3 decoding via libuavs3d [no]
   --enable-libv4l2 enable libv4l2/v4l-utils [no]
@@ -289,6 +289,8 @@ External library support:
native implementation exists [no]
   --enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
   --enable-libwebp enable WebP encoding via libwebp [no]
+  --enable-wolfssl enable WolfSSL), needed for https support
+   if openssl, gnutls, libtls or mbedtls is not used [no]
   --enable-libx264 enable H.264 encoding via x264 [no]
   --enable-libx265 enable HEVC encoding via x265 [no]
   --enable-libxavs enable AVS encoding via xavs [no]
@@ -317,7 +319,7 @@ External library support:
   --enable-opencl  enable OpenCL processing [no]
   --enable-opengl  enable OpenGL rendering [no]
   --enable-openssl enable openssl, needed for https support
-   if gnutls, libtls or mbedtls is not used [no]
+   if gnutls, libtls, wolfssl or mbedtls is not used [no]
   --enable-pocketsphinxenable PocketSphinx, needed for asr filter [no]
   --disable-sndio  disable sndio support [autodetect]
   --disable-schannel   disable SChannel SSP, needed for TLS support on
@@ -1885,6 +1887,7 @@ EXTERNAL_LIBRARY_LIST="
 openssl
 pocketsphinx
 vapoursynth
+wolfssl
 "
 
 HWACCEL_AUTODETECT_LIBRARY_LIST="
@@ -3581,7 +3584,7 @@ sctp_protocol_select="network"
 securetransport_conflict="openssl gnutls libtls mbedtls"
 srtp_protocol_select="rtp_protocol srtp"
 tcp_protocol_select="network"
-tls_protocol_deps_any="gnutls openssl schannel securetransport libtls mbedtls"
+tls_protocol_deps_any="gnutls openssl schannel securetransport libtls mbedtls wolfssl"
 tls_protocol_select="tcp_protocol"
 udp_protocol_select="network"
 udplite_protocol_select="network"
@@ -6512,6 +6515,7 @@ enabled decklink  && { require_headers DeckLinkAPI.h &&
 enabled frei0r&& require_headers "frei0r.h"
 enabled gmp   && require gmp gmp.h mpz_export -lgmp
 enabled gnutls&& require_pkg_config gnutls gnutls gnutls/gnutls.h gnutls_global_init
+enabled wolfssl   && require_pkg_config wolfssl wolfssl wolfssl/ssl.h wolfSSL_library_init
 enabled jni   && { [ $target_os = "android" ] && check_headers jni.h && enabled pthreads || die "ERROR: jni not found"; }
 enabled ladspa&& require_headers "ladspa.h dlfcn.h"
 enabled lcms2 && require_pkg_config lcms2 "lcms2 >= 2.13" lcms2.h cmsCreateContext
diff --git a/libavformat/Makefile b/libavformat/Makefile
index f16634a418..6e95bb1eee 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -667,6 +667,7 @@ TLS-OBJS-$(CONFIG_GNUTLS)+= tls_gnutls.o
 TLS-OBJS-$(CONFIG_LIBTLS)+= tls_libtls.o
 TLS-OBJS-$(CONFIG_MBEDTLS)   +

Re: [FFmpeg-devel] [PATCH 1/3] avutils/hwcontext: add derive-device function which searches for existing devices in both directions

2022-05-03 Thread Mark Thompson

On 03/05/2022 01:11, Soft Works wrote:

-Original Message-
From: ffmpeg-devel  On Behalf Of Mark
Thompson
Sent: Tuesday, May 3, 2022 1:57 AM
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 1/3] avutils/hwcontext: add derive-
device function which searches for existing devices in both directions

On 02/05/2022 23:59, Soft Works wrote:

-Original Message-
From: ffmpeg-devel  On Behalf Of

Mark

Thompson
Sent: Tuesday, May 3, 2022 12:12 AM
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 1/3] avutils/hwcontext: add

derive-

device function which searches for existing devices in both

directions


On 02/05/2022 09:14, Soft Works wrote:

-Original Message-
From: ffmpeg-devel  On Behalf Of

Mark

Thompson
Sent: Monday, May 2, 2022 12:01 AM
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 1/3] avutils/hwcontext: add

derive-

device function which searches for existing devices in both

directions


[..]


* The thread-safety properties of the hwcontext API have been

lost

-

you can no longer operate on devices independently across

threads

(insofar as the underlying API allows that).
   Maybe there is an argument that derivation is something

which

should happen early on and therefore documenting it as thread-

unsafe

is ok, but when hwupload/hwmap can use it inside filtergraphs

that

just isn't going to happen (and will be violated in the FFmpeg

utility

if filters get threaded, as is being worked on).


From my understanding there will be a single separate thread

which

handles all filtergraph operations.
I don't think it would even be possible (without massive

changes)

to arbitrate filter processing in parallel.
But even if this would be implemented: the filtergraph setup

(init,

uninit, query_formats, etc.) would surely happen on a single

thread.


The ffmpeg utility creates filtergraphs dynamically when the

first

frame is available from their inputs, so I don't see why you

wouldn't

allow multiple of them to be created in parallel in that case.

If you create all devices at the beginning and then give

references

to

them to the various filters which need them (so never manipulate
devices dynamically within the graph) then it would be ok, but I

think

you've already rejected that approach.


Please let's not break out of the scope of this patchset.
This patchset is not about re-doing device derivation. The only
small change that it does is that it returns an existing device
instead of creating a new one when such device already exists
in the same(!) chain.

The change it makes has really nothing to do with threading or
anything around it.


The change makes existing thread-safe hwcontext APIs unsafe.  That

is

definitely not "nothing to do with threading", and has to be

resolved

since they can currently be called from contexts which expect

thread-

safety (such as making filtergraphs).


As I said, I'm not aware that filtergraph creation would be a

context

which requires thread-safety, even when considering frames which get
pushed into a filtergraph (like from a decoder).


User programs can do whatever they like within the API constraints.


Could you please show a command line which causes a situation where
device_derive is being called from multiple threads?


Given that the ffmpeg utility is currently entirely single-threaded,
this will only happen once the intended plans for adding threading to
it are complete.


As mentioned, I don't think that would be possible easily, and from
what I have understood, the plan is to have separate threads for decoding,
encoding and filtering but not multiple threads for filtering.


As the summary in 
 
states, the intent is a separate thread for each instance of those things, including 
filtergraphs.


With that, it will be true for something which makes two filtergraphs
and uses derivation in both of them.  For example:, this currently
makes two independent VAAPI devices, but equally could reuse the same
device:

# ffmpeg -y -f kmsgrab -i /dev/dri/card0 -vf
hwmap=derive_device=vaapi,scale_vaapi=format=nv12 -c:v h264_vaapi
out1.mp4 -vf
hwmap=derive_device=vaapi,scale_vaapi=w=1280:h=720:format=nv12 -c:v
h264_vaapi out2.mp4


Well, multi-threading is not an issue right now, and I don't expect it
to be then.

But on a more practical take: what do you want me to do?

Guard that function with a lock? I can do this, no problem.


I'd like it to be designed in a way that avoids this sort of problem, as all 
the existing functions are.


But
none of any of the device control function does any synchronization,
so why would exactly this - and only this function need synchronization?


The derived_devices field is modified post-creation, which gives you data races 
if there is no other synchronisation.

(Consider simultaneous derivation calls: current

Re: [FFmpeg-devel] [PATCH] hwcontext: Skip derivation checking for an existing device if options are set

2022-05-03 Thread Mark Thompson

On 03/05/2022 01:14, Soft Works wrote:

-Original Message-
From: ffmpeg-devel  On Behalf Of Mark
Thompson
Sent: Tuesday, May 3, 2022 2:09 AM
To: FFmpeg development discussions and patches 
Subject: [FFmpeg-devel] [PATCH] hwcontext: Skip derivation checking
for an existing device if options are set

If options are set then the user definitely intends to create a new
device, so we shouldn't attempt to return an existing one.
---
   libavutil/hwcontext.c | 26 --
   1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index ab9ad3703e..c4e01e0e78 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -653,18 +653,24 @@ int
av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr,
   AVHWDeviceContext *dst_ctx, *tmp_ctx;
   int ret = 0;

-tmp_ref = src_ref;
-while (tmp_ref) {
-tmp_ctx = (AVHWDeviceContext*)tmp_ref->data;
-if (tmp_ctx->type == type) {
-dst_ref = av_buffer_ref(tmp_ref);
-if (!dst_ref) {
-ret = AVERROR(ENOMEM);
-goto fail;
+// If we were derived (possibly transitively) from a device of
the
+// target type then we want to return that original device,
unless
+// options are set in which case we can skip this check because
it
+// is definitely intended to create a new device.
+if (!options) {
+tmp_ref = src_ref;
+while (tmp_ref) {
+tmp_ctx = (AVHWDeviceContext*)tmp_ref->data;
+if (tmp_ctx->type == type) {
+dst_ref = av_buffer_ref(tmp_ref);
+if (!dst_ref) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+goto done;
   }
-goto done;
+tmp_ref = tmp_ctx->internal->source_device;
   }
-tmp_ref = tmp_ctx->internal->source_device;
   }

   dst_ref = av_hwdevice_ctx_alloc(type);
--


This doesn't implement the matching of device parameters, which you
were talking about:

You said that when deriving a device, an existing device should
only be returned when the parameters are the same.

This patch is doing something quite different.


Why would that be useful in the current design?  As the documentation on create_derived 
states, it has two independent uses - this is the "retrieve source device" 
case, and for that it does not make sense to set the options argument because no new 
device is being created.

I will clarify the doxy on _opts.

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

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


Re: [FFmpeg-devel] [PATCH 1/3] avutils/hwcontext: add derive-device function which searches for existing devices in both directions

2022-05-03 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of Mark
> Thompson
> Sent: Tuesday, May 3, 2022 10:23 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH 1/3] avutils/hwcontext: add derive-
> device function which searches for existing devices in both directions
> 
> On 03/05/2022 01:11, Soft Works wrote:
> >> -Original Message-
> >> From: ffmpeg-devel  On Behalf Of
> Mark
> >> Thompson
> >> Sent: Tuesday, May 3, 2022 1:57 AM
> >> To: ffmpeg-devel@ffmpeg.org
> >> Subject: Re: [FFmpeg-devel] [PATCH 1/3] avutils/hwcontext: add
> derive-
> >> device function which searches for existing devices in both
> directions
> >>
> >> On 02/05/2022 23:59, Soft Works wrote:
>  -Original Message-
>  From: ffmpeg-devel  On Behalf Of
> >> Mark
>  Thompson
>  Sent: Tuesday, May 3, 2022 12:12 AM
>  To: ffmpeg-devel@ffmpeg.org
>  Subject: Re: [FFmpeg-devel] [PATCH 1/3] avutils/hwcontext: add
> >> derive-
>  device function which searches for existing devices in both
> >> directions
> 
>  On 02/05/2022 09:14, Soft Works wrote:
> >> -Original Message-
> >> From: ffmpeg-devel  On Behalf
> Of
>  Mark
> >> Thompson
> >> Sent: Monday, May 2, 2022 12:01 AM
> >> To: ffmpeg-devel@ffmpeg.org
> >> Subject: Re: [FFmpeg-devel] [PATCH 1/3] avutils/hwcontext: add
>  derive-
> >> device function which searches for existing devices in both
>  directions
> >
> > [..]
> >
>  * The thread-safety properties of the hwcontext API have been
>  lost
> >> -
>  you can no longer operate on devices independently across
> >> threads
>  (insofar as the underlying API allows that).
> Maybe there is an argument that derivation is
> something
>  which
>  should happen early on and therefore documenting it as
> thread-
> >> unsafe
>  is ok, but when hwupload/hwmap can use it inside filtergraphs
>  that
>  just isn't going to happen (and will be violated in the
> FFmpeg
> >> utility
>  if filters get threaded, as is being worked on).
> >>>
> >>> From my understanding there will be a single separate
> thread
>  which
> >>> handles all filtergraph operations.
> >>> I don't think it would even be possible (without massive
> >> changes)
> >>> to arbitrate filter processing in parallel.
> >>> But even if this would be implemented: the filtergraph setup
>  (init,
> >>> uninit, query_formats, etc.) would surely happen on a single
>  thread.
> >>
> >> The ffmpeg utility creates filtergraphs dynamically when the
> >> first
> >> frame is available from their inputs, so I don't see why you
>  wouldn't
> >> allow multiple of them to be created in parallel in that case.
> >>
> >> If you create all devices at the beginning and then give
> >> references
>  to
> >> them to the various filters which need them (so never
> manipulate
> >> devices dynamically within the graph) then it would be ok, but
> I
>  think
> >> you've already rejected that approach.
> >
> > Please let's not break out of the scope of this patchset.
> > This patchset is not about re-doing device derivation. The only
> > small change that it does is that it returns an existing device
> > instead of creating a new one when such device already exists
> > in the same(!) chain.
> >
> > The change it makes has really nothing to do with threading or
> > anything around it.
> 
>  The change makes existing thread-safe hwcontext APIs unsafe.
> That
> >> is
>  definitely not "nothing to do with threading", and has to be
> >> resolved
>  since they can currently be called from contexts which expect
> >> thread-
>  safety (such as making filtergraphs).
> >>>
> >>> As I said, I'm not aware that filtergraph creation would be a
> >> context
> >>> which requires thread-safety, even when considering frames which
> get
> >>> pushed into a filtergraph (like from a decoder).
> >>
> >> User programs can do whatever they like within the API constraints.
> >>
> >>> Could you please show a command line which causes a situation
> where
> >>> device_derive is being called from multiple threads?
> >>
> >> Given that the ffmpeg utility is currently entirely single-
> threaded,
> >> this will only happen once the intended plans for adding threading
> to
> >> it are complete.
> >
> > As mentioned, I don't think that would be possible easily, and from
> > what I have understood, the plan is to have separate threads for
> decoding,
> > encoding and filtering but not multiple threads for filtering.
> 
> As the summary in  devel/2022-April/294940.html> states, the intent is a separate thread
> for each instance of those things, including filtergraphs.
> 
> >> With that, it will be true for something which makes two

Re: [FFmpeg-devel] [PATCH] hwcontext: Skip derivation checking for an existing device if options are set

2022-05-03 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of Mark
> Thompson
> Sent: Tuesday, May 3, 2022 10:32 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] hwcontext: Skip derivation
> checking for an existing device if options are set
> 
> On 03/05/2022 01:14, Soft Works wrote:
> >> -Original Message-
> >> From: ffmpeg-devel  On Behalf Of
> Mark
> >> Thompson
> >> Sent: Tuesday, May 3, 2022 2:09 AM
> >> To: FFmpeg development discussions and patches  >> de...@ffmpeg.org>
> >> Subject: [FFmpeg-devel] [PATCH] hwcontext: Skip derivation checking
> >> for an existing device if options are set
> >>
> >> If options are set then the user definitely intends to create a new
> >> device, so we shouldn't attempt to return an existing one.
> >> ---
> >>libavutil/hwcontext.c | 26 --
> >>1 file changed, 16 insertions(+), 10 deletions(-)
> >>
> >> diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
> >> index ab9ad3703e..c4e01e0e78 100644
> >> --- a/libavutil/hwcontext.c
> >> +++ b/libavutil/hwcontext.c
> >> @@ -653,18 +653,24 @@ int
> >> av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr,
> >>AVHWDeviceContext *dst_ctx, *tmp_ctx;
> >>int ret = 0;
> >>
> >> -tmp_ref = src_ref;
> >> -while (tmp_ref) {
> >> -tmp_ctx = (AVHWDeviceContext*)tmp_ref->data;
> >> -if (tmp_ctx->type == type) {
> >> -dst_ref = av_buffer_ref(tmp_ref);
> >> -if (!dst_ref) {
> >> -ret = AVERROR(ENOMEM);
> >> -goto fail;
> >> +// If we were derived (possibly transitively) from a device of
> >> the
> >> +// target type then we want to return that original device,
> >> unless
> >> +// options are set in which case we can skip this check
> because
> >> it
> >> +// is definitely intended to create a new device.
> >> +if (!options) {
> >> +tmp_ref = src_ref;
> >> +while (tmp_ref) {
> >> +tmp_ctx = (AVHWDeviceContext*)tmp_ref->data;
> >> +if (tmp_ctx->type == type) {
> >> +dst_ref = av_buffer_ref(tmp_ref);
> >> +if (!dst_ref) {
> >> +ret = AVERROR(ENOMEM);
> >> +goto fail;
> >> +}
> >> +goto done;
> >>}
> >> -goto done;
> >> +tmp_ref = tmp_ctx->internal->source_device;
> >>}
> >> -tmp_ref = tmp_ctx->internal->source_device;
> >>}
> >>
> >>dst_ref = av_hwdevice_ctx_alloc(type);
> >> --
> >
> > This doesn't implement the matching of device parameters, which you
> > were talking about:
> >
> > You said that when deriving a device, an existing device should
> > only be returned when the parameters are the same.
> >
> > This patch is doing something quite different.
> 
> Why would that be useful in the current design?  As the documentation
> on create_derived states, it has two independent uses - this is the
> "retrieve source device" case, and for that it does not make sense to
> set the options argument because no new device is being created.


I thought you were saying that when deriving a device with extensionParam1
an existing device should be returned when it was also derived with
extensionParam1 but when there's no existing device of the requested
type _and_ matching parameters, then a new derived device should be
created.

Maybe I understood wrong?


Kind regards,
softworkz





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

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


Re: [FFmpeg-devel] [RFC] QSV: Introduce min Compile-SDK Version and check for Runtime-Versions instead

2022-05-03 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of Soft
> Works
> Sent: Wednesday, January 12, 2022 4:37 AM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [RFC] QSV: Introduce min Compile-SDK
> Version and check for Runtime-Versions instead

[..]

> > > Question
> > >
> > > Having both - run-time and compile-time checks all over the code
> is adding
> > > a lot of complexity and makes it difficult to maintain and work
> with.
> > >
> > > Hence, I'm wondering whether we couldn't/shouldn't introduce a
> minimum
> > > MSDK compile-time version, for example 1.22, or even later?
> > >
> > > This would allow simplification of the QSV code in many places
> where run-
> > time
> > > version checks are actually needed instead.
> > >
> > > Over time, there have been better and worse MSDK versions, and
> there
> > > should still be enough room for choosing, but I don't think
> there's any
> > > reason why somebody would still want to compile against some
> really old
> > > (e.g. < 1.22) MSDK version.
> > >
> > > Please share your thoughts on this subject..
> >
> > I agree we may add a requirement for the minimal compiling version
> in
> > configure,
> > version 1.28 was released 3 years ago, how about using this version
> as the
> > minimal compiling version ?
> 
> I'm fine with 1.28!


Are there any objections towards setting 1.28 as a minimum requirement 
for the MSDK (QSV) compile-time version?

sw



___
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] avformat/movenc: Add support for AVIF muxing

2022-05-03 Thread James Zern
On Mon, May 2, 2022 at 2:35 PM Vignesh Venkatasubramanian
 wrote:
>
> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
>
> AVIF Specification: https://aomediacodec.github.io/av1-avif
>
> Sample usage for still image:
> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
>
> Sample usage for animated AVIF image:
> ffmpeg -i video.mp4 animated.avif
>
> We can re-use any of the AV1 encoding options that will make
> sense for image encoding (like bitrate, tiles, encoding speed,
> etc).
>
> The files generated by this muxer has been verified to be valid
> AVIF files by the following:
> 1) Displays on Chrome (both still and animated images).
> 2) Displays on Firefox (only still images, firefox does not support
>animated AVIF yet).
> 3) Verified to be valid by Compliance Warden:
>https://github.com/gpac/ComplianceWarden
>
> Fixes the encoder/muxer part of Trac Ticket #7621
>
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  configure|   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/movenc.c | 335 ---
>  libavformat/movenc.h |   5 +
>  4 files changed, 317 insertions(+), 25 deletions(-)
>

lgtm
___
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 00/12] I added text to bitmap subtitle conversion functionality!

2022-05-03 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of Soft
> Works
> Sent: Tuesday, May 3, 2022 6:27 PM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Cc: Traian Coza 
> Subject: Re: [FFmpeg-devel] [PATCH 00/12] I added text to bitmap
> subtitle conversion functionality!
> 
> 
> 
> > -Original Message-
> > From: ffmpeg-devel  On Behalf Of
> > Traian Coza
> > Sent: Tuesday, May 3, 2022 6:13 PM
> > To: ffmpeg-devel@ffmpeg.org
> > Cc: Traian Coza 
> > Subject: [FFmpeg-devel] [PATCH 00/12] I added text to bitmap
> subtitle
> > conversion functionality!
> >
> > I added the possibility of converting text-based subtitle tracks
> (such
> > as subrip or ass) to bitmap-based subtitle tracks (such as
> > dvd_subtitle).
> >
> > I accomplished this by using libass, and basically using the code
> from
> > vf_subtitles.c to render text subtitles and store the images in the
> > AVSubtitle structure.
> 
> Have you seen this: https://github.com/ffstaging/FFmpeg/pull/18

With the subtitle filtering patchset, you could do the same with 
a fraction of code and (probably) a single code file.

You can use the textsub2video filter as a starting point to
create a textsub2graphicsub filter.

What you see there will look all familiar to you. The textsub2video
filter uses libass as well.
You'll need to change the output media type to subtitle and the
format to graphic subtitles and add AvSubtitleArea items for 
each bitmap in a frame (similar to AVSubtitleRect).

Your code will magically shrink.. :-)

Kind regards,
softworkz







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

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


Re: [FFmpeg-devel] PATCH - libmad MP3 decoding support

2022-05-03 Thread Andreas Rheinhardt
David Fletcher:
> Following today's posts about help with submitting patches I realised I
> sent the libmad patch yesterday in the wrong format. Apologies, I was
> not familiar with the git format patches.
> 
> Hopefully the attached version is now in the correct format against the
> current master branch.
> 
> The bug report about why this exists is at the following link, including
> a link to sample distorted audio from decoding an mp3 stream on ARMv4
> hardware: https://trac.ffmpeg.org/ticket/9764
> 
> Best regards, David.
> 

> 
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index c47133aa18..e3df6178c8 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -744,6 +744,7 @@ extern const FFCodec ff_libcodec2_decoder;
>  extern const FFCodec ff_libdav1d_decoder;
>  extern const FFCodec ff_libdavs2_decoder;
>  extern const FFCodec ff_libfdk_aac_encoder;
> +extern const AVCodec ff_libmad_decoder;
>  extern const FFCodec ff_libfdk_aac_decoder;
>  extern const FFCodec ff_libgsm_encoder;
>  extern const FFCodec ff_libgsm_decoder;

This should look weird to you.

> 
> diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
> index 8b317fa121..be70f4a71c 100644
> --- a/libavcodec/codec_id.h
> +++ b/libavcodec/codec_id.h
> @@ -519,6 +519,7 @@ enum AVCodecID {
>  AV_CODEC_ID_FASTAUDIO,
>  AV_CODEC_ID_MSNSIREN,
>  AV_CODEC_ID_DFPWM,
> +AV_CODEC_ID_LIBMAD,
>  
>  /* subtitle codecs */
>  AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing 
> at the start of subtitle codecs.

This makes no sense: Your decoder is still expected to decode MP3 and
not a new, previously unsupported format.

> diff --git a/libavcodec/libmaddec.c b/libavcodec/libmaddec.c
> new file mode 100644
> index 00..7082c53f4d
> --- /dev/null
> +++ b/libavcodec/libmaddec.c
> @@ -0,0 +1,181 @@
> +/*
> + * MP3 decoder using libmad
> + * Copyright (c) 2022 David Fletcher
> + *
> + * 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 
> +
> +#include "libavutil/channel_layout.h"
> +#include "libavutil/common.h"
> +#include "avcodec.h"
> +#include "internal.h"
> +#include "decode.h"
> +
> +#define MAD_BUFSIZE (32 * 1024)
> +#define MIN(a, b) ((a) < (b) ? (a) : (b))
> +
> +typedef struct libmad_context {
> +uint8_t input_buffer[MAD_BUFSIZE+MAD_BUFFER_GUARD];
> +struct mad_synth  synth; 
> +struct mad_stream stream;
> +struct mad_frame  frame;
> +struct mad_header header;
> +int got_header;
> +}libmad_context; 
> +
> +/* utility to scale and round samples to 16 bits */
> +static inline signed int mad_scale(mad_fixed_t sample)
> +{
> + /* round */
> + sample += (1L << (MAD_F_FRACBITS - 16));
> + 
> + /* clip */
> + if (sample >= MAD_F_ONE)
> + sample = MAD_F_ONE - 1;
> + else if (sample < -MAD_F_ONE)
> + sample = -MAD_F_ONE;
> +
> + /* quantize */
> + return sample >> (MAD_F_FRACBITS + 1 - 16);
> +}
> +
> +static av_cold int libmad_decode_init(AVCodecContext *avc)
> +{
> + libmad_context *mad = avc->priv_data;
> +
> + mad_synth_init  (&mad->synth);
> + mad_stream_init (&mad->stream);
> + mad_frame_init  (&mad->frame);
> + mad->got_header = 0;
> +
> + return 0;
> +}
> +
> +static av_cold int libmad_decode_close(AVCodecContext *avc)
> +{
> + libmad_context *mad = avc->priv_data;
> +
> + mad_synth_finish(&mad->synth);
> + mad_frame_finish(&mad->frame);
> + mad_stream_finish(&mad->stream);
> +
> + mad = NULL;

This is pointless as the lifetime of this pointer ends with returning
from this function anyway.

> +
> + return 0;
> +}
> +
> +static int libmad_decode_frame(AVCodecContext *avc, void *data,
> +  int *got_frame_ptr, AVPacket *pkt)
> +{
> + AVFrame *frame = data;
> + libmad_context *mad = avc->priv_data;
> + struct mad_pcm *pcm;
> + mad_fixed_t const *left_ch;
> + mad_fixed_t const *right_ch;
> + int16_t *output;
> + int nsamples;
> + int nchannels;
> + size_t bytes_read = 0;
> + size_t remaining = 0;
> + 
> + if (!avc)
> +  return 0;

A codec can presume the AVCodecContext to not be NULL.

> + 
> 

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-05-03 Thread zhilizhao(赵志立)


> On May 3, 2022, at 5:35 AM, Vignesh Venkatasubramanian 
>  wrote:
> 
> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> 
> AVIF Specification: https://aomediacodec.github.io/av1-avif
> 
> Sample usage for still image:
> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> 
> Sample usage for animated AVIF image:
> ffmpeg -i video.mp4 animated.avif
> 
> We can re-use any of the AV1 encoding options that will make
> sense for image encoding (like bitrate, tiles, encoding speed,
> etc).
> 
> The files generated by this muxer has been verified to be valid
> AVIF files by the following:
> 1) Displays on Chrome (both still and animated images).
> 2) Displays on Firefox (only still images, firefox does not support
>   animated AVIF yet).
> 3) Verified to be valid by Compliance Warden:
>   https://github.com/gpac/ComplianceWarden
> 
> Fixes the encoder/muxer part of Trac Ticket #7621
> 
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
> configure|   1 +
> libavformat/allformats.c |   1 +
> libavformat/movenc.c | 335 ---
> libavformat/movenc.h |   5 +
> 4 files changed, 317 insertions(+), 25 deletions(-)
> 
> 

[…]

> static int mov_write_video_tag(AVFormatContext *s, AVIOContext *pb, 
> MOVMuxContext *mov, MOVTrack *track)
> {
> int ret = AVERROR_BUG;
> @@ -2156,6 +2176,8 @@ static int mov_write_video_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVMuxContex
> avio_wb32(pb, 0); /* size */
> if (mov->encryption_scheme != MOV_ENC_NONE) {
> ffio_wfourcc(pb, "encv");
> +} else if (track->mode == MODE_AVIF) {
> +ffio_wfourcc(pb, "av01");

Can the ‘else’ path handle the case?

> } else {
> avio_wl32(pb, track->tag); // store it byteswapped
> }
> @@ -2272,7 +2294,7 @@ static int mov_write_video_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVMuxContex
> else
> av_log(mov->fc, AV_LOG_WARNING, "Not writing 'gama' atom. Format 
> is not MOV.\n");
> }
> -if (track->mode == MODE_MOV || track->mode == MODE_MP4) {
> +if (track->mode == MODE_MOV || track->mode == MODE_MP4 || track->mode == 
> MODE_AVIF) {
> int has_color_info = track->par->color_primaries != 
> AVCOL_PRI_UNSPECIFIED &&
>  track->par->color_trc != AVCOL_TRC_UNSPECIFIED &&
>  track->par->color_space != AVCOL_SPC_UNSPECIFIED;
> @@ -2324,6 +2346,9 @@ static int mov_write_video_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVMuxContex
> if (avid)
> avio_wb32(pb, 0);
> 
> +if (track->mode == MODE_AVIF)
> +mov_write_ccst_tag(pb);
> +
> return update_size(pb, pos);
> }
> 
> @@ -2825,7 +2850,10 @@ static int mov_write_hdlr_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVTrack *tra
> 
> if (track) {
> hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0";
> -if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) {
> +if (track->mode == MODE_AVIF) {
> +hdlr_type = "pict";
> +descr = "PictureHandler";
> +} else if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) {

I prefer put check inside the ‘if (track->par->codec_type == 
AVMEDIA_TYPE_VIDEO)’.
It’s a special case of ‘AVMEDIA_TYPE_VIDEO’.

> hdlr_type = "vide";
> descr = "VideoHandler";
> } else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) {
> @@ -2892,6 +2920,128 @@ static int mov_write_hdlr_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVTrack *tra
> return update_size(pb, pos);
> }
> 
> +static int mov_write_pitm_tag(AVIOContext *pb, int item_id)
> +{
> +int64_t pos = avio_tell(pb);
> +avio_wb32(pb, 0); /* size */
> +ffio_wfourcc(pb, "pitm");
> +avio_wb32(pb, 0); /* Version & flags */
> +avio_wb16(pb, item_id); /* item_id */
> +return update_size(pb, pos);
> +}
> +
> +static int mov_write_iloc_tag(AVIOContext *pb, MOVMuxContext *mov, 
> AVFormatContext *s)
> +{
> +int64_t pos = avio_tell(pb);
> +avio_wb32(pb, 0); /* size */
> +ffio_wfourcc(pb, "iloc");
> +avio_wb32(pb, 0); /* Version & flags */
> +avio_w8(pb, (4 << 4) + 4); /* offset_size(4) and length_size(4) */
> +avio_w8(pb, 0); /* base_offset_size(4) and reserved(4) */
> +avio_wb16(pb, 1); /* item_count */
> +
> +avio_wb16(pb, 1); /* item_id */
> +avio_wb16(pb, 0); /* data_reference_index */
> +avio_wb16(pb, 1); /* extent_count */
> +mov->avif_extent_pos = avio_tell(pb);
> +avio_wb32(pb, 0); /* extent_offset (written later) */
> +// For animated AVIF, we simply write the first packet's size.
> +avio_wb32(pb, mov->avif_extent_length); /* extent_length */
> +
> +return update_size(pb, pos);
> +}
> +
> +static int mov_write_iinf_tag(AVIOContext *pb, MOVMuxContext *mov, 
> AVFormatContext *s)
> +{
> +int64_t infe_pos;
> +int64_t iinf_pos = avio_tell(pb);
> +avio_wb32(pb, 0); /* size */
> +ffio_wfourcc(pb, "iinf");
> +  

Re: [FFmpeg-devel] [PATCH] avcodec/jpeg2000:fast-fail if HTJ2K codeblocks are present

2022-05-03 Thread Pierre-Anthony Lemieux
Hi Caleb,

There is a space missing in the commit message before "fast-fail".

Few minor comments below.

Looks good otherwise -- it works as expected on an MXF file that
contains JPEG 2000 Part 15 code-blocks.

Looking forward to the full implementation!

Best,

-- Pierre

On Tue, Apr 19, 2022 at 1:17 AM caleb  wrote:
>
> ---
> This patch adds support for detecting Part 15 codeblocks to JPEG2000 
> specified in (Rec. ITU-T T.814 | ISO/IEC 15444-15).
>
> The decoder on detecting Part 15 codeblocks now fails gracefully with a 
> AVERROR_PATCHWELCOME return code
>
>  libavcodec/jpeg2000.h| 2 ++
>  libavcodec/jpeg2000dec.c | 9 +
>  2 files changed, 11 insertions(+)
>
> diff --git a/libavcodec/jpeg2000.h b/libavcodec/jpeg2000.h
> index d06313425e..e5ecb4cbf9 100644
> --- a/libavcodec/jpeg2000.h
> +++ b/libavcodec/jpeg2000.h
> @@ -110,6 +110,8 @@ enum Jpeg2000Quantsty { // quantization style
>  #define JPEG2000_CSTY_PREC  0x01 // Precincts defined in coding style
>  #define JPEG2000_CSTY_SOP   0x02 // SOP marker present
>  #define JPEG2000_CSTY_EPH   0x04 // EPH marker present
> +#define JPEG2000_CTSY_HTJ2K_F   0x40 // Only HT code-blocks (Rec. ITU-T 
> T.814 | ISO/IEC 15444-15) are present
> +#define JPEG2000_CTSY_HTJ2K_M   0xC0 // HT code blocks (Rec. ITU-T T.814 | 
> ISO/IEC 15444-15) can be present
>
>  // Progression orders
>  #define JPEG2000_PGOD_LRCP  0x00  // Layer-resolution 
> level-component-position progression
> diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> index 92966b11f5..ef4a653afe 100644
> --- a/libavcodec/jpeg2000dec.c
> +++ b/libavcodec/jpeg2000dec.c
> @@ -521,6 +521,15 @@ static int get_cox(Jpeg2000DecoderContext *s, 
> Jpeg2000CodingStyle *c)
>
>  c->cblk_style = bytestream2_get_byteu(&s->g);
>  if (c->cblk_style != 0) { // cblk style
> +if (c->cblk_style & JPEG2000_CTSY_HTJ2K_M || c->cblk_style & 
> JPEG2000_CTSY_HTJ2K_F) {
> +/*
> + * HT code-blocks (Rec. ITU-T T.814 | ISO/IEC 15444-15) 
> bit-stream
> + * Not yet supported in ffmpeg, cannot continue.

The comment above can be removed since the av_log and return code are
sufficiently descriptive.

> + */
> +av_log(s->avctx, AV_LOG_FATAL, "Support for High throughput JPEG 
> 2000 is not yet available\n");

That should probably be AV_LOG_ERROR.

> +return AVERROR_PATCHWELCOME;
> +}
> +
>  av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", 
> c->cblk_style);
>  if (c->cblk_style & JPEG2000_CBLK_BYPASS)
>  av_log(s->avctx, AV_LOG_WARNING, "Selective arithmetic coding 
> bypass\n");
> --
> 2.34.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel 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".