Re: [FFmpeg-devel] [PATCH 3/3] avcodec/mlpdec: add max channels check

2022-09-30 Thread Paul B Mahol
On 9/30/22, Michael Niedermayer  wrote:
> Fixes: out of array access
> Fixes:
> 51648/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TRUEHD_fuzzer-4644322217164800
>


Make sure that this "fix"
does not break Mono.thd decoding.
The sample is on trac ticket.

Thanks.

> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/mlpdec.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
> index 635f92895c5..0b0eb759901 100644
> --- a/libavcodec/mlpdec.c
> +++ b/libavcodec/mlpdec.c
> @@ -547,6 +547,9 @@ static int read_restart_header(MLPDecodeContext *m,
> GetBitContext *gbp,
>  return AVERROR_PATCHWELCOME;
>  }
>
> +if (max_channel + 1 > MAX_CHANNELS || max_channel + 1 < min_channel)
> +return AVERROR_INVALIDDATA;
> +
>  s->min_channel= min_channel;
>  s->max_channel= max_channel;
>  s->coded_channels = ((1LL << (max_channel - min_channel + 1)) - 1)
> << min_channel;
> --
> 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 mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] avformat/mov: parse the last moof box when mp4 segment format

2022-09-30 Thread wangyaqiang


> 2022年9月29日 16:29,zhilizhao(赵志立)  > 写道:
> 
> 
> 
>> On Sep 1, 2022, at 18:22, 1035567...@qq.com  wrote:
>> 
>> From: Wang Yaqiang > >
>> 
>> In the format of mp4 segment, the bitrate calculation of
>> stream depends on the sample_size in moof->traf->trun box.
>> In the original logic, when the last sidx box is read,
>> it is not parsed backwards, and the total sample_size calculation is smaller.
>> As a result, the bitrate displayed by ffprobe is also smaller than the 
>> actual.
>> Increasing the moof_count variable ensures that the last moof is parsed.
>> 
>> Test method: You can use -c copy remux a fmp4 file as mp4
>> and ffprobe the two files will find that the bitrate is inconsistent
>> Befor patch:
>> Stream #0:1[0x2](und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, 
>> stereo, fltp, 59 kb/s
>> After patch:
>> Stream #0:1[0x2](und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, 
>> stereo, fltp, 96 kb/s (default)
>> 
>> Signed-off-by: Wang Yaqiang > >
>> ---
>> libavformat/isom.h | 1 +
>> libavformat/mov.c  | 8 +++-
>> 2 files changed, 8 insertions(+), 1 deletion(-)
>> 
>> diff --git a/libavformat/isom.h b/libavformat/isom.h
>> index f05c2d9c28..183a3c486b 100644
>> --- a/libavformat/isom.h
>> +++ b/libavformat/isom.h
>> @@ -296,6 +296,7 @@ typedef struct MOVContext {
>>int has_looked_for_mfra;
>>int use_tfdt;
>>MOVFragmentIndex frag_index;
>> +int moof_count; //ensure last fragment parse moof box
>>int atom_depth;
>>unsigned int aax_mode;  ///< 'aax' file has been detected
>>uint8_t file_key[20];
>> diff --git a/libavformat/mov.c b/libavformat/mov.c
>> index 14550e6456..396658e342 100644
>> --- a/libavformat/mov.c
>> +++ b/libavformat/mov.c
>> @@ -7784,12 +7784,15 @@ static int mov_read_default(MOVContext *c, 
>> AVIOContext *pb, MOVAtom atom)
>>int64_t start_pos = avio_tell(pb);
>>int64_t left;
>>int err = parse(c, pb, a);
>> +if (a.type == MKTAG('m','o','o','f')) {
>> +c->moof_count ++;
>> +}
>>if (err < 0) {
>>c->atom_depth --;
>>return err;
>>}
>>if (c->found_moov && c->found_mdat && a.size <= INT64_MAX - 
>> start_pos &&
>> -((!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags & 
>> AVFMT_FLAG_IGNIDX || c->frag_index.complete) ||
>> +((!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags & 
>> AVFMT_FLAG_IGNIDX || (c->frag_index.complete && c->moof_count >= 
>> c->frag_index.nb_items)) ||
>> start_pos + a.size == avio_size(pb))) {
>>if (!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags & 
>> AVFMT_FLAG_IGNIDX || c->frag_index.complete)
>>c->next_root_atom = start_pos + a.size;
> 
> No, it breaks the use case with global sidx. We can achieve fast
> startup with global sidx.

This patch indeed have an effect on startup, will add some option.

> 
> The patch describes an issue with multiple sidx cases, actually
> it’s more serious with global sidx. In the first case, the bitrate
> is a little inaccurate. Bitrate is near zero for the second case.
> 
> I have two ideas:
> 
> 1. Just skip bitrate calculation from sc->data_size if sidx exist,
> e.g.,
> 
> @@ -8500,7 +8500,7 @@ static int mov_read_header(AVFormatContext *s)
> for (i = 0; i < s->nb_streams; i++) {
> AVStream *st = s->streams[i];
> MOVStreamContext *sc = st->priv_data;
> -if (st->duration > 0) {
> +if (st->duration > 0 && !sc->has_sidx) {
> /* Akin to sc->data_size * 8 * sc->time_scale / st->duration 
> but accounting for overflows. */
> st->codecpar->bit_rate = av_rescale(sc->data_size, ((int64_t) 
> sc->time_scale) * 8, st->duration);
> if (st->codecpar->bit_rate == INT64_MIN) {
> 
> It’s simple, and bitrate information has multiple sources. 
> 

In this way, will be no bitrate info in the stream, will affect the users?

> 2. Add a option to prevent mark complete when reading sidx
> 
> @@ -5446,7 +5446,7 @@ static int mov_read_sidx(MOVContext *c, AVIOContext 
> *pb, MOVAtom atom)
> // See if the remaining bytes are just an mfra which we can ignore.
> is_complete = offset == stream_size;
> -if (!is_complete && (pb->seekable & AVIO_SEEKABLE_NORMAL) && stream_size 
> > 0 ) {
> +if (!is_complete && (pb->seekable & AVIO_SEEKABLE_NORMAL) && stream_size 
> > 0 && !parse_full) {
> 
> Then

Mfra box is not required in fmp4. for example, adding skip_trailer parameter 
when generate fm4, bitrate will still be incorrect.

> 
> @@ -8500,7 +8500,7 @@ static int mov_read_header(AVFormatContext *s)
> for (i = 0; i < s->nb_streams; i++) {
> AVStream *st = s->streams[i];
> MOVStreamContext *sc = st

Re: [FFmpeg-devel] [PATCH] avformat/mov: parse the last moof box when mp4 segment format

2022-09-30 Thread zhilizhao(赵志立)


> On Sep 30, 2022, at 17:50, wangyaqiang <1035567...@qq.com> wrote:
> 
> 
> 
>> 2022年9月29日 16:29,zhilizhao(赵志立) > > 写道:
>> 
>> 
>> 
>>> On Sep 1, 2022, at 18:22, 1035567...@qq.com  
>>> wrote:
>>> 
>>> From: Wang Yaqiang >> >
>>> 
>>> In the format of mp4 segment, the bitrate calculation of
>>> stream depends on the sample_size in moof->traf->trun box.
>>> In the original logic, when the last sidx box is read,
>>> it is not parsed backwards, and the total sample_size calculation is 
>>> smaller.
>>> As a result, the bitrate displayed by ffprobe is also smaller than the 
>>> actual.
>>> Increasing the moof_count variable ensures that the last moof is parsed.
>>> 
>>> Test method: You can use -c copy remux a fmp4 file as mp4
>>> and ffprobe the two files will find that the bitrate is inconsistent
>>> Befor patch:
>>> Stream #0:1[0x2](und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, 
>>> stereo, fltp, 59 kb/s
>>> After patch:
>>> Stream #0:1[0x2](und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, 
>>> stereo, fltp, 96 kb/s (default)
>>> 
>>> Signed-off-by: Wang Yaqiang >> >
>>> ---
>>> libavformat/isom.h | 1 +
>>> libavformat/mov.c  | 8 +++-
>>> 2 files changed, 8 insertions(+), 1 deletion(-)
>>> 
>>> diff --git a/libavformat/isom.h b/libavformat/isom.h
>>> index f05c2d9c28..183a3c486b 100644
>>> --- a/libavformat/isom.h
>>> +++ b/libavformat/isom.h
>>> @@ -296,6 +296,7 @@ typedef struct MOVContext {
>>>   int has_looked_for_mfra;
>>>   int use_tfdt;
>>>   MOVFragmentIndex frag_index;
>>> +int moof_count; //ensure last fragment parse moof box
>>>   int atom_depth;
>>>   unsigned int aax_mode;  ///< 'aax' file has been detected
>>>   uint8_t file_key[20];
>>> diff --git a/libavformat/mov.c b/libavformat/mov.c
>>> index 14550e6456..396658e342 100644
>>> --- a/libavformat/mov.c
>>> +++ b/libavformat/mov.c
>>> @@ -7784,12 +7784,15 @@ static int mov_read_default(MOVContext *c, 
>>> AVIOContext *pb, MOVAtom atom)
>>>   int64_t start_pos = avio_tell(pb);
>>>   int64_t left;
>>>   int err = parse(c, pb, a);
>>> +if (a.type == MKTAG('m','o','o','f')) {
>>> +c->moof_count ++;
>>> +}
>>>   if (err < 0) {
>>>   c->atom_depth --;
>>>   return err;
>>>   }
>>>   if (c->found_moov && c->found_mdat && a.size <= INT64_MAX - 
>>> start_pos &&
>>> -((!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags & 
>>> AVFMT_FLAG_IGNIDX || c->frag_index.complete) ||
>>> +((!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags & 
>>> AVFMT_FLAG_IGNIDX || (c->frag_index.complete && c->moof_count >= 
>>> c->frag_index.nb_items)) ||
>>>start_pos + a.size == avio_size(pb))) {
>>>   if (!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags & 
>>> AVFMT_FLAG_IGNIDX || c->frag_index.complete)
>>>   c->next_root_atom = start_pos + a.size;
>> 
>> No, it breaks the use case with global sidx. We can achieve fast
>> startup with global sidx.
> 
> This patch indeed have an effect on startup, will add some option.
> 
>> 
>> The patch describes an issue with multiple sidx cases, actually
>> it’s more serious with global sidx. In the first case, the bitrate
>> is a little inaccurate. Bitrate is near zero for the second case.
>> 
>> I have two ideas:
>> 
>> 1. Just skip bitrate calculation from sc->data_size if sidx exist,
>> e.g.,
>> 
>> @@ -8500,7 +8500,7 @@ static int mov_read_header(AVFormatContext *s)
>>for (i = 0; i < s->nb_streams; i++) {
>>AVStream *st = s->streams[i];
>>MOVStreamContext *sc = st->priv_data;
>> -if (st->duration > 0) {
>> +if (st->duration > 0 && !sc->has_sidx) {
>>/* Akin to sc->data_size * 8 * sc->time_scale / st->duration 
>> but accounting for overflows. */
>>st->codecpar->bit_rate = av_rescale(sc->data_size, ((int64_t) 
>> sc->time_scale) * 8, st->duration);
>>if (st->codecpar->bit_rate == INT64_MIN) {
>> 
>> It’s simple, and bitrate information has multiple sources. 
>> 
> 
> In this way, will be no bitrate info in the stream, will affect the users?

It depends. We have multiple sources to get bitrate.

> 
>> 2. Add a option to prevent mark complete when reading sidx
>> 
>> @@ -5446,7 +5446,7 @@ static int mov_read_sidx(MOVContext *c, AVIOContext 
>> *pb, MOVAtom atom)
>>// See if the remaining bytes are just an mfra which we can ignore.
>>is_complete = offset == stream_size;
>> -if (!is_complete && (pb->seekable & AVIO_SEEKABLE_NORMAL) && 
>> stream_size > 0 ) {
>> +if (!is_complete && (pb->seekable & AVIO_SEEKABLE_NORMAL) && 
>> stream_size > 0 && !parse_full) {
>> 
>> Then
> 
> Mfra box is not required in fmp4. for example, adding skip_trailer parameter 
> when genera

Re: [FFmpeg-devel] [PATCH] avformat/mov: parse the last moof box when mp4 segment format

2022-09-30 Thread zhilizhao(赵志立)


> On Sep 30, 2022, at 18:22, zhilizhao(赵志立)  wrote:
> 
> 
> 
>> On Sep 30, 2022, at 17:50, wangyaqiang <1035567...@qq.com> wrote:
>> 
>> 
>> 
>>> 2022年9月29日 16:29,zhilizhao(赵志立) >> > 写道:
>>> 
>>> 
>>> 
 On Sep 1, 2022, at 18:22, 1035567...@qq.com  
 wrote:
 
 From: Wang Yaqiang >>> >
 
 In the format of mp4 segment, the bitrate calculation of
 stream depends on the sample_size in moof->traf->trun box.
 In the original logic, when the last sidx box is read,
 it is not parsed backwards, and the total sample_size calculation is 
 smaller.
 As a result, the bitrate displayed by ffprobe is also smaller than the 
 actual.
 Increasing the moof_count variable ensures that the last moof is parsed.
 
 Test method: You can use -c copy remux a fmp4 file as mp4
 and ffprobe the two files will find that the bitrate is inconsistent
 Befor patch:
 Stream #0:1[0x2](und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, 
 stereo, fltp, 59 kb/s
 After patch:
 Stream #0:1[0x2](und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, 
 stereo, fltp, 96 kb/s (default)
 
 Signed-off-by: Wang Yaqiang >>> >
 ---
 libavformat/isom.h | 1 +
 libavformat/mov.c  | 8 +++-
 2 files changed, 8 insertions(+), 1 deletion(-)
 
 diff --git a/libavformat/isom.h b/libavformat/isom.h
 index f05c2d9c28..183a3c486b 100644
 --- a/libavformat/isom.h
 +++ b/libavformat/isom.h
 @@ -296,6 +296,7 @@ typedef struct MOVContext {
  int has_looked_for_mfra;
  int use_tfdt;
  MOVFragmentIndex frag_index;
 +int moof_count; //ensure last fragment parse moof box
  int atom_depth;
  unsigned int aax_mode;  ///< 'aax' file has been detected
  uint8_t file_key[20];
 diff --git a/libavformat/mov.c b/libavformat/mov.c
 index 14550e6456..396658e342 100644
 --- a/libavformat/mov.c
 +++ b/libavformat/mov.c
 @@ -7784,12 +7784,15 @@ static int mov_read_default(MOVContext *c, 
 AVIOContext *pb, MOVAtom atom)
  int64_t start_pos = avio_tell(pb);
  int64_t left;
  int err = parse(c, pb, a);
 +if (a.type == MKTAG('m','o','o','f')) {
 +c->moof_count ++;
 +}
  if (err < 0) {
  c->atom_depth --;
  return err;
  }
  if (c->found_moov && c->found_mdat && a.size <= INT64_MAX - 
 start_pos &&
 -((!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags 
 & AVFMT_FLAG_IGNIDX || c->frag_index.complete) ||
 +((!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags 
 & AVFMT_FLAG_IGNIDX || (c->frag_index.complete && c->moof_count >= 
 c->frag_index.nb_items)) ||
   start_pos + a.size == avio_size(pb))) {
  if (!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags & 
 AVFMT_FLAG_IGNIDX || c->frag_index.complete)
  c->next_root_atom = start_pos + a.size;
>>> 
>>> No, it breaks the use case with global sidx. We can achieve fast
>>> startup with global sidx.
>> 
>> This patch indeed have an effect on startup, will add some option.
>> 
>>> 
>>> The patch describes an issue with multiple sidx cases, actually
>>> it’s more serious with global sidx. In the first case, the bitrate
>>> is a little inaccurate. Bitrate is near zero for the second case.
>>> 
>>> I have two ideas:
>>> 
>>> 1. Just skip bitrate calculation from sc->data_size if sidx exist,
>>> e.g.,
>>> 
>>> @@ -8500,7 +8500,7 @@ static int mov_read_header(AVFormatContext *s)
>>>   for (i = 0; i < s->nb_streams; i++) {
>>>   AVStream *st = s->streams[i];
>>>   MOVStreamContext *sc = st->priv_data;
>>> -if (st->duration > 0) {
>>> +if (st->duration > 0 && !sc->has_sidx) {
>>>   /* Akin to sc->data_size * 8 * sc->time_scale / st->duration 
>>> but accounting for overflows. */
>>>   st->codecpar->bit_rate = av_rescale(sc->data_size, ((int64_t) 
>>> sc->time_scale) * 8, st->duration);
>>>   if (st->codecpar->bit_rate == INT64_MIN) {
>>> 
>>> It’s simple, and bitrate information has multiple sources. 
>>> 
>> 
>> In this way, will be no bitrate info in the stream, will affect the users?
> 
> It depends. We have multiple sources to get bitrate.
> 
>> 
>>> 2. Add a option to prevent mark complete when reading sidx
>>> 
>>> @@ -5446,7 +5446,7 @@ static int mov_read_sidx(MOVContext *c, AVIOContext 
>>> *pb, MOVAtom atom)
>>>   // See if the remaining bytes are just an mfra which we can ignore.
>>>   is_complete = offset == stream_size;
>>> -if (!is_complete && (pb->seekable & AVIO_SEEKABLE_NORMAL) && 
>>> stream_size > 0 ) {
>>> +if (!is_complete && (pb->seekable & AVIO_SEE

Re: [FFmpeg-devel] [PATCH 1/1] fate/opus: add silk LBRR test (refs #9890)

2022-09-30 Thread Tristan Matthews
On Fri, Sep 23, 2022 at 3:04 PM Tristan Matthews  wrote:
>
> On Fri, Sep 23, 2022 at 8:15 AM Andreas Rheinhardt
>  wrote:
> >
> > Tristan Matthews:
> > > On Thu, Sep 8, 2022 at 3:58 PM Tristan Matthews  
> > > wrote:
> > >
> > >> This adds a fate test for a sample with LBRR packets.
> > >>
> > >> It requires that these files be uploaded:
> > >> https://people.videolan.org/~tmatth/9890-fate/silk-lbrr.mka
> > >> https://people.videolan.org/~tmatth/9890-fate/silk-lbrr.dec
> > >>
> > >> ---
> > >>  tests/fate/opus.mak | 3 ++-
> > >>  1 file changed, 2 insertions(+), 1 deletion(-)
> > >>
> > >> diff --git a/tests/fate/opus.mak b/tests/fate/opus.mak
> > >> index 573044ed15..7d359f414a 100644
> > >> --- a/tests/fate/opus.mak
> > >> +++ b/tests/fate/opus.mak
> > >> @@ -4,7 +4,7 @@
> > >>
> > >>  OPUS_CELT_SAMPLES   = $(addprefix testvector, 01 11) tron.6ch.tinypkts
> > >>  OPUS_HYBRID_SAMPLES = $(addprefix testvector, 05 06)
> > >> -OPUS_SILK_SAMPLES   = $(addprefix testvector, 02 03 04)
> > >> +OPUS_SILK_SAMPLES   = $(addprefix testvector, 02 03 04) silk-lbrr
> > >>  OPUS_OTHER_SAMPLES  = $(addprefix testvector, 07 08 09 10 12)
> > >>
> > >>  define FATE_OPUS_TEST
> > >> @@ -33,6 +33,7 @@ fate-opus-testvector09:  CMP_TARGET = 0
> > >>  fate-opus-testvector10:  CMP_TARGET = 38
> > >>  fate-opus-testvector11:  CMP_TARGET = 0
> > >>  fate-opus-testvector12:  CMP_TARGET = 160
> > >> +fate-opus-silk-lbrr: CMP_TARGET = 0
> > >>  fate-opus-tron.6ch.tinypkts: CMP_SHIFT = 1440
> > >>  fate-opus-tron.6ch.tinypkts: CMP_TARGET = 0
> > >>
> > >> --
> > >> 2.34.1
> > >>
> > >
> > >
> > > Sorry this was supposed to be in response to
> > > http://ffmpeg.org/pipermail/ffmpeg-devel/2022-August/300758.html (as it
> > > depends on it) but I screwed up the git-send-email.
> > >
> >
> > Does this sample have to be so long?
>
> I've shortened it from 4 seconds to 1 second (which is still long
> enough to hear the bug when using an older build).
> Note that most of the opus test vectors are on the order of 25 seconds.

These shorter samples have been updated by James Almer, so this patch
is good to go

Best,
-t


>
> Best,
> Tristan
>
> >
> > - Andreas
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel 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] Encrypted SMPTE DC MXF - additional UL needed to unpack EKLV packet

2022-09-30 Thread Richard Ayres
We had an issue where ffmpeg was unable to unpack the EKLV of an encrypted 3D 
SMPTE DC MXF.

The patch adds the SMPTE UL for EKLV packets 
(060e2b34.02040101.0d010301.027e0100), to mxfdec.c in order to unpack an EKLV 
packet found within an Encrypted SMPTE Digital Cinema MXF.

Signed-off-by: Richard Ayres 
---
 libavformat/mxfdec.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index badd2be224..ebd64b1c68 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -343,6 +343,7 @@ static const uint8_t mxf_apple_coll_prefix[]   
= { 0x06,0x0e,0x2b,0x
 /* complete keys to match */
 static const uint8_t mxf_crypto_source_container_ul[]  = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x02,0x02,0x00,0x00,0x00 
};
 static const uint8_t mxf_encrypted_triplet_key[]   = { 
0x06,0x0e,0x2b,0x34,0x02,0x04,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x7e,0x01,0x00 
};
+static const uint8_t mxf_encrypted_triplet_smpte_key[] = { 
0x06,0x0e,0x2b,0x34,0x02,0x04,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x7e,0x01,0x00 
};
 static const uint8_t mxf_encrypted_essence_container[] = { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0b,0x01,0x00 
};
 static const uint8_t mxf_sony_mpeg4_extradata[]= { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0e,0x06,0x06,0x02,0x02,0x01,0x00,0x00 
};
 static const uint8_t mxf_ffv1_extradata[]  = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x04,0x01,0x06,0x0c,0x01,0x00,0x00,0x00 
}; // FFV1InitializationMetadata
@@ -3738,6 +3739,7 @@ static int mxf_read_header(AVFormatContext *s)
 PRINT_KEY(s, "read header", klv.key);
 av_log(s, AV_LOG_TRACE, "size %"PRIu64" offset %#"PRIx64"\n", 
klv.length, klv.offset);
 if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key) ||
+IS_KLV_KEY(klv.key, mxf_encrypted_triplet_smpte_key) ||
 IS_KLV_KEY(klv.key, mxf_essence_element_key) ||
 IS_KLV_KEY(klv.key, mxf_canopus_essence_element_key) ||
 IS_KLV_KEY(klv.key, mxf_avid_essence_element_key) ||
@@ -3983,7 +3985,8 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 pos = klv.next_klv - klv.length;
 PRINT_KEY(s, "read packet", klv.key);
 av_log(s, AV_LOG_TRACE, "size %"PRIu64" offset %#"PRIx64"\n", 
klv.length, klv.offset);
-if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key)) {
+if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key) ||
+IS_KLV_KEY(klv.key, mxf_encrypted_triplet_smpte_key)) {
 ret = mxf_decrypt_triplet(s, pkt, &klv);
 if (ret < 0) {
 av_log(s, AV_LOG_ERROR, "invalid encoded triplet\n");
--
2.25.1

This e-mail and any attachments are intended only for use by the addressee(s) 
named herein and may contain confidential information. If you are not the 
intended recipient of this e-mail, you are hereby notified any dissemination, 
distribution or copying of this email and any attachments is strictly 
prohibited. If you receive this email in error, please immediately notify the 
sender by return email and permanently delete the original, any copy and any 
printout thereof. The integrity and security of e-mail cannot be guaranteed.
___
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/1] libswscale: force a minimum size of the slide for bayer sources

2022-09-30 Thread Anton Khirnov
Quoting Chema Gonzalez (2022-09-28 18:20:22)
> Hi,
> 
> On Wed, Sep 28, 2022 at 8:09 AM Anton Khirnov  wrote:
> > >  if (isBayer(srcFormat)) {
> > > +c->dst_slice_align = 2;
> >
> > IMO it's better to put this next to the line that sets dst_slice_align
> > for non-bayer cases, makes it clearer what the final value is.
> Are you suggesting setting `dst_slice_align` in a different function?
> 
> The way I read `ff_get_unscaled_swscale()` is that it goes through the
> quirks of all the different conversions (per source and destination
> type). In all cases, it sets the `convert_unscaled` function pointer.
> In the cases where there is the need to align (yuv2bgr and
> yuv410p_to_yuv[a]420p), it also adds `dst_slice_align`. In the same
> fashion, the conversions that affect Bayer sources are set in line
> 2097.

I suppose it depends on whether you consider the required alignment a
fundamental property of the pixel format or a specific property of the
chosen conversion kernel. My first hunch would be the former, but I
guess your argument is valid as well.

Anybody else also has an opinion? If not, I can push your patch as is.

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

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


[FFmpeg-devel] [PATCH] avcodec/dvdsub_parser: Fix length check for short packets

2022-09-30 Thread Aidan MacDonald
The DVD subtitle parser handles two types of packets: "normal"
packets with a 16-bit length, and HD-DVD packets that set the
16-bit length to 0 and encode a 32-bit length in the next four
bytes. This implies that HD-DVD packets are at least six bytes
long, but the code didn't actually verify this.

The faulty length check results in an out of bounds read for
zero-length "normal" packets that occur in the input, which are
only 2 bytes long, but get misinterpreted as an HD-DVD packet.
When this happens the parser reads packet_len from beyond the
end of the input buffer. The subtitle stream is not correctly
decoded after this point due to the garbage packet_len.

Fixing this is pretty simple: fix the length check so packets
less than 6 bytes long will not be mistakenly parsed as HD-DVD
packets.

Signed-off-by: Aidan MacDonald 
---
 libavcodec/dvdsub_parser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dvdsub_parser.c b/libavcodec/dvdsub_parser.c
index 44738a73d6..8871b6a383 100644
--- a/libavcodec/dvdsub_parser.c
+++ b/libavcodec/dvdsub_parser.c
@@ -43,7 +43,7 @@ static int dvdsub_parse(AVCodecParserContext *s,
 *poutbuf_size = buf_size;
 
 if (pc->packet_index == 0) {
-if (buf_size < 2 || AV_RB16(buf) && buf_size < 6) {
+if (buf_size < 2 || (AV_RB16(buf) == 0 && buf_size < 6)) {
 if (buf_size)
 av_log(avctx, AV_LOG_DEBUG, "Parser input %d too small\n", 
buf_size);
 return buf_size;
-- 
2.35.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] Encrypted SMPTE DC MXF - additional UL needed to unpack EKLV packet

2022-09-30 Thread Pierre-Anthony Lemieux
On Fri, Sep 30, 2022 at 7:08 AM Richard Ayres
 wrote:
>
> We had an issue where ffmpeg was unable to unpack the EKLV of an encrypted 3D 
> SMPTE DC MXF.
>
> The patch adds the SMPTE UL for EKLV packets 
> (060e2b34.02040101.0d010301.027e0100), to mxfdec.c in order to unpack an EKLV 
> packet found within an Encrypted SMPTE Digital Cinema MXF.
>
> Signed-off-by: Richard Ayres 
> ---
>  libavformat/mxfdec.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index badd2be224..ebd64b1c68 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -343,6 +343,7 @@ static const uint8_t mxf_apple_coll_prefix[]  
>  = { 0x06,0x0e,0x2b,0x
>  /* complete keys to match */
>  static const uint8_t mxf_crypto_source_container_ul[]  = { 
> 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x02,0x02,0x00,0x00,0x00
>  };
>  static const uint8_t mxf_encrypted_triplet_key[]   = { 
> 0x06,0x0e,0x2b,0x34,0x02,0x04,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x7e,0x01,0x00
>  };
> +static const uint8_t mxf_encrypted_triplet_smpte_key[] = { 
> 0x06,0x0e,0x2b,0x34,0x02,0x04,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x7e,0x01,0x00
>  };
>  static const uint8_t mxf_encrypted_essence_container[] = { 
> 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0b,0x01,0x00
>  };
>  static const uint8_t mxf_sony_mpeg4_extradata[]= { 
> 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0e,0x06,0x06,0x02,0x02,0x01,0x00,0x00
>  };
>  static const uint8_t mxf_ffv1_extradata[]  = { 
> 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x04,0x01,0x06,0x0c,0x01,0x00,0x00,0x00
>  }; // FFV1InitializationMetadata
> @@ -3738,6 +3739,7 @@ static int mxf_read_header(AVFormatContext *s)
>  PRINT_KEY(s, "read header", klv.key);
>  av_log(s, AV_LOG_TRACE, "size %"PRIu64" offset %#"PRIx64"\n", 
> klv.length, klv.offset);
>  if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key) ||
> +IS_KLV_KEY(klv.key, mxf_encrypted_triplet_smpte_key) ||

Calling one UL "mxf_encrypted_triplet_key" and the other
"mxf_encrypted_triplet_smpte_key" is misleading IMHO.

The only difference is the version byte, which should be ignored in
most, if not all, SMPTE UL comparisons.

I would instead use mxf_match_uid(), which ignores the version byte,
to compare the UL keys.


>  IS_KLV_KEY(klv.key, mxf_essence_element_key) ||
>  IS_KLV_KEY(klv.key, mxf_canopus_essence_element_key) ||
>  IS_KLV_KEY(klv.key, mxf_avid_essence_element_key) ||
> @@ -3983,7 +3985,8 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket 
> *pkt)
>  pos = klv.next_klv - klv.length;
>  PRINT_KEY(s, "read packet", klv.key);
>  av_log(s, AV_LOG_TRACE, "size %"PRIu64" offset %#"PRIx64"\n", 
> klv.length, klv.offset);
> -if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key)) {
> +if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key) ||
> +IS_KLV_KEY(klv.key, mxf_encrypted_triplet_smpte_key)) {
>  ret = mxf_decrypt_triplet(s, pkt, &klv);
>  if (ret < 0) {
>  av_log(s, AV_LOG_ERROR, "invalid encoded triplet\n");
> --
> 2.25.1
>
> This e-mail and any attachments are intended only for use by the addressee(s) 
> named herein and may contain confidential information. If you are not the 
> intended recipient of this e-mail, you are hereby notified any dissemination, 
> distribution or copying of this email and any attachments is strictly 
> prohibited. If you receive this email in error, please immediately notify the 
> sender by return email and permanently delete the original, any copy and any 
> printout thereof. The integrity and security of e-mail cannot be guaranteed.
> ___
> 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] lavc/opusdsp: RISC-V F deemphasis

2022-09-30 Thread Rémi Denis-Courmont
Le torstaina 29. syyskuuta 2022, 22.51.59 EEST r...@remlab.net a écrit :
> From: Rémi Denis-Courmont 
> 
> This saves almost exactly 25% on SiFive U74.
> 
> deemphasis_c: 11536.2
> deemphasis_rvf: 8654.2

One can get the same result with the C version using -ffast-math.
Forget this patch.

-- 
雷米‧德尼-库尔蒙
http://www.remlab.net/



___
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/7] avcodec/sunrast: Use ptrdiff_t for stride

2022-09-30 Thread Andreas Rheinhardt
Fixes segfaults with negative linesizes; in particular,
this affected the sunraster-(1|8|24)bit-(raw|rle) and
sunraster-8bit_gray-raw FATE tests.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/sunrast.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/sunrast.c b/libavcodec/sunrast.c
index 77feef06e1..45b29e4d72 100644
--- a/libavcodec/sunrast.c
+++ b/libavcodec/sunrast.c
@@ -31,7 +31,8 @@ static int sunrast_decode_frame(AVCodecContext *avctx, 
AVFrame *p,
 {
 const uint8_t *buf   = avpkt->data;
 const uint8_t *buf_end   = avpkt->data + avpkt->size;
-unsigned int w, h, depth, type, maptype, maplength, stride, x, y, len, 
alen;
+unsigned int w, h, depth, type, maptype, maplength, x, y, len, alen;
+ptrdiff_t stride;
 uint8_t *ptr, *ptr2 = NULL;
 const uint8_t *bufstart = buf;
 int ret;
@@ -141,7 +142,7 @@ static int sunrast_decode_frame(AVCodecContext *avctx, 
AVFrame *p,
 
 if (type == RT_BYTE_ENCODED) {
 int value, run;
-uint8_t *end = ptr + h * stride;
+uint8_t *end = ptr + (ptrdiff_t)h * stride;
 
 x = 0;
 while (ptr != end && buf < buf_end) {
-- 
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] tests/fate/truehd: Add test for shortened Ticket1726 tesetcase

2022-09-30 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 tests/fate/truehd.mak | 5 +
 1 file changed, 5 insertions(+)

diff --git a/tests/fate/truehd.mak b/tests/fate/truehd.mak
index 7da8c93cffd..2a9e94b1cc8 100644
--- a/tests/fate/truehd.mak
+++ b/tests/fate/truehd.mak
@@ -13,5 +13,10 @@ fate-truehd-core-bsf: CMD = md5pipe -i 
$(TARGET_SAMPLES)/truehd/atmos.thd -c:a c
 fate-truehd-core-bsf: CMP = oneline
 fate-truehd-core-bsf: REF = 3aa5d0c7825051f3657b71fd6135183b
 
+FATE_TRUEHD-$(call DEMDEC, TRUEHD, TRUEHD) += fate-truehd-mono1726
+fate-truehd-mono1726: CMD = md5pipe -f truehd -i 
$(TARGET_SAMPLES)/truehd/ticket-1726-monocut.thd -f s32le
+fate-truehd-mono1726: CMP = oneline
+fate-truehd-mono1726: REF = 9be9551fac418440bb02101bfdb11df9
+
 FATE_SAMPLES_AUDIO += $(FATE_TRUEHD-yes)
 fate-truehd: $(FATE_TRUEHD-yes)
-- 
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 2/7] avcodec/sgidec: Support negative linesizes

2022-09-30 Thread Andreas Rheinhardt
The earlier code used "p->data[0] + p->linesize[0] * s->height" with
the latter being unsigned, which gives the wrong value for negative
linesizes. There is also a not so obvious problem with this:
In case of negative linesizes, the last line is the start of
the allocated buffer, so using the line after the last line
would involve undefined pointer arithmetic. So don't do it.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/sgidec.c | 21 +++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/libavcodec/sgidec.c b/libavcodec/sgidec.c
index dd3dc46b48..a449859bf8 100644
--- a/libavcodec/sgidec.c
+++ b/libavcodec/sgidec.c
@@ -28,7 +28,7 @@
 typedef struct SgiState {
 AVCodecContext *avctx;
 unsigned int width;
-unsigned int height;
+int height;
 unsigned int depth;
 unsigned int bytes_per_channel;
 int linesize;
@@ -127,12 +127,11 @@ static int expand_rle_row16(SgiState *s, uint16_t 
*out_buf,
  * @param s the current image state
  * @return 0 if no error, else return error code.
  */
-static int read_rle_sgi(uint8_t *out_buf, SgiState *s)
+static int read_rle_sgi(uint8_t *last_line, SgiState *s)
 {
 uint8_t *dest_row;
 unsigned int len = s->height * s->depth * 4;
 GetByteContext g_table = s->g;
-unsigned int y, z;
 unsigned int start_offset;
 int linesize, ret;
 
@@ -141,11 +140,10 @@ static int read_rle_sgi(uint8_t *out_buf, SgiState *s)
 return AVERROR_INVALIDDATA;
 }
 
-for (z = 0; z < s->depth; z++) {
-dest_row = out_buf;
-for (y = 0; y < s->height; y++) {
+for (unsigned z = 0; z < s->depth; z++) {
+dest_row = last_line;
+for (int remaining_lines = s->height;;) {
 linesize = s->width * s->depth;
-dest_row -= s->linesize;
 start_offset = bytestream2_get_be32(&g_table);
 bytestream2_seek(&s->g, start_offset, SEEK_SET);
 if (s->bytes_per_channel == 1)
@@ -154,6 +152,9 @@ static int read_rle_sgi(uint8_t *out_buf, SgiState *s)
 ret = expand_rle_row16(s, (uint16_t *)dest_row + z, linesize, 
s->depth);
 if (ret != s->width)
 return AVERROR_INVALIDDATA;
+if (--remaining_lines == 0)
+break;
+dest_row -= s->linesize;
 }
 }
 return 0;
@@ -204,7 +205,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
 SgiState *s = avctx->priv_data;
 unsigned int dimension, rle;
 int ret = 0;
-uint8_t *out_buf, *out_end;
+uint8_t *out_buf, *last_line;
 
 bytestream2_init(&s->g, avpkt->data, avpkt->size);
 if (bytestream2_get_bytes_left(&s->g) < SGI_HEADER_SIZE) {
@@ -258,14 +259,14 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
 p->key_frame = 1;
 out_buf = p->data[0];
 
-out_end = out_buf + p->linesize[0] * s->height;
+last_line = out_buf + p->linesize[0] * (s->height - 1);
 
 s->linesize = p->linesize[0];
 
 /* Skip header. */
 bytestream2_seek(&s->g, SGI_HEADER_SIZE, SEEK_SET);
 if (rle) {
-ret = read_rle_sgi(out_end, s);
+ret = read_rle_sgi(last_line, s);
 } else {
 ret = read_uncompressed_sgi(out_buf, s);
 }
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 3/7] avcodec/sgidec: Avoid redundant private context

2022-09-30 Thread Andreas Rheinhardt
SGI is intra-frame only; the decoder therefore does not
maintain any state between frames, so remove
the private context.

Also rename depth to nb_components.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/sgidec.c | 158 
 1 file changed, 73 insertions(+), 85 deletions(-)

diff --git a/libavcodec/sgidec.c b/libavcodec/sgidec.c
index a449859bf8..bd49a3510d 100644
--- a/libavcodec/sgidec.c
+++ b/libavcodec/sgidec.c
@@ -25,25 +25,17 @@
 #include "decode.h"
 #include "sgi.h"
 
-typedef struct SgiState {
-AVCodecContext *avctx;
-unsigned int width;
-int height;
-unsigned int depth;
-unsigned int bytes_per_channel;
-int linesize;
-GetByteContext g;
-} SgiState;
-
 /**
  * Expand an RLE row into a channel.
- * @param s the current image state
+ * @param logctx a logcontext
  * @param out_buf Points to one line after the output buffer.
+ * @param g   GetByteContext used to read input from
  * @param len length of out_buf in bytes
  * @param pixelstride pixel stride of input buffer
  * @return size of output in bytes, else return error code.
  */
-static int expand_rle_row8(SgiState *s, uint8_t *out_buf,
+static int expand_rle_row8(void *logctx, uint8_t *out_buf,
+   GetByteContext *g,
int len, int pixelstride)
 {
 unsigned char pixel, count;
@@ -51,26 +43,26 @@ static int expand_rle_row8(SgiState *s, uint8_t *out_buf,
 uint8_t *out_end = out_buf + len;
 
 while (out_buf < out_end) {
-if (bytestream2_get_bytes_left(&s->g) < 1)
+if (bytestream2_get_bytes_left(g) < 1)
 return AVERROR_INVALIDDATA;
-pixel = bytestream2_get_byteu(&s->g);
+pixel = bytestream2_get_byteu(g);
 if (!(count = (pixel & 0x7f))) {
 break;
 }
 
 /* Check for buffer overflow. */
 if (out_end - out_buf <= pixelstride * (count - 1)) {
-av_log(s->avctx, AV_LOG_ERROR, "Invalid pixel count.\n");
+av_log(logctx, AV_LOG_ERROR, "Invalid pixel count.\n");
 return AVERROR_INVALIDDATA;
 }
 
 if (pixel & 0x80) {
 while (count--) {
-*out_buf = bytestream2_get_byte(&s->g);
+*out_buf = bytestream2_get_byte(g);
 out_buf += pixelstride;
 }
 } else {
-pixel = bytestream2_get_byte(&s->g);
+pixel = bytestream2_get_byte(g);
 
 while (count--) {
 *out_buf = pixel;
@@ -81,7 +73,8 @@ static int expand_rle_row8(SgiState *s, uint8_t *out_buf,
 return (out_buf - orig) / pixelstride;
 }
 
-static int expand_rle_row16(SgiState *s, uint16_t *out_buf,
+static int expand_rle_row16(void *logctx, uint16_t *out_buf,
+GetByteContext *g,
 int len, int pixelstride)
 {
 unsigned short pixel;
@@ -90,26 +83,26 @@ static int expand_rle_row16(SgiState *s, uint16_t *out_buf,
 uint16_t *out_end = out_buf + len;
 
 while (out_buf < out_end) {
-if (bytestream2_get_bytes_left(&s->g) < 2)
+if (bytestream2_get_bytes_left(g) < 2)
 return AVERROR_INVALIDDATA;
-pixel = bytestream2_get_be16u(&s->g);
+pixel = bytestream2_get_be16u(g);
 if (!(count = (pixel & 0x7f)))
 break;
 
 /* Check for buffer overflow. */
 if (out_end - out_buf <= pixelstride * (count - 1)) {
-av_log(s->avctx, AV_LOG_ERROR, "Invalid pixel count.\n");
+av_log(logctx, AV_LOG_ERROR, "Invalid pixel count.\n");
 return AVERROR_INVALIDDATA;
 }
 
 if (pixel & 0x80) {
 while (count--) {
-pixel = bytestream2_get_ne16(&s->g);
+pixel = bytestream2_get_ne16(g);
 AV_WN16A(out_buf, pixel);
 out_buf += pixelstride;
 }
 } else {
-pixel = bytestream2_get_ne16(&s->g);
+pixel = bytestream2_get_ne16(g);
 
 while (count--) {
 AV_WN16A(out_buf, pixel);
@@ -127,34 +120,38 @@ static int expand_rle_row16(SgiState *s, uint16_t 
*out_buf,
  * @param s the current image state
  * @return 0 if no error, else return error code.
  */
-static int read_rle_sgi(uint8_t *last_line, SgiState *s)
+static int read_rle_sgi(void *logctx, uint8_t *last_line, GetByteContext *g,
+ptrdiff_t stride, unsigned width, unsigned height,
+unsigned nb_components, unsigned bytes_per_channel)
 {
 uint8_t *dest_row;
-unsigned int len = s->height * s->depth * 4;
-GetByteContext g_table = s->g;
+unsigned int len = height * nb_components * 4;
+GetByteContext g_table = *g;
 unsigned int start_offset;
 int linesize, ret;
 
 /* size of  RLE offset and length tables */
-if (len * 2 > bytestream2_get_bytes_left(&s->g)) {
+if (len * 2 > bytestream2_get_byte

[FFmpeg-devel] [PATCH 4/7] avcodec/sgidec: Use planar pixel formats

2022-09-30 Thread Andreas Rheinhardt
The data in SGI images is stored planar, so exporting
it via planar pixel formats is natural.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/sgidec.c   | 123 --
 tests/ref/fate/sgi-rgb24  |   2 +-
 tests/ref/fate/sgi-rgb24-rle  |   2 +-
 tests/ref/fate/sgi-rgb48  |   2 +-
 tests/ref/fate/sgi-rgb48-rle  |   2 +-
 tests/ref/fate/sgi-rgba   |   2 +-
 tests/ref/fate/sgi-rgba-rle   |   2 +-
 tests/ref/fate/sgi-rgba64 |   2 +-
 tests/ref/fate/sgi-rgba64-rle |   2 +-
 tests/ref/lavf/sgi|   2 +-
 10 files changed, 66 insertions(+), 75 deletions(-)

diff --git a/libavcodec/sgidec.c b/libavcodec/sgidec.c
index bd49a3510d..6ff2ee97f6 100644
--- a/libavcodec/sgidec.c
+++ b/libavcodec/sgidec.c
@@ -30,17 +30,15 @@
  * @param logctx a logcontext
  * @param out_buf Points to one line after the output buffer.
  * @param g   GetByteContext used to read input from
- * @param len length of out_buf in bytes
- * @param pixelstride pixel stride of input buffer
- * @return size of output in bytes, else return error code.
+ * @param width length of out_buf in nb of elements
+ * @return nb of elements written, else return error code.
  */
 static int expand_rle_row8(void *logctx, uint8_t *out_buf,
-   GetByteContext *g,
-   int len, int pixelstride)
+   GetByteContext *g, unsigned width)
 {
 unsigned char pixel, count;
 unsigned char *orig = out_buf;
-uint8_t *out_end = out_buf + len;
+uint8_t *out_end = out_buf + width;
 
 while (out_buf < out_end) {
 if (bytestream2_get_bytes_left(g) < 1)
@@ -51,36 +49,31 @@ static int expand_rle_row8(void *logctx, uint8_t *out_buf,
 }
 
 /* Check for buffer overflow. */
-if (out_end - out_buf <= pixelstride * (count - 1)) {
+if (out_end - out_buf < count) {
 av_log(logctx, AV_LOG_ERROR, "Invalid pixel count.\n");
 return AVERROR_INVALIDDATA;
 }
 
 if (pixel & 0x80) {
-while (count--) {
-*out_buf = bytestream2_get_byte(g);
-out_buf += pixelstride;
-}
+while (count--)
+*out_buf++ = bytestream2_get_byte(g);
 } else {
 pixel = bytestream2_get_byte(g);
 
-while (count--) {
-*out_buf = pixel;
-out_buf += pixelstride;
-}
+while (count--)
+*out_buf++ = pixel;
 }
 }
-return (out_buf - orig) / pixelstride;
+return out_buf - orig;
 }
 
 static int expand_rle_row16(void *logctx, uint16_t *out_buf,
-GetByteContext *g,
-int len, int pixelstride)
+GetByteContext *g, unsigned width)
 {
 unsigned short pixel;
 unsigned char count;
 unsigned short *orig = out_buf;
-uint16_t *out_end = out_buf + len;
+uint16_t *out_end = out_buf + width;
 
 while (out_buf < out_end) {
 if (bytestream2_get_bytes_left(g) < 2)
@@ -90,7 +83,7 @@ static int expand_rle_row16(void *logctx, uint16_t *out_buf,
 break;
 
 /* Check for buffer overflow. */
-if (out_end - out_buf <= pixelstride * (count - 1)) {
+if (out_end - out_buf < count) {
 av_log(logctx, AV_LOG_ERROR, "Invalid pixel count.\n");
 return AVERROR_INVALIDDATA;
 }
@@ -99,18 +92,18 @@ static int expand_rle_row16(void *logctx, uint16_t *out_buf,
 while (count--) {
 pixel = bytestream2_get_ne16(g);
 AV_WN16A(out_buf, pixel);
-out_buf += pixelstride;
+out_buf++;
 }
 } else {
 pixel = bytestream2_get_ne16(g);
 
 while (count--) {
 AV_WN16A(out_buf, pixel);
-out_buf += pixelstride;
+out_buf++;
 }
 }
 }
-return (out_buf - orig) / pixelstride;
+return out_buf - orig;
 }
 
 
@@ -120,15 +113,14 @@ static int expand_rle_row16(void *logctx, uint16_t 
*out_buf,
  * @param s the current image state
  * @return 0 if no error, else return error code.
  */
-static int read_rle_sgi(void *logctx, uint8_t *last_line, GetByteContext *g,
-ptrdiff_t stride, unsigned width, unsigned height,
+static int read_rle_sgi(void *logctx, uint8_t *out[4], ptrdiff_t stride[4],
+GetByteContext *g, unsigned width, int height,
 unsigned nb_components, unsigned bytes_per_channel)
 {
-uint8_t *dest_row;
 unsigned int len = height * nb_components * 4;
 GetByteContext g_table = *g;
 unsigned int start_offset;
-int linesize, ret;
+int ret;
 
 /* size of  RLE offset and length tables */
 if (len * 2 > bytestream2_get_bytes_left(g)) {
@@ -136,22 +128,19 @@ static int read_rle_sgi(void *logctx, uin

[FFmpeg-devel] [PATCH 5/7] avcodec/c93: Fix segfault when using negative linesizes

2022-09-30 Thread Andreas Rheinhardt
c93.c used an int for the stride and an unsigned for the current
linenumber. This does not work when using negative linesizes.
So use ptrdiff_t for stride and int for linenumber.

This fixes the cyberia-c93 FATE test when using negative linesizes.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/c93.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavcodec/c93.c b/libavcodec/c93.c
index 66b551a5d6..bfcbc7c150 100644
--- a/libavcodec/c93.c
+++ b/libavcodec/c93.c
@@ -130,7 +130,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 AVFrame * const oldpic = c93->pictures[c93->currentpic^1];
 GetByteContext gb;
 uint8_t *out;
-int stride, ret, i, x, y, b, bt = 0;
+int ret, i, x, y, b, bt = 0;
+ptrdiff_t stride;
 
 if ((ret = ff_set_dimensions(avctx, WIDTH, HEIGHT)) < 0)
 return ret;
@@ -156,7 +157,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 out = newpic->data[0] + y * stride;
 for (x = 0; x < WIDTH; x += 8) {
 uint8_t *copy_from = oldpic->data[0];
-unsigned int offset, j;
 uint8_t cols[4], grps[4];
 C93BlockType block_type;
 
@@ -165,16 +165,17 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 
 block_type= bt & 0x0F;
 switch (block_type) {
-case C93_8X8_FROM_PREV:
-offset = bytestream2_get_le16(&gb);
+case C93_8X8_FROM_PREV: {
+int offset = bytestream2_get_le16(&gb);
 if ((ret = copy_block(avctx, out, copy_from, offset, 8, 
stride)) < 0)
 return ret;
 break;
+}
 
 case C93_4X4_FROM_CURR:
 copy_from = newpic->data[0];
 case C93_4X4_FROM_PREV:
-for (j = 0; j < 8; j += 4) {
+for (int j = 0; j < 8; j += 4) {
 for (i = 0; i < 8; i += 4) {
 int offset = bytestream2_get_le16(&gb);
 int from_x = offset % WIDTH;
@@ -203,7 +204,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 case C93_4X4_2COLOR:
 case C93_4X4_4COLOR:
 case C93_4X4_4COLOR_GRP:
-for (j = 0; j < 8; j += 4) {
+for (int j = 0; j < 8; j += 4) {
 for (i = 0; i < 8; i += 4) {
 if (block_type == C93_4X4_2COLOR) {
 bytestream2_get_buffer(&gb, cols, 2);
@@ -226,7 +227,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 break;
 
 case C93_8X8_INTRA:
-for (j = 0; j < 8; j++)
+for (int j = 0; j < 8; j++)
 bytestream2_get_buffer(&gb, out + j*stride, 8);
 break;
 
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 6/7] avcodec/escape124: Fix segfault with negative linesizes

2022-09-30 Thread Andreas Rheinhardt
Use ptrdiff_t instead of unsigned for linesizes.
Fixes the armovie-escape124 FATE test with negative linesizes.

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

diff --git a/libavcodec/escape124.c b/libavcodec/escape124.c
index eeeb9bb0f7..024eec59ce 100644
--- a/libavcodec/escape124.c
+++ b/libavcodec/escape124.c
@@ -178,8 +178,8 @@ static void insert_mb_into_sb(SuperBlock* sb, MacroBlock 
mb, unsigned index) {
dst[4] = mb.pixels32[1];
 }
 
-static void copy_superblock(uint16_t* dest, unsigned dest_stride,
-uint16_t* src, unsigned src_stride)
+static void copy_superblock(uint16_t* dest, ptrdiff_t dest_stride,
+uint16_t* src,  ptrdiff_t src_stride)
 {
 unsigned y;
 if (src)
@@ -211,7 +211,7 @@ static int escape124_decode_frame(AVCodecContext *avctx, 
AVFrame *frame,
  superblocks_per_row = avctx->width / 8, skip = -1;
 
 uint16_t* old_frame_data, *new_frame_data;
-unsigned old_stride, new_stride;
+ptrdiff_t old_stride, new_stride;
 
 int ret;
 
-- 
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 7/7] avcodec/fraps: Fix segfault with negative linesizes

2022-09-30 Thread Andreas Rheinhardt
Using unsigned and negative linesizes doesn't really work.
Use ptrdiff_t instead. This fixes the fraps-v0 and fraps-v1
FATE tests with negative linesizes.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/fraps.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/libavcodec/fraps.c b/libavcodec/fraps.c
index 9c8cbf7323..4c4c46b602 100644
--- a/libavcodec/fraps.c
+++ b/libavcodec/fraps.c
@@ -141,7 +141,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *f,
 int buf_size   = avpkt->size;
 uint32_t header;
 unsigned int version,header_size;
-unsigned int x, y;
 const uint32_t *buf32;
 uint32_t *luma1,*luma2,*cb,*cr;
 uint32_t offs[4];
@@ -238,12 +237,12 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *f,
 }
 
 buf32 = (const uint32_t*)buf;
-for (y = 0; y < avctx->height / 2; y++) {
+for (ptrdiff_t y = 0; y < avctx->height / 2; y++) {
 luma1 = (uint32_t*)&f->data[0][  y * 2  * f->linesize[0] ];
 luma2 = (uint32_t*)&f->data[0][ (y * 2 + 1) * f->linesize[0] ];
 cr= (uint32_t*)&f->data[1][  y  * f->linesize[1] ];
 cb= (uint32_t*)&f->data[2][  y  * f->linesize[2] ];
-for (x = 0; x < avctx->width; x += 8) {
+for (ptrdiff_t x = 0; x < avctx->width; x += 8) {
 *luma1++ = *buf32++;
 *luma1++ = *buf32++;
 *luma2++ = *buf32++;
@@ -258,18 +257,18 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *f,
 if (is_pal) {
 uint32_t *pal = (uint32_t *)f->data[1];
 
-for (y = 0; y < 256; y++) {
+for (unsigned y = 0; y < 256; y++) {
 pal[y] = AV_RL32(buf) | 0xFF00;
 buf += 4;
 }
 
-for (y = 0; y height; y++)
+for (ptrdiff_t y = 0; y < avctx->height; y++)
 memcpy(&f->data[0][y * f->linesize[0]],
&buf[y * avctx->width],
avctx->width);
 } else {
 /* Fraps v1 is an upside-down BGR24 */
-for (y = 0; yheight; y++)
+for (ptrdiff_t y = 0; y < avctx->height; y++)
 memcpy(&f->data[0][(avctx->height - y - 1) * f->linesize[0]],
&buf[y * avctx->width * 3],
3 * avctx->width);
-- 
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] avcodec/mjpegdec: Fix compilation

2022-09-30 Thread Andreas Rheinhardt
Regression since 9a494b82d998823d0de68cb6b8db83cc451d1781.

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

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 85d1129f30..3374ae71bd 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -596,7 +596,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
 case 0x1400:
 case 0x22211100:
 case 0x22112100:
-if (s->component_id[0] == 'R' && s->component_id[1] == 'G' && 
s->component_id[B] == 'B') {
+if (s->component_id[0] == 'R' && s->component_id[1] == 'G' && 
s->component_id[2] == 'B') {
 if (s->bits <= 8) s->avctx->pix_fmt = AV_PIX_FMT_GBRP;
 else
 goto unk_pixfmt;
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH 3/3] avcodec/mlpdec: add max channels check

2022-09-30 Thread Michael Niedermayer
On Fri, Sep 30, 2022 at 10:00:57AM +0200, Paul B Mahol wrote:
> On 9/30/22, Michael Niedermayer  wrote:
> > Fixes: out of array access
> > Fixes:
> > 51648/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TRUEHD_fuzzer-4644322217164800
> >
> 
> 
> Make sure that this "fix"
> does not break Mono.thd decoding.
> The sample is on trac ticket.

i have tested Mono.thd before posting the patch

thx

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

Dictatorship: All citizens are under surveillance, all their steps and
actions recorded, for the politicians to enforce control.
Democracy: All politicians are under surveillance, all their steps and
actions recorded, for the citizens to enforce control.


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] avcodec/mjpegdec: Fix compilation

2022-09-30 Thread James Almer

On 9/30/2022 2:23 PM, Andreas Rheinhardt wrote:

Regression since 9a494b82d998823d0de68cb6b8db83cc451d1781.

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

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 85d1129f30..3374ae71bd 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -596,7 +596,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
  case 0x1400:
  case 0x22211100:
  case 0x22112100:
-if (s->component_id[0] == 'R' && s->component_id[1] == 'G' && 
s->component_id[B] == 'B') {
+if (s->component_id[0] == 'R' && s->component_id[1] == 'G' && 
s->component_id[2] == 'B') {
  if (s->bits <= 8) s->avctx->pix_fmt = AV_PIX_FMT_GBRP;
  else
  goto unk_pixfmt;


LGTM, so please push.
___
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] tests/fate/truehd: Add test for shortened Ticket1726 tesetcase

2022-09-30 Thread Michael Niedermayer
On Fri, Sep 30, 2022 at 07:03:07PM +0200, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer 
> ---
>  tests/fate/truehd.mak | 5 +
>  1 file changed, 5 insertions(+)

will apply this, more tests are always good


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

Into a blind darkness they enter who follow after the Ignorance,
they as if into a greater darkness enter who devote themselves
to the Knowledge alone. -- Isha Upanishad


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] [crop support for matroska demuxer 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters.

2022-09-30 Thread OvchinnikovDmitrii
---
 libavcodec/avcodec.h   | 8 
 libavcodec/codec_par.h | 8 
 2 files changed, 16 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 7365eb5cc0..66df571afc 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -585,6 +585,14 @@ typedef struct AVCodecContext {
  */
 int coded_width, coded_height;
 
+/**
+ * The dimensions of the crop, usually from container.
+ */
+int crop_top;
+int crop_left;
+int crop_bottom;
+int crop_right;
+
 /**
  * the number of pictures in a group of pictures, or 0 for intra_only
  * - encoding: Set by user.
diff --git a/libavcodec/codec_par.h b/libavcodec/codec_par.h
index 7660791a12..c730a79957 100644
--- a/libavcodec/codec_par.h
+++ b/libavcodec/codec_par.h
@@ -210,6 +210,14 @@ typedef struct AVCodecParameters {
  * Audio only. The channel layout and number of channels.
  */
 AVChannelLayout ch_layout;
+
+/**
+ * The dimensions of the crop, usually from container.
+ */
+int crop_top;
+int crop_left;
+int crop_bottom;
+int crop_right;
 } AVCodecParameters;
 
 /**
-- 
2.30.0.windows.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] [crop support for matroska demuxer 2/3] libavcodec: Public code to support container crop

2022-09-30 Thread OvchinnikovDmitrii
Support both simple and receive_frame api
The container crop information is applied additional to frame crop information
---
 libavcodec/codec_par.c |  8 
 libavcodec/decode.c| 20 
 2 files changed, 28 insertions(+)

diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c
index abda649aa8..f74964a817 100644
--- a/libavcodec/codec_par.c
+++ b/libavcodec/codec_par.c
@@ -118,6 +118,10 @@ int avcodec_parameters_from_context(AVCodecParameters *par,
 par->format  = codec->pix_fmt;
 par->width   = codec->width;
 par->height  = codec->height;
+par->crop_top   = codec->crop_top;
+par->crop_left  = codec->crop_left;
+par->crop_bottom= codec->crop_bottom;
+par->crop_right = codec->crop_right;
 par->field_order = codec->field_order;
 par->color_range = codec->color_range;
 par->color_primaries = codec->color_primaries;
@@ -199,6 +203,10 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
 codec->pix_fmt= par->format;
 codec->width  = par->width;
 codec->height = par->height;
+codec->crop_top   = par->crop_top;
+codec->crop_left  = par->crop_left;
+codec->crop_bottom= par->crop_bottom;
+codec->crop_right = par->crop_right;
 codec->field_order= par->field_order;
 codec->color_range= par->color_range;
 codec->color_primaries= par->color_primaries;
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6be2d3d6ed..548225c904 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -324,6 +324,16 @@ static inline int decode_simple_internal(AVCodecContext 
*avctx, AVFrame *frame,
 emms_c();
 actual_got_frame = got_frame;
 
+/* crop for simple api mode. apply additional container crop info to frame 
*/
+if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
+if (avctx->crop_top != 0 || avctx->crop_left != 0 || avctx->crop_right 
!= 0 || avctx->crop_bottom != 0){
+frame->crop_top+= avctx->crop_top;
+frame->crop_left   += avctx->crop_left;
+frame->crop_right  += avctx->crop_right;
+frame->crop_bottom += avctx->crop_bottom;
+}
+}
+
 if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
 if (frame->flags & AV_FRAME_FLAG_DISCARD)
 got_frame = 0;
@@ -707,6 +717,16 @@ int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame 
*frame)
 
 if (avci->buffer_frame->buf[0]) {
 av_frame_move_ref(frame, avci->buffer_frame);
+
+/* crop for receive_frame api mode. apply additional container crop 
info to frame */
+if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
+if (avctx->crop_top != 0 || avctx->crop_left != 0 || 
avctx->crop_right != 0 || avctx->crop_bottom != 0){
+frame->crop_top+= avctx->crop_top;
+frame->crop_left   += avctx->crop_left;
+frame->crop_right  += avctx->crop_right;
+frame->crop_bottom += avctx->crop_bottom;
+}
+}
 } else {
 ret = decode_receive_frame_internal(avctx, frame);
 if (ret < 0)
-- 
2.30.0.windows.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] [crop support for matroska demuxer 3/3] libavformat\matroskadec.c: crop support for matroska demuxer.

2022-09-30 Thread OvchinnikovDmitrii
In webm specification, it supports cropping information. 
(https://www.webmproject.org/docs/container/)
In ffmpeg, the implementation of webm is a subset of matroska. In 
matroskadec.c, those cropping related four fields are forced to 0.

for the sample file with crop (crop_bottom =8, crop_top=crop_left=crop_right=0.)
ffmpeg.exe -i  test_with_container_crop.webm -pix_fmt yuv420p -y output.yuv

original ffmpeg code - the output.yuv resolution is 1920x1088
changed code - the output.yuv resolution is 1920x1080"
---
 libavformat/matroskadec.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index d582f566a2..e7b00cdbe6 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -210,6 +210,10 @@ typedef struct MatroskaTrackVideo {
 uint64_t pixel_width;
 uint64_t pixel_height;
 EbmlBin  color_space;
+uint64_t pixel_cropt;
+uint64_t pixel_cropl;
+uint64_t pixel_cropb;
+uint64_t pixel_cropr;
 uint64_t display_unit;
 uint64_t interlaced;
 uint64_t field_order;
@@ -517,10 +521,10 @@ static EbmlSyntax matroska_track_video[] = {
 { MATROSKA_ID_VIDEOALPHAMODE,  EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, alpha_mode), { .u = 0 } },
 { MATROSKA_ID_VIDEOCOLOR,  EBML_NEST,  0, 
sizeof(MatroskaTrackVideoColor), offsetof(MatroskaTrackVideo, color), { .n = 
matroska_track_video_color } },
 { MATROSKA_ID_VIDEOPROJECTION, EBML_NEST,  0, 0, 
offsetof(MatroskaTrackVideo, projection), { .n = 
matroska_track_video_projection } },
-{ MATROSKA_ID_VIDEOPIXELCROPB, EBML_NONE },
-{ MATROSKA_ID_VIDEOPIXELCROPT, EBML_NONE },
-{ MATROSKA_ID_VIDEOPIXELCROPL, EBML_NONE },
-{ MATROSKA_ID_VIDEOPIXELCROPR, EBML_NONE },
+{ MATROSKA_ID_VIDEOPIXELCROPT, EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, pixel_cropt), {.u = 0 } },
+{ MATROSKA_ID_VIDEOPIXELCROPL, EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, pixel_cropl), {.u = 0 } },
+{ MATROSKA_ID_VIDEOPIXELCROPB, EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, pixel_cropb), {.u = 0 } },
+{ MATROSKA_ID_VIDEOPIXELCROPR, EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, pixel_cropr), {.u = 0 } },
 { MATROSKA_ID_VIDEODISPLAYUNIT,EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, display_unit), { .u= 
MATROSKA_VIDEO_DISPLAYUNIT_PIXELS } },
 { MATROSKA_ID_VIDEOFLAGINTERLACED, EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, interlaced),  { .u = 
MATROSKA_VIDEO_INTERLACE_FLAG_UNDETERMINED } },
 { MATROSKA_ID_VIDEOFIELDORDER, EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, field_order), { .u = 
MATROSKA_VIDEO_FIELDORDER_UNDETERMINED } },
@@ -2879,6 +2883,11 @@ static int matroska_parse_tracks(AVFormatContext *s)
 st->codecpar->width  = track->video.pixel_width;
 st->codecpar->height = track->video.pixel_height;
 
+st->codecpar->crop_top   = track->video.pixel_cropt;
+st->codecpar->crop_left  = track->video.pixel_cropl;
+st->codecpar->crop_bottom= track->video.pixel_cropb;
+st->codecpar->crop_right = track->video.pixel_cropr;
+
 if (track->video.interlaced == 
MATROSKA_VIDEO_INTERLACE_FLAG_INTERLACED)
 st->codecpar->field_order = mkv_field_order(matroska, 
track->video.field_order);
 else if (track->video.interlaced == 
MATROSKA_VIDEO_INTERLACE_FLAG_PROGRESSIVE)
-- 
2.30.0.windows.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] libavformat\matroskadec.c: crop support for matroska demuxer.

2022-09-30 Thread Dmitrii Ovchinnikov
I fixed issues1-4 and sent an updated version:
https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=7668
___
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".