[FFmpeg-devel] [PATCH] avcodec/options_table: reorder nokey after nointra

2023-04-25 Thread Zhao Zhili
From: Zhao Zhili 

So the values are in ascending order.

Signed-off-by: Zhao Zhili 
---
 libavcodec/options_table.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index f331ce2861..4f5918c7f6 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -259,8 +259,8 @@ static const AVOption avcodec_options[] = {
 {"default" , "discard useless frames",  0, 
AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, 
"avdiscard"},
 {"noref"   , "discard all non-reference frames",0, 
AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONREF  }, INT_MIN, INT_MAX, V|D, 
"avdiscard"},
 {"bidir"   , "discard all bidirectional frames",0, 
AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_BIDIR   }, INT_MIN, INT_MAX, V|D, 
"avdiscard"},
-{"nokey"   , "discard all frames except keyframes", 0, 
AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONKEY  }, INT_MIN, INT_MAX, V|D, 
"avdiscard"},
 {"nointra" , "discard all frames except I frames",  0, 
AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONINTRA}, INT_MIN, INT_MAX, V|D, 
"avdiscard"},
+{"nokey"   , "discard all frames except keyframes", 0, 
AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONKEY  }, INT_MIN, INT_MAX, V|D, 
"avdiscard"},
 {"all" , "discard all frames",  0, 
AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_ALL }, INT_MIN, INT_MAX, V|D, 
"avdiscard"},
 {"bidir_refine", "refine the two motion vectors used in bidirectional 
macroblocks", OFFSET(bidir_refine), AV_OPT_TYPE_INT, {.i64 = 1 }, 0, 4, V|E},
 {"keyint_min", "minimum interval between IDR-frames", OFFSET(keyint_min), 
AV_OPT_TYPE_INT, {.i64 = 25 }, INT_MIN, INT_MAX, V|E},
-- 
2.25.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 3/5] avformat/mov: Better check for duplicate iloc

2023-04-25 Thread Vignesh Venkatasubramanian
On Mon, Apr 17, 2023 at 4:18 PM Michael Niedermayer
 wrote:
>
> On Mon, Apr 17, 2023 at 12:36:26PM +0200, Anton Khirnov wrote:
> > Quoting Michael Niedermayer (2023-04-17 00:25:16)
> > > Fixes: memleak
> > > Fixes: 
> > > 45982/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-6674082962997248
> > >
> > > Found-by: continuous fuzzing process 
> > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > Signed-off-by: Michael Niedermayer 
> > > ---
> > >  libavformat/mov.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > > index 057fd872b10..6853bb324cf 100644
> > > --- a/libavformat/mov.c
> > > +++ b/libavformat/mov.c
> > > @@ -,7 +,7 @@ static int mov_read_iloc(MOVContext *c, AVIOContext 
> > > *pb, MOVAtom atom)
> > >  return 0;
> > >  }
> > >
> > > -if (c->fc->nb_streams) {
> > > +if (c->fc->nb_streams || c->avif_info) {
> >
> > This first condition is now redundant, is it not?
>
> Iam not sure

I think the second condition alone should be enough here. Either way,
lgtm (if the current patch is more clearer for readers).

> what exactly happens if a trak occurs before
>

If a trak occurs before, then the condition in the line above should
take care of that case (!c->is_still_picture_avif). Because if a trak
was found, it will not be considered a still picture.

> Iam also not sure what happens if multiple meta tags occur triggering
> the avif stream addition, i may be missing something but the code seems
> not to expect that
>

Multiple meta tags are not allowed in the AVIF/HEIF specification.


> Adding the author of this code to CC
>
> thx
>
> [...]
>
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> In a rich man's house there is no place to spit but his face.
> -- Diogenes of Sinope



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

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


Re: [FFmpeg-devel] [PATCH 0/2] Implement SMPTE 2038 output support over Decklink SDI

2023-04-25 Thread Marton Balint



On Mon, 24 Apr 2023, Devin Heitmueller wrote:


Hello Marton,

Thanks for reviewing.  Comments inline:

On Sun, Apr 23, 2023 at 2:43 PM Marton Balint  wrote:


[...]

Thanks for the detailed explanations. I guess then keeping the queue is 
well justified here.



Regarding the use of avpriv_packet_list() as opposed to
avpacket_queue_*, I used the avpacket_queue functions for consistency
with the decklink capture module where it is used today.  Also,
avpacket_queue is threadsafe while avpriv_packet_list.*() is not.
While the threadsafeness is not critical for the VANC case, I have
subsequent patches for audio where it is important, and I figured it
would more consistent to use the same queue mechanism within decklink
for all three (capture, audio output, and vanc output).


Can you explain how thread safety will be relevant for audio? The 
muxer should get packets in a thread safe way, so I don't quite see how 
suddenly it will be needed.




That said, I wouldn't specifically object to converting to the
avpriv_packet_list functions since thread-safeness isn't really a
requirement for this particular case.  It's probably worth noting
though that I extended the avpacket_queue method to allow me to peek
at the first packet in the queue (which avpriv_packet_list doesn't
support today).  Hence converting to avpriv_packet_list would require
an equivalent addition to be accepted upstream.


You can access the internals of the PacketList struct, so you can just add 
needed function to your own code, you don't necessarily have to make it 
public. On the other hand, the avpriv_packet_list does not have the 
concept of queue size or queue count, so it is not only thread safety 
that will be missing.


Two things bother me with the decklink queue:

1) It duplicates the functionality of avpriv_packet_list_put and 
avpriv_packet_list_get, but it seems to me it should not be difficult 
to actually use these get/put functions in the decklink queue as well, 
because it is already using the same packet list struct internally.

Maybe can you give it a try?

2) Namespacing of the struct / functions are wrong. Struct is called 
AVPacketQueue, it should be something like DecklinkPacketQueue in order 
to make it clear that it is not a public struct. The function names are 
prefixed with avpacket, which is also wrong. It should be simply 
packet_queue_xxx, av* would imply a public function. And if you 
factorize it to a non-static function, then it should be 
ff_decklink_packet_queue_xxx.


With these two things fixed, things would look a lot better :)

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

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


Re: [FFmpeg-devel] [PATCH] avcodec/jpeg2000dec: Explicitly cast quad_width and quad_height to size_t

2023-04-25 Thread James Almer

On 4/25/2023 5:13 PM, Pierre-Anthony Lemieux wrote:

On Tue, Apr 25, 2023 at 11:25 AM  wrote:


From: caleb 

Prevents un-necessary casts when calculating buf_size


This is to address Coverity CID 1528149: """Suspicious implicit sign
extension: "quad_height" with type "uint16_t const" (16 bits,
unsigned) is promoted in "4 * quad_width * quad_height" to type "int"
(32 bits, signed), then sign-extended to type "unsigned long" (64
bits, unsigned).  If "4 * quad_width * quad_height" is greater than
0x7FFF, the upper bits of the result will all be 1."""


---
  libavcodec/jpeg2000htdec.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c
index 51cd96e0f1..8907820806 100644
--- a/libavcodec/jpeg2000htdec.c
+++ b/libavcodec/jpeg2000htdec.c
@@ -592,8 +592,8 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
  const uint16_t is_border_x = width % 2;
  const uint16_t is_border_y = height % 2;

-const uint16_t quad_width  = ff_jpeg2000_ceildivpow2(width, 1);
-const uint16_t quad_height = ff_jpeg2000_ceildivpow2(height, 1);
+const size_t quad_width  = ff_jpeg2000_ceildivpow2(width, 1);
+const size_t quad_height = ff_jpeg2000_ceildivpow2(height, 1);


Shouldn't quad_width and quad_height be kept as uint16_t, and instead
be explicitly cast to (size_t) when computing buf_size?


Or just make the 4 a 4UL.





  size_t buf_size = 4 * quad_width * quad_height;

--
2.39.2


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

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

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

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


Re: [FFmpeg-devel] [PATCH] avcodec/jpeg2000dec: Explicitly cast quad_width and quad_height to size_t

2023-04-25 Thread Pierre-Anthony Lemieux
On Tue, Apr 25, 2023 at 11:25 AM  wrote:
>
> From: caleb 
>
> Prevents un-necessary casts when calculating buf_size

This is to address Coverity CID 1528149: """Suspicious implicit sign
extension: "quad_height" with type "uint16_t const" (16 bits,
unsigned) is promoted in "4 * quad_width * quad_height" to type "int"
(32 bits, signed), then sign-extended to type "unsigned long" (64
bits, unsigned).  If "4 * quad_width * quad_height" is greater than
0x7FFF, the upper bits of the result will all be 1."""

> ---
>  libavcodec/jpeg2000htdec.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c
> index 51cd96e0f1..8907820806 100644
> --- a/libavcodec/jpeg2000htdec.c
> +++ b/libavcodec/jpeg2000htdec.c
> @@ -592,8 +592,8 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
> Jpeg2000DecoderContext *s,
>  const uint16_t is_border_x = width % 2;
>  const uint16_t is_border_y = height % 2;
>
> -const uint16_t quad_width  = ff_jpeg2000_ceildivpow2(width, 1);
> -const uint16_t quad_height = ff_jpeg2000_ceildivpow2(height, 1);
> +const size_t quad_width  = ff_jpeg2000_ceildivpow2(width, 1);
> +const size_t quad_height = ff_jpeg2000_ceildivpow2(height, 1);

Shouldn't quad_width and quad_height be kept as uint16_t, and instead
be explicitly cast to (size_t) when computing buf_size?

>
>  size_t buf_size = 4 * quad_width * quad_height;
>
> --
> 2.39.2
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH 2/2] avcodec/aacdec_template: Fix undefined signed interger operations

2023-04-25 Thread Michael Niedermayer
Fixed: signed integer overflow: -2 * -1085502286 cannot be represented in type 
'int'
Fixed: 
57986/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AAC_FIXED_fuzzer-5123651145170944

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/aacdec_template.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 444dc4fa9d..237ec8828f 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -2856,8 +2856,8 @@ static void imdct_and_windowing_eld(AACContext *ac, 
SingleChannelElement *sce)
 ac->mdct512_fn(ac->mdct512, buf, in, sizeof(INTFLOAT));
 
 for (i = 0; i < n; i+=2) {
-buf[i + 0] = -(USE_FIXED + 1)*buf[i + 0];
-buf[i + 1] =  (USE_FIXED + 1)*buf[i + 1];
+buf[i + 0] = -(USE_FIXED + 1U)*buf[i + 0];
+buf[i + 1] =  (USE_FIXED + 1U)*buf[i + 1];
 }
 // Like with the regular IMDCT at this point we still have the middle half
 // of a transform but with even symmetry on the left and odd symmetry on
-- 
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] avcodec/wavarc: Fix k limit

2023-04-25 Thread Michael Niedermayer
The implementation does not support k=32

Fixes: shift exponent 32 is too large for 32-bit type 'unsigned int'
Fixes: 
57976/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WAVARC_fuzzer-5911925807775744

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/wavarc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/wavarc.c b/libavcodec/wavarc.c
index 827803c91d..312e4beb7f 100644
--- a/libavcodec/wavarc.c
+++ b/libavcodec/wavarc.c
@@ -192,7 +192,7 @@ static int decode_1dif(AVCodecContext *avctx,
 if (block_type < 4 && block_type >= 0) {
 k = 1 + (avctx->sample_fmt == AV_SAMPLE_FMT_S16P);
 k = get_urice(gb, k) + 1;
-if (k > 32)
+if (k >= 32)
 return AVERROR_INVALIDDATA;
 }
 
@@ -284,7 +284,7 @@ static int decode_2slp(AVCodecContext *avctx,
 if (block_type < 5 && block_type >= 0) {
 k = 1 + (avctx->sample_fmt == AV_SAMPLE_FMT_S16P);
 k = get_urice(gb, k) + 1;
-if (k > 32)
+if (k >= 32)
 return AVERROR_INVALIDDATA;
 }
 
-- 
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] avcodec/jpeg2000dec: Explicitly cast quad_width and quad_height to size_t

2023-04-25 Thread etemesicaleb
From: caleb 

Prevents un-necessary casts when calculating buf_size
---
 libavcodec/jpeg2000htdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c
index 51cd96e0f1..8907820806 100644
--- a/libavcodec/jpeg2000htdec.c
+++ b/libavcodec/jpeg2000htdec.c
@@ -592,8 +592,8 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 const uint16_t is_border_x = width % 2;
 const uint16_t is_border_y = height % 2;
 
-const uint16_t quad_width  = ff_jpeg2000_ceildivpow2(width, 1);
-const uint16_t quad_height = ff_jpeg2000_ceildivpow2(height, 1);
+const size_t quad_width  = ff_jpeg2000_ceildivpow2(width, 1);
+const size_t quad_height = ff_jpeg2000_ceildivpow2(height, 1);
 
 size_t buf_size = 4 * quad_width * quad_height;
 
-- 
2.39.2

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

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


Re: [FFmpeg-devel] [PATCH] lavu: header and documentation for AVWriter

2023-04-25 Thread James Almer

On 4/25/2023 2:11 PM, Nicolas George wrote:

Hi.

I finally have some tome to go at this again.

Totalizing this thread, the previous discussions and the few private
mails I received, I conclude there is significant more support than
opposition to AVWriter, so I am moving forward with polishing and
pushing the implementation.

(To avoid antagonizing people, and because I knew a new job would mean
little time to work on it soon, I refrained from pushing the header, but
consider it done anyway: the fact that the implementation of AVWriter is
not present in FFmpeg is now a bug that needs to be fixed.)

Regards,


I support the addition of a new better API as a replacement for 
AVBprint, as long as you take into account the suggestions made by 
people and their requests for exemplifications of its usage and 
usefulness. This also means potential changes to the header.
And please, do not ignore or dismiss any of them. No one is out to block 
your work for the sake of it.

___
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] lavu: header and documentation for AVWriter

2023-04-25 Thread Nicolas George
Hi.

I finally have some tome to go at this again.

Totalizing this thread, the previous discussions and the few private
mails I received, I conclude there is significant more support than
opposition to AVWriter, so I am moving forward with polishing and
pushing the implementation.

(To avoid antagonizing people, and because I knew a new job would mean
little time to work on it soon, I refrained from pushing the header, but
consider it done anyway: the fact that the implementation of AVWriter is
not present in FFmpeg is now a bug that needs to be fixed.)

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] [PATCH] mov: Do not blindly disable advanced edit lists if use_mfra_for is set

2023-04-25 Thread Derek Buitenhuis
On 4/20/2023 3:36 PM, Derek Buitenhuis wrote:
> This was a bug/mistake in dae3679a9bfa421829ef9049ae2167089a2fdef7.
> 
> use_mfra_for by defintion only has an effect on fragmented MP4 files,
> making the check not only redundant, but also broken if a user used
> the option globally (i.e. set on non-fragmented MP4s).
> 
> Signed-off-by: Derek Buitenhuis 
> ---
>  libavformat/mov.c | 6 +-
>  1 file changed, 1 insertion(+), 5 deletions(-)

Will push soon if there are no objections.

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

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


Re: [FFmpeg-devel] [PATCH v2] fftools/ffmpeg_mux: fix reporting muxer EOF as error

2023-04-25 Thread Nicolas George
Anton Khirnov (12023-04-24):
> I think the point on which we disagree is your notion of "error
> conditions" as being basically interchangeable.

The way everything, FFmpeg and all other sane system work, is that the
caller handles the very few errors it know how to handle (EAGAIN
certainly, maybe a few other depending on the situation), and everything
else is passed to the user in human-readable form, in the hope the user
can deal with it.

So in a sence, most errors are basically interchangeable for the
application, and it is how it is supposed to be. For example EISDIR,
ENOENT, ENOTDIR are almost always interchangeable for the application,
and really mean to the user “you mistyped the file name somehow”.

> In both of these cases the CLI code as it is now is correct.

Absolutely not. The documentation states that muxers return errors and
nothing else, there is no special case for EOF, unlike demuxers, and
therefore this patch is a waste of code.

-- 
  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] [PATCH] MXF - Add jpeg2000 subdescriptor - Sponsored by INA

2023-04-25 Thread Cédric Le Barz


Le 05/04/2023 à 15:53, Tomas Härdin a écrit :

ons 2023-04-05 klockan 15:05 +0200 skrev Cédric Le Barz:

Le 03/04/2023 à 17:14, Michael Niedermayer a écrit :

On Mon, Apr 03, 2023 at 10:08:25AM +0200, Cédric Le Barz wrote:

Hi,

I've attached the patch to this mail, in order to solve newlines

insertion

issue.

Please make sure each patch also updates the fate tests so
make fate
doesnt fail

I've attached to this mail the new patch. Fate test issue is fixed.


Please avoid top posting.

I was actually about to suggest merging these two patches but I see you
read my mind :)


@@ -1131,9 +1164,9 @@ static const UID mxf_aes3_descriptor_key  =
{ 0x06,0x0E,0x2B,0x34,0x02,0x53,
  static const UID mxf_cdci_descriptor_key  = {
0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01
,0x28,0x00 };
  static const UID mxf_rgba_descriptor_key  = {
0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01
,0x29,0x00 };
  static const UID mxf_generic_sound_descriptor_key = {
0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01
,0x42,0x00 };
-

Stray line deletion


+mxf_write_local_tag(s, 2, 0x8401);
+avio_wb16(pb, 0x);
+mxf_write_local_tag(s, 4, 0x8402);
+avio_wb32(pb, st->codecpar->width);
+mxf_write_local_tag(s, 4, 0x8403);
+avio_wb32(pb, st->codecpar->height);
+mxf_write_local_tag(s, 4, 0x8404);
+avio_wb32(pb, 0);
+mxf_write_local_tag(s, 4, 0x8405);
+avio_wb32(pb, 0);
+mxf_write_local_tag(s, 4, 0x8406);
+avio_wb32(pb, st->codecpar->width);
+mxf_write_local_tag(s, 4, 0x8407);
+avio_wb32(pb, st->codecpar->height);
+mxf_write_local_tag(s, 4, 0x8408);
+avio_wb32(pb, 0);
+mxf_write_local_tag(s, 4, 0x8409);
+avio_wb32(pb, 0);
+mxf_write_local_tag(s, 2, 0x840A);
+avio_wb16(pb, component_count);

A comment on each of these explaining what they are would be nice.


+{
+char _desc [3][3]= {  {0x09,0x01,0x01} , {0x09,0x02,0x01} ,
{0x09,0x02,0x01} };
+int comp = 0;
+for ( comp = 0; comp< component_count ;comp++ ) {
+avio_write(pb, _desc[comp%3] , 3);
+}
+}

Maybe just a style nit but you could move the char desc[] into the loop
body, int comp to the start of the function and then you can remove the
extra {} around this. Also you could make desc static const.


+{
+char _layout[16] = {  'Y' , '\n', 'U' , '\n', 'V' , '\n',
'F' , 0x02,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00 };
+avio_write(pb, _layout , 16);
+}

Again there is the issue of RGB(A)

/Tomas

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



Please consider this new patch taking into account remarks. For the 
moment, I remove the RGB(A) / YUV code part as it is an optional feature 
for the JPEG2000 subdescriptor.


Regards,

Cédric
--- Begin Message ---
Signed-off-by: Cedric Le Barz 
---
 ffmpeg/libavformat/mxf.h|   1 +
 ffmpeg/libavformat/mxfenc.c | 169 +++-
 2 files changed, 167 insertions(+), 3 deletions(-)

diff --git a/ffmpeg/libavformat/mxf.h b/ffmpeg/libavformat/mxf.h
index 2561605..7dd1681 100644
--- a/ffmpeg/libavformat/mxf.h
+++ b/ffmpeg/libavformat/mxf.h
@@ -55,6 +55,7 @@ enum MXFMetadataSetType {
 SoundfieldGroupLabelSubDescriptor,
 GroupOfSoundfieldGroupsLabelSubDescriptor,
 FFV1SubDescriptor,
+JPEG2000SubDescriptor,
 };
 
 enum MXFFrameLayout {
diff --git a/ffmpeg/libavformat/mxfenc.c b/ffmpeg/libavformat/mxfenc.c
index a29d678..7065a7d 100644
--- a/ffmpeg/libavformat/mxfenc.c
+++ b/ffmpeg/libavformat/mxfenc.c
@@ -48,8 +48,10 @@
 #include "libavutil/pixdesc.h"
 #include "libavutil/time_internal.h"
 #include "libavcodec/avcodec.h"
+#include "libavcodec/bytestream.h"
 #include "libavcodec/golomb.h"
 #include "libavcodec/h264.h"
+#include "libavcodec/jpeg2000.h"
 #include "libavcodec/packet_internal.h"
 #include "libavcodec/startcode.h"
 #include "avformat.h"
@@ -102,6 +104,16 @@ typedef struct MXFStreamContext {
 int b_picture_count; ///< maximum number of consecutive b pictures, 
used in mpeg-2 descriptor
 int low_delay;   ///< low delay, used in mpeg-2 descriptor
 int avc_intra;
+uint16_t j2k_cap;///< j2k required decoder capabilities
+uint32_t j2k_xsiz;   ///< j2k widht of the reference grid
+uint32_t j2k_ysiz;   ///< j2k height of the reference grid
+uint32_t j2k_x0siz;  ///< j2k horizontal offset from the origin of the 
reference grid to the left side of the image
+uint32_t j2k_y0siz;  ///< j2k vertical offset from the origin of the 
reference grid to the left side of the image
+uint32_t j2k_xtsiz;  ///< j2k width of one reference tile with respect 
to the reference grid
+

Re: [FFmpeg-devel] [PATCH v3 1/5] ccfifo: Properly handle CEA-708 captions through framerate conversion

2023-04-25 Thread Lance Wang
On Fri, Apr 21, 2023 at 9:29 PM Devin Heitmueller <
devin.heitmuel...@ltnglobal.com> wrote:

> When transcoding video that contains 708 closed captions, the
> caption data is tied to the frames as side data.  Simply dropping
> or adding frames to change the framerate will result in loss of
> data, so the caption data needs to be preserved and reformatted.
>
> For example, without this patch converting 720p59 to 1080i59
> would result in loss of 50% of the caption bytes, resulting in
> garbled 608 captions and 708 probably wouldn't render at all.
> Further, the frames that are there will have an illegal
> cc_count for the target framerate, so some decoders may ignore
> the packets entirely.
>
> Extract the 608 and 708 tuples and insert them onto queues.  Then
> after dropping/adding frames, re-write the tuples back into the
> resulting frames at the appropriate rate given the target
> framerate.  This includes both having the correct cc_count as
> well as clocking out the 608 pairs at the appropriate rate.
>
> Signed-off-by: Devin Heitmueller 
> ---
>  libavfilter/Makefile |   1 +
>  libavfilter/ccfifo.c | 191
> +++
>  libavfilter/ccfifo.h |  85 +++
>  3 files changed, 277 insertions(+)
>  create mode 100644 libavfilter/ccfifo.c
>  create mode 100644 libavfilter/ccfifo.h
>
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 71e198b..628ade8 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -14,6 +14,7 @@ OBJS = allfilters.o
>\
> buffersink.o \
> buffersrc.o  \
> colorspace.o \
> +   ccfifo.o \
> drawutils.o  \
> fifo.o   \
> formats.o\
> diff --git a/libavfilter/ccfifo.c b/libavfilter/ccfifo.c
> new file mode 100644
> index 000..3f8be57
> --- /dev/null
> +++ b/libavfilter/ccfifo.c
> @@ -0,0 +1,191 @@
> +/*
> + * CEA-708 Closed Captioning FIFO
> + * Copyright (c) 2023 LTN Global Communications
> + *
> + * Author: Devin Heitmueller 
> + *
> + * 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 "ccfifo.h"
> +
> +struct AVCCFifo {
> +AVFifo *cc_608_fifo;
> +AVFifo *cc_708_fifo;
> +int expected_cc_count;
> +int expected_608;
> +int cc_detected;
> +void *log_ctx;
> +};
> +
> +#define MAX_CC_ELEMENTS 128
> +#define CC_BYTES_PER_ENTRY 3
> +
> +struct cc_lookup {
> +int num;
> +int den;
> +int cc_count;
> +int num_608;
> +};
> +
> +const static struct cc_lookup cc_lookup_vals[] = {
> +{ 15, 1, 40, 4 },
> +{ 24, 1, 25, 3 },
> +{ 24000, 1001, 25, 3 },
> +{ 30, 1, 20, 2 },
> +{ 3, 1001, 20, 2},
> +{ 60, 1, 10, 1 },
> +{ 6, 1001, 10, 1},
> +};
> +
> +void ff_ccfifo_freep(AVCCFifo **ccf)
> +{
> +if (ccf && *ccf) {
> +AVCCFifo *tmp = *ccf;
> +if (tmp->cc_608_fifo)
> +av_fifo_freep2(>cc_608_fifo);
> +if (tmp->cc_708_fifo)
> +av_fifo_freep2(>cc_708_fifo);
> +av_freep(*ccf);
> +}
> +}
> +
> +AVCCFifo *ff_ccfifo_alloc(AVRational *framerate, void *log_ctx)
> +{
> +AVCCFifo *ccf;
> +int i;
> +
> +ccf = av_mallocz(sizeof(*ccf));
> +if (!ccf)
> +return NULL;
> +
> +if (!(ccf->cc_708_fifo = av_fifo_alloc2(MAX_CC_ELEMENTS,
> CC_BYTES_PER_ENTRY, 0)))
> +goto error;
> +
> +if (!(ccf->cc_608_fifo = av_fifo_alloc2(MAX_CC_ELEMENTS,
> CC_BYTES_PER_ENTRY, 0)))
> +goto error;
> +
> +/* Based on the target FPS, figure out the expected cc_count and
> number of
> +   608 tuples per packet.  See ANSI/CTA-708-E Sec 4.3.6.1. */
> +for (i = 0; i < (sizeof(cc_lookup_vals) / sizeof(struct cc_lookup));
> i++) {
>

I prefer to use FF_ARRAY_ELEMS here.


> +if (framerate->num == cc_lookup_vals[i].num &&
> +framerate->den == 

Re: [FFmpeg-devel] trac spam

2023-04-25 Thread Thilo Borgmann

Am 24.04.23 um 22:23 schrieb Michael Niedermayer:

Hi all

thilo pointed me to some spam on trac today, investigating i found a spammer
with 4 accounts who spammed ~6 tickets

thanks to the last update the permission for the admin page to delete users
seems to got a new name which slightly slowed me down.

I think i deleted all that spam.
If you see more spam, please report it. We do have a few people who
had spam filtering powers but iam not sure they are still aware of it
as there wasnt much previously. Iam also not sure if all the previosuly
needed permission names still are effective. So if you where previously
able to cleanup spam and it doesnt work anymore, say something!


Thank you, Michael!

-Thilo

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

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


Re: [FFmpeg-devel] [PATCH] avcodec/aacenc: add strict bit rate control mode

2023-04-25 Thread Jeremy Wu
Thanks for the feedback! I was also looking at whether there is a less 
intrusive way to enable the code path.


I have uploaded a v2 patch that looks at `bit_rate_tolerance`, with 
minor changes to the option table as it was ignored in the context of audio.


I'm only looking at the Bluetooth streaming use case as of now, and the 
issue cannot be bypassed without this (common implementations use libfdk 
that supports a similar option).


___
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 v5 5/5] lavfi/format: add a hwmap auto conversion filter

2023-04-25 Thread Tong Wu
When two formats lists cannot be merged, a scale filter is
auto-inserted. However, when it comes to hardware map, we have to
manually add a hwmap filter to do the conversion. This patch introduces
an auto hwmap filter to do the hwmap conversion automatically.

Signed-off-by: Tong Wu 
---
 libavfilter/avfiltergraph.c | 3 ++-
 libavfilter/formats.c   | 4 
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 8af0467bc5..b2b627ad6a 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -402,7 +402,8 @@ static int insert_auto_filter(AVFilterContext **convert, 
AVFilterGraph *graph,
 AVFilterContext *ctx;
 AVFilterLink *inlink, *outlink;
 char inst_name[30];
-const char *opts = FF_FIELD_AT(char *, 
neg->conversion_filters[conv_step].conversion_opts_offset, *graph);
+const char *opts = 
neg->conversion_filters[conv_step].conversion_opts_offset == 0 ? NULL :
+   FF_FIELD_AT(char *, 
neg->conversion_filters[conv_step].conversion_opts_offset, *graph);
 const char *name = neg->conversion_filters[conv_step].conversion_filter;
 
 if (!(filter = avfilter_get_by_name(name))) {
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index c8e20e5b20..fee10fa0ee 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -331,6 +331,10 @@ static const AVFilterFormatsFilter filters_video[] = {
 .conversion_filter = "scale",
 .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts),
 },
+{
+.conversion_filter = "hwmap",
+.conversion_opts_offset = 0,
+}
 };
 
 static const AVFilterFormatsFilter filters_audio[] = {
-- 
2.39.1.windows.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 v5 4/5] lavfi/format: wrap auto filters into structures

2023-04-25 Thread Tong Wu
This patch wraps auto conversion filters into new structures, making it
easier to add more auto filters. And it adds a loop to automatically insert
every possible conversion filter until merge succeeds.

Signed-off-by: Tong Wu 
---
 libavfilter/avfiltergraph.c | 76 +
 libavfilter/formats.c   | 22 +--
 libavfilter/formats.h   | 10 -
 3 files changed, 78 insertions(+), 30 deletions(-)

diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 9e5bb32886..8af0467bc5 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -395,24 +395,22 @@ static int formats_declared(AVFilterContext *f)
 
 static int insert_auto_filter(AVFilterContext **convert, AVFilterGraph *graph,
   AVFilterLink *link, const AVFilterNegotiation 
*neg,
-  int *converter_count, void *log_ctx)
+  unsigned conv_step, int *converter_count, void 
*log_ctx)
 {
 int ret;
 const AVFilter *filter;
 AVFilterContext *ctx;
 AVFilterLink *inlink, *outlink;
 char inst_name[30];
-const char *opts;
+const char *opts = FF_FIELD_AT(char *, 
neg->conversion_filters[conv_step].conversion_opts_offset, *graph);
+const char *name = neg->conversion_filters[conv_step].conversion_filter;
 
-if (!(filter = avfilter_get_by_name(neg->conversion_filter))) {
+if (!(filter = avfilter_get_by_name(name))) {
 av_log(log_ctx, AV_LOG_ERROR,
-   "'%s' filter not present, cannot convert formats.\n",
-   neg->conversion_filter);
+   "'%s' filter not present, cannot convert formats.\n", name);
 return AVERROR(EINVAL);
 }
-snprintf(inst_name, sizeof(inst_name), "auto_%s_%d",
- neg->conversion_filter, (*converter_count)++);
-opts = FF_FIELD_AT(char *, neg->conversion_opts_offset, *graph);
+snprintf(inst_name, sizeof(inst_name), "auto_%s_%d", name, 
(*converter_count)++);
 ret = avfilter_graph_create_filter(, filter, inst_name, opts, NULL, 
graph);
 if (ret < 0)
 return ret;
@@ -501,7 +499,7 @@ static int query_formats(AVFilterGraph *graph, void 
*log_ctx)
 for (j = 0; j < filter->nb_inputs; j++) {
 AVFilterLink *link = filter->inputs[j];
 const AVFilterNegotiation *neg;
-unsigned neg_step;
+unsigned neg_step, conv_step;
 int convert_needed = 0;
 
 if (!link)
@@ -537,8 +535,6 @@ static int query_formats(AVFilterGraph *graph, void 
*log_ctx)
 }
 
 if (convert_needed) {
-AVFilterContext *convert;
-
 if (graph->disable_auto_convert) {
 av_log(log_ctx, AV_LOG_ERROR,
"The filters '%s' and '%s' do not have a common 
format "
@@ -548,20 +544,52 @@ static int query_formats(AVFilterGraph *graph, void 
*log_ctx)
 }
 
 /* couldn't merge format lists. auto-insert conversion filter 
*/
-ret = insert_auto_filter(, graph, link, neg, 
_count, log_ctx);
-if (ret < 0) {
-av_log(log_ctx, AV_LOG_ERROR, "Failed to insert an auto 
filter.\n");
-return ret;
-}
+for (conv_step = 0; conv_step < neg->nb_conversion_filters; 
conv_step++) {
+AVFilterContext *convert;
+ret = insert_auto_filter(, graph, link, neg,
+ conv_step, _count, 
log_ctx);
+if (ret < 0) {
+av_log(log_ctx, AV_LOG_ERROR, "Failed to insert an 
auto filter.\n");
+return ret;
+}
 
-ret = merge_auto_filter(convert, neg);
-if (ret < 0)
-return ret;
-else if (ret == 0) {
-av_log(log_ctx, AV_LOG_ERROR,
-   "Impossible to convert between the formats 
supported by the filter "
-   "'%s' and the filter '%s'\n", link->src->name, 
link->dst->name);
-return AVERROR(ENOSYS);
+ret = merge_auto_filter(convert, neg);
+if (ret < 0)
+return ret;
+else if (ret > 0)
+break;
+else if (conv_step < neg->nb_conversion_filters - 1) {
+AVFilterLink *inlink  = convert->inputs[0];
+AVFilterLink *outlink = convert->outputs[0];
+av_log(log_ctx, AV_LOG_VERBOSE,
+   "Impossible to convert between the formats 
supported by the filter "
+   "'%s' and the filter '%s', try another 
conversion filter.\n",
+   link->src->name, link->dst->name);
+ 

[FFmpeg-devel] [PATCH v5 3/5] lavfi/avfiltergraph: move convert codes into functions

2023-04-25 Thread Tong Wu
This patch moves the auto-insert filter codes into two functions.

Signed-off-by: Tong Wu 
---
 libavfilter/avfiltergraph.c | 128 ++--
 1 file changed, 79 insertions(+), 49 deletions(-)

diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 53f468494d..9e5bb32886 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -393,6 +393,74 @@ static int formats_declared(AVFilterContext *f)
 return 1;
 }
 
+static int insert_auto_filter(AVFilterContext **convert, AVFilterGraph *graph,
+  AVFilterLink *link, const AVFilterNegotiation 
*neg,
+  int *converter_count, void *log_ctx)
+{
+int ret;
+const AVFilter *filter;
+AVFilterContext *ctx;
+AVFilterLink *inlink, *outlink;
+char inst_name[30];
+const char *opts;
+
+if (!(filter = avfilter_get_by_name(neg->conversion_filter))) {
+av_log(log_ctx, AV_LOG_ERROR,
+   "'%s' filter not present, cannot convert formats.\n",
+   neg->conversion_filter);
+return AVERROR(EINVAL);
+}
+snprintf(inst_name, sizeof(inst_name), "auto_%s_%d",
+ neg->conversion_filter, (*converter_count)++);
+opts = FF_FIELD_AT(char *, neg->conversion_opts_offset, *graph);
+ret = avfilter_graph_create_filter(, filter, inst_name, opts, NULL, 
graph);
+if (ret < 0)
+return ret;
+
+if ((ret = avfilter_insert_filter(link, ctx, 0, 0)) < 0)
+return ret;
+
+if ((ret = filter_query_formats(ctx)) < 0)
+return ret;
+
+inlink  = ctx->inputs[0];
+outlink = ctx->outputs[0];
+av_assert0( inlink->incfg.formats->refcount > 0);
+av_assert0( inlink->outcfg.formats->refcount > 0);
+av_assert0(outlink->incfg.formats->refcount > 0);
+av_assert0(outlink->outcfg.formats->refcount > 0);
+if (outlink->type == AVMEDIA_TYPE_AUDIO) {
+av_assert0( inlink-> incfg.samplerates->refcount > 0);
+av_assert0( inlink->outcfg.samplerates->refcount > 0);
+av_assert0(outlink-> incfg.samplerates->refcount > 0);
+av_assert0(outlink->outcfg.samplerates->refcount > 0);
+av_assert0( inlink-> incfg.channel_layouts->refcount > 0);
+av_assert0( inlink->outcfg.channel_layouts->refcount > 0);
+av_assert0(outlink-> incfg.channel_layouts->refcount > 0);
+av_assert0(outlink->outcfg.channel_layouts->refcount > 0);
+}
+
+*convert = ctx;
+return 0;
+}
+
+static int merge_auto_filter(AVFilterContext *convert, const 
AVFilterNegotiation *neg)
+{
+int ret;
+AVFilterLink *inlink  = convert->inputs[0];
+AVFilterLink *outlink = convert->outputs[0];
+#define MERGE(merger, link)  \
+((merger)->merge(FF_FIELD_AT(void *, (merger)->offset, (link)->incfg),   \
+ FF_FIELD_AT(void *, (merger)->offset, (link)->outcfg)))
+for (unsigned neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
+const AVFilterFormatsMerger *m = >mergers[neg_step];
+if ((ret = MERGE(m,  inlink)) <= 0 ||
+(ret = MERGE(m, outlink)) <= 0)
+break;
+}
+return ret;
+}
+
 /**
  * Perform one round of query_formats() and merging formats lists on the
  * filter graph.
@@ -470,10 +538,6 @@ static int query_formats(AVFilterGraph *graph, void 
*log_ctx)
 
 if (convert_needed) {
 AVFilterContext *convert;
-const AVFilter *filter;
-AVFilterLink *inlink, *outlink;
-char inst_name[30];
-const char *opts;
 
 if (graph->disable_auto_convert) {
 av_log(log_ctx, AV_LOG_ERROR,
@@ -484,54 +548,20 @@ static int query_formats(AVFilterGraph *graph, void 
*log_ctx)
 }
 
 /* couldn't merge format lists. auto-insert conversion filter 
*/
-if (!(filter = avfilter_get_by_name(neg->conversion_filter))) {
-av_log(log_ctx, AV_LOG_ERROR,
-   "'%s' filter not present, cannot convert 
formats.\n",
-   neg->conversion_filter);
-return AVERROR(EINVAL);
-}
-snprintf(inst_name, sizeof(inst_name), "auto_%s_%d",
- neg->conversion_filter, converter_count++);
-opts = FF_FIELD_AT(char *, neg->conversion_opts_offset, 
*graph);
-ret = avfilter_graph_create_filter(, filter, 
inst_name, opts, NULL, graph);
-if (ret < 0)
-return ret;
-if ((ret = avfilter_insert_filter(link, convert, 0, 0)) < 0)
+ret = insert_auto_filter(, graph, link, neg, 
_count, log_ctx);
+if (ret < 0) {
+av_log(log_ctx, AV_LOG_ERROR, "Failed to insert an auto 
filter.\n");
 return ret;
+

[FFmpeg-devel] [PATCH v5 2/5] avfilter/vf_hwmap: get the AVHWDeviceType from outlink format

2023-04-25 Thread Tong Wu
When both derive_device_type and device context are not
presented during hw->hw map, the hwmap filter should be
able to retrieve AVHWDeviceType from outlink->format and create
corresponding hwdevice context.

Signed-off-by: Tong Wu 
---
 libavfilter/vf_hwmap.c | 35 ++-
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/libavfilter/vf_hwmap.c b/libavfilter/vf_hwmap.c
index e246b22603..e5b40233b2 100644
--- a/libavfilter/vf_hwmap.c
+++ b/libavfilter/vf_hwmap.c
@@ -70,16 +70,31 @@ static int hwmap_config_output(AVFilterLink *outlink)
 device_is_derived = 0;
 
 if (inlink->hw_frames_ctx) {
+enum AVHWDeviceType type;
 hwfc = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
 
-if (ctx->derive_device_type) {
-enum AVHWDeviceType type;
+desc = av_pix_fmt_desc_get(outlink->format);
+if (!desc) {
+err = AVERROR(EINVAL);
+goto fail;
+}
 
-type = av_hwdevice_find_type_by_name(ctx->derive_device_type);
-if (type == AV_HWDEVICE_TYPE_NONE) {
-av_log(avctx, AV_LOG_ERROR, "Invalid device type.\n");
-err = AVERROR(EINVAL);
-goto fail;
+if (ctx->derive_device_type || (!device && (desc->flags & 
AV_PIX_FMT_FLAG_HWACCEL))) {
+if (ctx->derive_device_type) {
+type = av_hwdevice_find_type_by_name(ctx->derive_device_type);
+if (type == AV_HWDEVICE_TYPE_NONE) {
+av_log(avctx, AV_LOG_ERROR, "Invalid device type.\n");
+err = AVERROR(EINVAL);
+goto fail;
+}
+} else {
+type = av_hwdevice_get_type_by_pix_fmt(outlink->format);
+if (type == AV_HWDEVICE_TYPE_NONE) {
+av_log(avctx, AV_LOG_ERROR, "Could not get device type 
from "
+"format %s.\n", av_get_pix_fmt_name(outlink->format));
+err = AVERROR(EINVAL);
+goto fail;
+}
 }
 
 err = av_hwdevice_ctx_create_derived(, type,
@@ -92,12 +107,6 @@ static int hwmap_config_output(AVFilterLink *outlink)
 device_is_derived = 1;
 }
 
-desc = av_pix_fmt_desc_get(outlink->format);
-if (!desc) {
-err = AVERROR(EINVAL);
-goto fail;
-}
-
 if (inlink->format == hwfc->format &&
 (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) &&
 !ctx->reverse) {
-- 
2.39.1.windows.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 v5 1/5] avutil/hwcontext: add a function to get the AVHWDeviceType

2023-04-25 Thread Tong Wu
Add a function to get the corresponding AVHWDeviceType from a given
hardware pixel format.

Signed-off-by: Tong Wu 
---
 libavutil/hwcontext.c | 11 +++
 libavutil/hwcontext.h | 12 
 2 files changed, 23 insertions(+)

diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 3396598269..3042bf9af0 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -80,6 +80,17 @@ static const char *const hw_type_names[] = {
 [AV_HWDEVICE_TYPE_VULKAN] = "vulkan",
 };
 
+enum AVHWDeviceType av_hwdevice_get_type_by_pix_fmt(enum AVPixelFormat fmt)
+{
+for (int i = 0; hw_table[i]; i++) {
+for (int j = 0; hw_table[i]->pix_fmts[j] != AV_PIX_FMT_NONE; j++) {
+if (hw_table[i]->pix_fmts[j] == fmt)
+return hw_table[i]->type;
+}
+}
+return AV_HWDEVICE_TYPE_NONE;
+}
+
 enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
 {
 int type;
diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index 7ff08c8608..940c7a6a46 100644
--- a/libavutil/hwcontext.h
+++ b/libavutil/hwcontext.h
@@ -229,6 +229,18 @@ typedef struct AVHWFramesContext {
 int width, height;
 } AVHWFramesContext;
 
+/**
+ * Get the device type by a given pixel format.
+ *
+ * This function only returns a preferred device type which supports the given
+ * pixel format. There is no guarantee that the device type is unique.
+ *
+ * @param fmt Pixel format from enum AVPixelFormat.
+ * @return The type from enum AVHWDeviceType, or AV_HWDEVICE_TYPE_NONE if
+ * not found.
+ */
+enum AVHWDeviceType av_hwdevice_get_type_by_pix_fmt(enum AVPixelFormat fmt);
+
 /**
  * Look up an AVHWDeviceType by name.
  *
-- 
2.39.1.windows.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 v2] avcodec/aacenc: add strict bit rate control option

2023-04-25 Thread Jeremy Wu
From: Jeremy Wu 

In certain use cases, controlling the maximum frame size is critical. An
example is when transmitting AAC packets over Bluetooth A2DP.

While the spec allows the packets to be fragmented (but UNRECOMMENDED),
in practice most headsets do not recognize nor reassemble such packets.

In this patch, we allow setting `bit_rate_tolerance` to 0 to indicate
that the specified bit rate should be treated as an upper bound up to
frame level.

Signed-off-by: Jeremy Wu 
---
 libavcodec/aacenc.c| 12 
 libavcodec/options_table.h |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index ed036209e9..f48f057022 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -1106,6 +1106,18 @@ static int aac_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 too_many_bits = FFMIN(too_many_bits, 6144 * s->channels - 3);
 too_few_bits = FFMIN(FFMAX(rate_bits - rate_bits/4, target_bits), 
too_many_bits);
 
+/* When strict bit-rate control is demanded */
+if (avctx->bit_rate_tolerance == 0) {
+if (rate_bits < frame_bits) {
+float ratio = ((float)rate_bits) / frame_bits;
+s->lambda *= FFMIN(0.9f, ratio);
+continue;
+}
+/* reset lambda when solution is found */
+s->lambda = avctx->global_quality > 0 ? avctx->global_quality : 
120;
+break;
+}
+
 /* When using ABR, be strict (but only for increasing) */
 too_few_bits = too_few_bits - too_few_bits/8;
 too_many_bits = too_many_bits + too_many_bits/2;
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index f331ce2861..716787aa59 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -50,7 +50,7 @@ static const AVOption avcodec_options[] = {
 {"bt", "Set video bitrate tolerance (in bits/s). In 1-pass mode, bitrate 
tolerance specifies how far "
"ratecontrol is willing to deviate from the target average bitrate 
value. This is not related "
"to minimum/maximum bitrate. Lowering tolerance too much has an adverse 
effect on quality.",
-   OFFSET(bit_rate_tolerance), AV_OPT_TYPE_INT, {.i64 = 
AV_CODEC_DEFAULT_BITRATE*20 }, 1, INT_MAX, V|E},
+   OFFSET(bit_rate_tolerance), AV_OPT_TYPE_INT, {.i64 = 
AV_CODEC_DEFAULT_BITRATE*20 }, 0, INT_MAX, A|V|E},
 {"flags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = DEFAULT }, 0, 
UINT_MAX, V|A|S|E|D, "flags"},
 {"unaligned", "allow decoders to produce unaligned output", 0, 
AV_OPT_TYPE_CONST, { .i64 = AV_CODEC_FLAG_UNALIGNED }, INT_MIN, INT_MAX, V | D, 
"flags" },
 {"mv4", "use four motion vectors per macroblock (MPEG-4)", 0, 
AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_4MV }, INT_MIN, INT_MAX, V|E, "flags"},
-- 
2.40.0.634.g4ca3ef3211-goog

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

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