[FFmpeg-cvslog] aacenc: remove ANMR coder

2025-02-26 Thread Lynne
ffmpeg | branch: master | Lynne  | Sat Feb  8 05:22:16 2025 
+0100| [b3d73df80d722ca329a2747ac5dba4476bd82e99] | committer: Lynne

aacenc: remove ANMR coder

If there's ever a rework of the AAC encoder, it won't start from here.
The codec, with all its oddities and tweaks needed to acheive good quality
has strayed far from the academic work upon which this coder was based on.
Its been 20 years since this paper was released, and no known existing
implementations, open-source or proprietary that we know of, are based on it.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b3d73df80d722ca329a2747ac5dba4476bd82e99
---

 libavcodec/aaccoder.c | 287 --
 libavcodec/aacenc.c   |   7 --
 libavcodec/aacenc.h   |   1 -
 3 files changed, 295 deletions(-)

diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index 478eda86f3..96915c9731 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -292,120 +292,6 @@ typedef struct BandCodingPath {
 int run;
 } BandCodingPath;
 
-/**
- * Encode band info for single window group bands.
- */
-static void encode_window_bands_info(AACEncContext *s, SingleChannelElement 
*sce,
- int win, int group_len, const float 
lambda)
-{
-BandCodingPath path[120][CB_TOT_ALL];
-int w, swb, cb, start, size;
-int i, j;
-const int max_sfb  = sce->ics.max_sfb;
-const int run_bits = sce->ics.num_windows == 1 ? 5 : 3;
-const int run_esc  = (1 << run_bits) - 1;
-int idx, ppos, count;
-int stackrun[120], stackcb[120], stack_len;
-float next_minrd = INFINITY;
-int next_mincb = 0;
-
-s->aacdsp.abs_pow34(s->scoefs, sce->coeffs, 1024);
-start = win*128;
-for (cb = 0; cb < CB_TOT_ALL; cb++) {
-path[0][cb].cost = 0.0f;
-path[0][cb].prev_idx = -1;
-path[0][cb].run  = 0;
-}
-for (swb = 0; swb < max_sfb; swb++) {
-size = sce->ics.swb_sizes[swb];
-if (sce->zeroes[win*16 + swb]) {
-for (cb = 0; cb < CB_TOT_ALL; cb++) {
-path[swb+1][cb].prev_idx = cb;
-path[swb+1][cb].cost = path[swb][cb].cost;
-path[swb+1][cb].run  = path[swb][cb].run + 1;
-}
-} else {
-float minrd = next_minrd;
-int mincb = next_mincb;
-next_minrd = INFINITY;
-next_mincb = 0;
-for (cb = 0; cb < CB_TOT_ALL; cb++) {
-float cost_stay_here, cost_get_here;
-float rd = 0.0f;
-if (cb >= 12 && sce->band_type[win*16+swb] < 
aac_cb_out_map[cb] ||
-cb  < aac_cb_in_map[sce->band_type[win*16+swb]] && 
sce->band_type[win*16+swb] > aac_cb_out_map[cb]) {
-path[swb+1][cb].prev_idx = -1;
-path[swb+1][cb].cost = INFINITY;
-path[swb+1][cb].run  = path[swb][cb].run + 1;
-continue;
-}
-for (w = 0; w < group_len; w++) {
-FFPsyBand *band = 
&s->psy.ch[s->cur_channel].psy_bands[(win+w)*16+swb];
-rd += quantize_band_cost(s, &sce->coeffs[start + w*128],
- &s->scoefs[start + w*128], size,
- sce->sf_idx[(win+w)*16+swb], 
aac_cb_out_map[cb],
- lambda / band->threshold, 
INFINITY, NULL, NULL);
-}
-cost_stay_here = path[swb][cb].cost + rd;
-cost_get_here  = minrd  + rd + run_bits + 4;
-if (   run_value_bits[sce->ics.num_windows == 
8][path[swb][cb].run]
-!= run_value_bits[sce->ics.num_windows == 
8][path[swb][cb].run+1])
-cost_stay_here += run_bits;
-if (cost_get_here < cost_stay_here) {
-path[swb+1][cb].prev_idx = mincb;
-path[swb+1][cb].cost = cost_get_here;
-path[swb+1][cb].run  = 1;
-} else {
-path[swb+1][cb].prev_idx = cb;
-path[swb+1][cb].cost = cost_stay_here;
-path[swb+1][cb].run  = path[swb][cb].run + 1;
-}
-if (path[swb+1][cb].cost < next_minrd) {
-next_minrd = path[swb+1][cb].cost;
-next_mincb = cb;
-}
-}
-}
-start += sce->ics.swb_sizes[swb];
-}
-
-//convert resulting path from backward-linked list
-stack_len = 0;
-idx   = 0;
-for (cb = 1; cb < CB_TOT_ALL; cb++)
-if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)
-idx = cb;
-ppos = max_sfb;
-while (ppos > 0) {
-av_assert1(idx >= 0);
-cb = idx;
-stackrun[stack_len] = path[ppos][cb].run;
-stackcb [stack_len] = cb;
-  

[FFmpeg-cvslog] avcodec/cuviddec: correctly handle buffer size and status when deinterlacing

2025-02-26 Thread Timo Rothenpieler
ffmpeg | branch: master | Timo Rothenpieler  | Tue Feb 
25 19:39:43 2025 +0100| [99e2af4e7837ca09b97d93a562dc12947179fc48] | committer: 
Timo Rothenpieler

avcodec/cuviddec: correctly handle buffer size and status when deinterlacing

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=99e2af4e7837ca09b97d93a562dc12947179fc48
---

 libavcodec/cuviddec.c | 24 +---
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index 67076a1752..5bf555e15f 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -131,7 +131,7 @@ static int CUDAAPI cuvid_handle_video_sequence(void 
*opaque, CUVIDEOFORMAT* form
 CUVIDDECODECREATEINFO cuinfo;
 int surface_fmt;
 int chroma_444;
-int fifo_size_inc;
+int old_nb_surfaces, fifo_size_inc, fifo_size_mul = 1;
 
 int old_width = avctx->width;
 int old_height = avctx->height;
@@ -349,20 +349,24 @@ static int CUDAAPI cuvid_handle_video_sequence(void 
*opaque, CUVIDEOFORMAT* form
 return 0;
 }
 
-fifo_size_inc = ctx->nb_surfaces;
-ctx->nb_surfaces = FFMAX(ctx->nb_surfaces, format->min_num_decode_surfaces 
+ 3);
+if (ctx->deint_mode_current != cudaVideoDeinterlaceMode_Weave && 
!ctx->drop_second_field) {
+avctx->framerate = av_mul_q(avctx->framerate, (AVRational){2, 1});
+fifo_size_mul = 2;
+}
 
+old_nb_surfaces = ctx->nb_surfaces;
+ctx->nb_surfaces = FFMAX(ctx->nb_surfaces, format->min_num_decode_surfaces 
+ 3);
 if (avctx->extra_hw_frames > 0)
 ctx->nb_surfaces += avctx->extra_hw_frames;
 
-fifo_size_inc = ctx->nb_surfaces - fifo_size_inc;
+fifo_size_inc = ctx->nb_surfaces * fifo_size_mul - 
av_fifo_can_read(ctx->frame_queue) - av_fifo_can_write(ctx->frame_queue);
 if (fifo_size_inc > 0 && av_fifo_grow2(ctx->frame_queue, fifo_size_inc) < 
0) {
 av_log(avctx, AV_LOG_ERROR, "Failed to grow frame queue on video 
sequence callback\n");
 ctx->internal_error = AVERROR(ENOMEM);
 return 0;
 }
 
-if (fifo_size_inc > 0 && av_reallocp_array(&ctx->key_frame, 
ctx->nb_surfaces, sizeof(int)) < 0) {
+if (ctx->nb_surfaces > old_nb_surfaces && 
av_reallocp_array(&ctx->key_frame, ctx->nb_surfaces, sizeof(int)) < 0) {
 av_log(avctx, AV_LOG_ERROR, "Failed to grow key frame array on video 
sequence callback\n");
 ctx->internal_error = AVERROR(ENOMEM);
 return 0;
@@ -374,9 +378,6 @@ static int CUDAAPI cuvid_handle_video_sequence(void 
*opaque, CUVIDEOFORMAT* form
 cuinfo.bitDepthMinus8 = format->bit_depth_luma_minus8;
 cuinfo.DeinterlaceMode = ctx->deint_mode_current;
 
-if (ctx->deint_mode_current != cudaVideoDeinterlaceMode_Weave && 
!ctx->drop_second_field)
-avctx->framerate = av_mul_q(avctx->framerate, (AVRational){2, 1});
-
 ctx->internal_error = 
CHECK_CU(ctx->cvdl->cuvidCreateDecoder(&ctx->cudecoder, &cuinfo));
 if (ctx->internal_error < 0)
 return 0;
@@ -448,11 +449,12 @@ static int cuvid_is_buffer_full(AVCodecContext *avctx)
 {
 CuvidContext *ctx = avctx->priv_data;
 
-int delay = ctx->cuparseinfo.ulMaxDisplayDelay;
+int shift = 0;
 if (ctx->deint_mode != cudaVideoDeinterlaceMode_Weave && 
!ctx->drop_second_field)
-delay *= 2;
+shift = 1;
 
-return av_fifo_can_read(ctx->frame_queue) + delay >= ctx->nb_surfaces;
+// shift/divide frame count to ensure the buffer is still signalled full 
if one half-frame has already been returned when deinterlacing.
+return ((av_fifo_can_read(ctx->frame_queue) + shift) >> shift) + 
ctx->cuparseinfo.ulMaxDisplayDelay >= ctx->nb_surfaces;
 }
 
 static int cuvid_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt)

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

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


[FFmpeg-cvslog] avformat/mp3dec: Subtract known padding from duration

2025-02-26 Thread Ulrik Mikaelsson
ffmpeg | branch: master | Ulrik Mikaelsson  | Tue 
Aug 22 13:55:14 2023 +0200| [5a526fdad01054d611be715099432bc7ac94a14b] | 
committer: Tomas Härdin

avformat/mp3dec: Subtract known padding from duration

When an Info-tag is present, marking initial and trailing samples as
padding, those samples should not be included in the calculation of track
duration.

This solves a surprising user experience where converting a WAV->MP3->WAV,
ffprobe will show the duration of the mp3 as slightly longer than both the
input and the output.

As a result, the estimated duration and imprecise seek-results of some
FATE-tests have been updated.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5a526fdad01054d611be715099432bc7ac94a14b
---

 libavformat/mp3dec.c | 20 ++--
 tests/ref/fate/gapless-mp3-side-data |  4 ++--
 tests/ref/seek/extra-mp3 |  8 
 3 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index dac91205d9..31eeb68ebb 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -52,6 +52,7 @@ typedef struct {
 int usetoc;
 unsigned frames; /* Total number of frames in file */
 unsigned header_filesize;   /* Total number of bytes in the stream */
+unsigned frame_duration;   /* Frame duration in st->time_base */
 int is_cbr;
 } MP3DecContext;
 
@@ -341,6 +342,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream 
*st, int64_t base)
 
 mp3->frames = 0;
 mp3->header_filesize   = 0;
+mp3->frame_duration = av_rescale_q(spf, (AVRational){1, c.sample_rate}, 
st->time_base);
 
 mp3_parse_info_tag(s, st, &c, spf);
 mp3_parse_vbri_tag(s, st, base);
@@ -351,11 +353,18 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, 
AVStream *st, int64_t base)
 /* Skip the vbr tag frame */
 avio_seek(s->pb, base + vbrtag_size, SEEK_SET);
 
-if (mp3->frames)
-st->duration = av_rescale_q(mp3->frames, (AVRational){spf, 
c.sample_rate},
+if (mp3->frames) {
+int64_t full_duration_samples;
+
+full_duration_samples = mp3->frames * (int64_t)spf;
+st->duration = av_rescale_q(full_duration_samples - mp3->start_pad - 
mp3->end_pad,
+(AVRational){1, c.sample_rate},
 st->time_base);
-if (mp3->header_filesize && mp3->frames && !mp3->is_cbr)
-st->codecpar->bit_rate = av_rescale(mp3->header_filesize, 8 * 
c.sample_rate, mp3->frames * (int64_t)spf);
+
+if (mp3->header_filesize && !mp3->is_cbr)
+st->codecpar->bit_rate = av_rescale(mp3->header_filesize, 8 * 
c.sample_rate,
+full_duration_samples);
+}
 
 return 0;
 }
@@ -586,8 +595,7 @@ static int mp3_seek(AVFormatContext *s, int stream_index, 
int64_t timestamp,
 return best_pos;
 
 if (mp3->is_cbr && ie == &ie1 && mp3->frames && mp3->header_filesize > 0) {
-int frame_duration = av_rescale(st->duration, 1, mp3->frames);
-ie1.timestamp = frame_duration * av_rescale(best_pos - 
si->data_offset, mp3->frames, mp3->header_filesize);
+ie1.timestamp = mp3->frame_duration * av_rescale(best_pos - 
si->data_offset, mp3->frames, mp3->header_filesize);
 }
 
 avpriv_update_cur_dts(s, st, ie->timestamp);
diff --git a/tests/ref/fate/gapless-mp3-side-data 
b/tests/ref/fate/gapless-mp3-side-data
index 49ebc32dc8..878425f092 100644
--- a/tests/ref/fate/gapless-mp3-side-data
+++ b/tests/ref/fate/gapless-mp3-side-data
@@ -593,5 +593,5 @@ 
packet|codec_type=audio|stream_index=0|pts=217866240|pts_time=15.438367|dts=2178
 
packet|codec_type=audio|stream_index=0|pts=218234880|pts_time=15.464490|dts=218234880|dts_time=15.464490|duration=368640|duration_time=0.026122|size=418|pos=248882|flags=K__|data_hash=CRC32:fbc83c3c
 
packet|codec_type=audio|stream_index=0|pts=218603520|pts_time=15.490612|dts=218603520|dts_time=15.490612|duration=368640|duration_time=0.026122|size=418|pos=249300|flags=K__|data_hash=CRC32:d5fb5f9c|side_datum/skip_samples:side_data_type=Skip
 
Samples|side_datum/skip_samples:skip_samples=0|side_datum/skip_samples:discard_padding=303|side_datum/skip_samples:skip_reason=0|side_datum/skip_samples:discard_reason=0
 
packet|codec_type=audio|stream_index=0|pts=218972160|pts_time=15.516735|dts=218972160|dts_time=15.516735|duration=368640|duration_time=0.026122|size=418|pos=249718|flags=K__|data_hash=CRC32:3789f3cf|side_datum/skip_samples:side_data_type=Skip
 
Samples|side_datum/skip_samples:skip_samples=0|side_datum/skip_samples:discard_padding=1152|side_datum/skip_samples:skip_reason=0|side_datum/skip_samples:discard_reason=0
-stream|index=0|codec_name=mp3|profile=unknown|codec_type=audio|codec_tag_string=[0][0][0][0]|codec_tag=0x|sample_fmt=fltp|sample_rate=44100|channels=2|channel_layout=stereo|bits_per_sample=0|initial_padding=0|id=N/A|r_frame_rate=0/0|avg_frame_rate=0/0|time_base=1/14112000|sta

[FFmpeg-cvslog] GOL-1361: Remove invalid CTTS sample_offset check

2025-02-26 Thread ekir
ffmpeg | branch: master | ekir  | Tue Apr 18 17:31:43 2023 
+0200| [da5353cf05bcbe2fc47e69321178a2f7ae64a4f3] | committer: Tomas Härdin

GOL-1361: Remove invalid CTTS sample_offset check

We checked in this places:
* In 8.6.1.3 of ISO/IEC 14496-12 about the CTTS box
* In Apples MOV spec: 
https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html#//apple_ref/doc/uid/TP4939-CH204-SW19

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=da5353cf05bcbe2fc47e69321178a2f7ae64a4f3
---

 libavformat/mov.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 15c840d164..ee44b10435 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3703,13 +3703,6 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 av_log(c->fc, AV_LOG_TRACE, "count=%d, duration=%d\n",
 count, duration);
 
-if (FFNABS(duration) < -(1<<28) && i+2fc, AV_LOG_WARNING, "CTTS invalid\n");
-av_freep(&sc->ctts_data);
-sc->ctts_count = 0;
-return 0;
-}
-
 if (i+2fc);
 }

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

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


[FFmpeg-cvslog] rtmp: Set correct message stream id when writing as server

2025-02-26 Thread Jonathan Murray
ffmpeg | branch: master | Jonathan Murray  | Thu 
Mar 31 16:23:17 2022 +0200| [98d97bb33b2a54265b3d41838b2fb64310360e22] | 
committer: Tomas Härdin

rtmp: Set correct message stream id when writing as server

rtmp_write is used both for writing outputs as a server. The
rt->listen flag determines which mode we're running in.

Previously, when running as a server, the message stream id would
always be set to 0 for media/metadata messages. This is surprising
given that we have both responded to "createStream()" with a value
of 1 and sent a "Stream Begin 1" to the client. Furthermore, some
client libraries (Red5) seem to trip up on receiving
"@setDataFrame" on stream 0 (and may be correct to assume that
this message would be sent on stream 1).

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=98d97bb33b2a54265b3d41838b2fb64310360e22
---

 libavformat/rtmpproto.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 4095ae9421..846376e668 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -3049,7 +3049,12 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, 
int size)
  pkttype, ts, pktsize)) < 0)
 return ret;
 
-rt->out_pkt.extra = rt->stream_id;
+// If rt->listen, then we're running as a a server and should
+// use the ID that we've sent in Stream Begin and in the
+// _result to createStream.
+// Otherwise, we're running as a client and should use the ID
+// that we've received in the createStream from the server.
+rt->out_pkt.extra = (rt->listen) ? rt->nb_streamid : rt->stream_id;
 rt->flv_data = rt->out_pkt.data;
 }
 

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

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


[FFmpeg-cvslog] avformat/http: Return EIO for prematurely broken connection

2025-02-26 Thread Ulrik
ffmpeg | branch: master | Ulrik  | Mon Jul 27 11:46:56 2020 
+0200| [1306e5c7d3107f00208b924af6caff8408c14902] | committer: Tomas Härdin

avformat/http: Return EIO for prematurely broken connection

Currently, a prematurely broken connection normally leads to the same
EOF, as a completed successful transfer. However, enabling reconnect
changes this logic, and leads to the return of EIO.

This patch unifies that logic, leading to the return of EIO for premature
disconnect, regardless of setting of "reconnect".

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1306e5c7d3107f00208b924af6caff8408c14902
---

 libavformat/http.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index ec60bc0b17..65ea5d993c 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -19,6 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+
 #include "config.h"
 #include "config_components.h"
 
@@ -1747,6 +1749,7 @@ static int http_read_stream(URLContext *h, uint8_t *buf, 
int size)
 read_ret = http_buf_read(h, buf, size);
 while (read_ret < 0) {
 uint64_t target = h->is_streamed ? 0 : s->off;
+bool is_premature = s->filesize > 0 && s->off < s->filesize;
 
 if (read_ret == AVERROR_EXIT)
 break;
@@ -1754,9 +1757,13 @@ static int http_read_stream(URLContext *h, uint8_t *buf, 
int size)
 if (h->is_streamed && !s->reconnect_streamed)
 break;
 
-if (!(s->reconnect && s->filesize > 0 && s->off < s->filesize) &&
-!(s->reconnect_at_eof && read_ret == AVERROR_EOF))
-break;
+if (!(s->reconnect && is_premature) &&
+!(s->reconnect_at_eof && read_ret == AVERROR_EOF)) {
+if (is_premature)
+return AVERROR(EIO);
+else
+break;
+}
 
 if (reconnect_delay > s->reconnect_delay_max || 
(s->reconnect_max_retries >= 0 && conn_attempts > s->reconnect_max_retries) ||
 reconnect_delay_total > s->reconnect_delay_total_max)

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

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


[FFmpeg-cvslog] Make mime-type award a bonus probe score

2025-02-26 Thread Peter Zebühr
ffmpeg | branch: master | Peter Zebühr  | Tue Nov 21 
14:16:49 2023 +0100| [e24920375cd2bbdd579424c16cf0f9c66579ea24] | committer: 
Tomas Härdin

Make mime-type award a bonus probe score

This changes the default behaviour of ffmpeg where content-type headers
on an input gives an absolut probe score (of 75) to instead give a bonus
score (of 30). This gives the probe a better chance to arrive at the
correct format by (hopefully) giving a large enough bonus to push edge
cases in the right direction (MPEG-PS vs MP3, I am looking at you) while
also not adversly punishing clearer cases (raw ADTS marked as
"audio/mpeg" for example).

This patch was regression tested against 20 million recent podcast
submissions (after content-type propagation was added to
original-storage), and 50k Juno vodcasts submissions (dito). No adverse
effects observed (but the bonus may still need tweaking if other edge
cases are detected in production).

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e24920375cd2bbdd579424c16cf0f9c66579ea24
---

 libavformat/avformat.h   | 2 +-
 libavformat/format.c | 8 
 libavformat/libopenmpt.c | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 6abdb6d480..498c557a3c 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -459,7 +459,7 @@ typedef struct AVProbeData {
 #define AVPROBE_SCORE_STREAM_RETRY (AVPROBE_SCORE_MAX/4-1)
 
 #define AVPROBE_SCORE_EXTENSION  50 ///< score for file extension
-#define AVPROBE_SCORE_MIME   75 ///< score for file mime type
+#define AVPROBE_SCORE_MIME_BONUS 30 ///< score added for matching mime type
 #define AVPROBE_SCORE_MAX   100 ///< maximum score
 
 #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the 
end of the probe buffer
diff --git a/libavformat/format.c b/libavformat/format.c
index e65a6fc05e..71018ea6ab 100644
--- a/libavformat/format.c
+++ b/libavformat/format.c
@@ -212,10 +212,10 @@ const AVInputFormat *av_probe_input_format3(const 
AVProbeData *pd,
 score = AVPROBE_SCORE_EXTENSION;
 }
 if (av_match_name(lpd.mime_type, fmt1->mime_type)) {
-if (AVPROBE_SCORE_MIME > score) {
-av_log(NULL, AV_LOG_DEBUG, "Probing %s score:%d increased to 
%d due to MIME type\n", fmt1->name, score, AVPROBE_SCORE_MIME);
-score = AVPROBE_SCORE_MIME;
-}
+int old_score = score;
+score += AVPROBE_SCORE_MIME_BONUS;
+if (score > AVPROBE_SCORE_MAX) score = AVPROBE_SCORE_MAX;
+av_log(NULL, AV_LOG_DEBUG, "Probing %s score:%d increased to %d 
due to MIME type\n", fmt1->name, old_score, score);
 }
 if (score > score_max) {
 score_max = score;
diff --git a/libavformat/libopenmpt.c b/libavformat/libopenmpt.c
index 736af7caf2..dee975c9c2 100644
--- a/libavformat/libopenmpt.c
+++ b/libavformat/libopenmpt.c
@@ -244,7 +244,7 @@ static int read_probe_openmpt(const AVProbeData *p)
  * AVPROBE_SCORE_MAX in order to reduce the impact in the rare
  * cases of false positives.
  */
-return AVPROBE_SCORE_MIME + 1;
+return (AVPROBE_SCORE_MAX * 3) / 4 + 1;
 } else if (probe_result == 
OPENMPT_PROBE_FILE_HEADER_RESULT_WANTMOREDATA) {
 if (probe_openmpt_extension(p) > 0) {
 return AVPROBE_SCORE_RETRY;

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

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


[FFmpeg-cvslog] avformat/flacdec: Return correct error-codes on read-failure

2025-02-26 Thread Ulrik
ffmpeg | branch: master | Ulrik  | Thu Jan 26 17:51:02 2023 
+0100| [95314cd7c5c0d2dc884c245583b697db590cfefd] | committer: Tomas Härdin

avformat/flacdec: Return correct error-codes on read-failure

Forward errors from `avio_read` directly. When `avio_read` sees EOF before
expected bytes can be read, consistently return `AVERROR_INVALIDDATA`

We used to return `AVERROR(AVERROR_INVALIDDATA)` when failing to read
metadata block headers. `AVERROR_INVALIDDATA` is already negative, so
wrapping in `AVERROR` leads to double-negation.

We used to return `AVERROR(EIO)` when failing to read extended metadata.
However, many times, the IO-layer is not at fault, the input data is simply
corrupted (truncated), so we return `AVERROR_INVALIDDATA` here as well.

---

Tomas: changed to use AVERROR_EOF

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=95314cd7c5c0d2dc884c245583b697db590cfefd
---

 libavformat/flacdec.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 3c317acaee..1c18556c3d 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -80,8 +80,13 @@ static int flac_read_header(AVFormatContext *s)
 
 /* process metadata blocks */
 while (!avio_feof(s->pb) && !metadata_last) {
-if (avio_read(s->pb, header, 4) != 4)
-return AVERROR_INVALIDDATA;
+ret = avio_read(s->pb, header, 4);
+if (ret < 0) {
+return ret;
+} else if (ret != 4) {
+return AVERROR_EOF;
+}
+
 flac_parse_block_header(header, &metadata_last, &metadata_type,
&metadata_size);
 switch (metadata_type) {
@@ -95,8 +100,11 @@ static int flac_read_header(AVFormatContext *s)
 if (!buffer) {
 return AVERROR(ENOMEM);
 }
-if (avio_read(s->pb, buffer, metadata_size) != metadata_size) {
-RETURN_ERROR(AVERROR(EIO));
+ret = avio_read(s->pb, buffer, metadata_size);
+if (ret < 0) {
+RETURN_ERROR(ret);
+} else if (ret != metadata_size) {
+RETURN_ERROR(AVERROR_EOF);
 }
 break;
 /* skip metadata block for unsupported types */

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

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


[FFmpeg-cvslog] libavcodec/wmadec: Return AVERROR_INVALIDDATA on decoding errors

2025-02-26 Thread Jonathan Murray
ffmpeg | branch: master | Jonathan Murray  | Wed 
Jun  9 12:00:24 2021 +0200| [399234ee2a22a7c5f0e0df55a66b36bf946efc5a] | 
committer: Tomas Härdin

libavcodec/wmadec: Return AVERROR_INVALIDDATA on decoding errors

WMA files that fail to decode due to incoherent block lengths and
frame lengths currently result in a "Operation not permitted".
After this change, they will instead result in "Invalid data found
when processing input".

Several other error cases are also changed from returning -1.

As we change the error propagation logic in wma_decode_frame and
wma_decode_superframe, previous occurrences of returning
AVERROR_INVALIDDATA are also affected by this. This includes
"total_gain overread" and a "channel exponents_initialized" check.

---

Tomas: changed some -1's to AVERROR_INVALIDDATA

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=399234ee2a22a7c5f0e0df55a66b36bf946efc5a
---

 libavcodec/wmadec.c | 40 
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index 3427e482dc..c24fff5522 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -368,7 +368,7 @@ static int decode_exp_vlc(WMACodecContext *s, int ch)
 if ((unsigned) last_exp + 60 >= FF_ARRAY_ELEMS(pow_tab)) {
 av_log(s->avctx, AV_LOG_ERROR, "Exponent out of range: %d\n",
last_exp);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 v  = ptab[last_exp];
 iv = iptab[last_exp];
@@ -439,8 +439,10 @@ static void wma_window(WMACodecContext *s, float *out)
 }
 
 /**
- * @return 0 if OK. 1 if last block of frame. return -1 if
- * unrecoverable error.
+ * @return
+ * 0 if OK.
+ * 1 if last block of frame.
+ * AVERROR if unrecoverable error.
  */
 static int wma_decode_block(WMACodecContext *s)
 {
@@ -468,7 +470,7 @@ static int wma_decode_block(WMACodecContext *s)
 av_log(s->avctx, AV_LOG_ERROR,
"prev_block_len_bits %d out of range\n",
s->frame_len_bits - v);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 s->prev_block_len_bits = s->frame_len_bits - v;
 v  = get_bits(&s->gb, n);
@@ -476,7 +478,7 @@ static int wma_decode_block(WMACodecContext *s)
 av_log(s->avctx, AV_LOG_ERROR,
"block_len_bits %d out of range\n",
s->frame_len_bits - v);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 s->block_len_bits = s->frame_len_bits - v;
 } else {
@@ -489,7 +491,7 @@ static int wma_decode_block(WMACodecContext *s)
 av_log(s->avctx, AV_LOG_ERROR,
"next_block_len_bits %d out of range\n",
s->frame_len_bits - v);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 s->next_block_len_bits = s->frame_len_bits - v;
 } else {
@@ -501,14 +503,14 @@ static int wma_decode_block(WMACodecContext *s)
 
 if (s->frame_len_bits - s->block_len_bits >= s->nb_block_sizes){
 av_log(s->avctx, AV_LOG_ERROR, "block_len_bits not initialized to a 
valid value\n");
-return -1;
+return AVERROR_INVALIDDATA;
 }
 
 /* now check if the block length is coherent with the frame length */
 s->block_len = 1 << s->block_len_bits;
 if ((s->block_pos + s->block_len) > s->frame_len) {
 av_log(s->avctx, AV_LOG_ERROR, "frame_len overflow\n");
-return -1;
+return AVERROR_INVALIDDATA;
 }
 
 if (channels == 2)
@@ -590,7 +592,7 @@ static int wma_decode_block(WMACodecContext *s)
 if (s->channel_coded[ch]) {
 if (s->use_exp_vlc) {
 if (decode_exp_vlc(s, ch) < 0)
-return -1;
+return AVERROR_INVALIDDATA;
 } else {
 decode_exp_lsp(s, ch);
 }
@@ -802,7 +804,7 @@ static int wma_decode_frame(WMACodecContext *s, float 
**samples,
 for (;;) {
 ret = wma_decode_block(s);
 if (ret < 0)
-return -1;
+return ret;
 if (ret)
 break;
 }
@@ -879,8 +881,10 @@ static int wma_decode_superframe(AVCodecContext *avctx, 
AVFrame *frame,
 return AVERROR_INVALIDDATA;
 
 if ((s->last_superframe_len + buf_size - 1) >
-MAX_CODED_SUPERFRAME_SIZE)
+MAX_CODED_SUPERFRAME_SIZE) {
+ret = AVERROR_INVALIDDATA;
 goto fail;
+}
 
 q   = s->last_superframe + s->last_superframe_len;
 len = buf_size - 1;
@@ -911,14 +915,17 @@ static int wma_decode_superframe(AVCodecContext *avctx, 
AVFrame *frame,
 av_log(avctx, AV_LOG_ERROR,
"Invalid last frame bit offset %d > bu

[FFmpeg-cvslog] aacenc: remove support for AAC Main profile

2025-02-26 Thread Lynne
ffmpeg | branch: master | Lynne  | Sat Feb  8 04:42:54 2025 
+0100| [9b11fefb88c770b9c1d4d4583c61c6abde6c033c] | committer: Lynne

aacenc: remove support for AAC Main profile

The Main profile of AAC is... terrible.
It enables the use of delta coding across coefficients of two frames
to try to increase compression, and it enabled one more pole for TNS
filters.

What the AAC authors failed to take into account were basic
mathematics, as MDCT leakage (e.g. the spread of each frequency when
represented in a discrete spectrum) is significant in most audio codecs.
This leads to huge variations between each frame, basically rendering
prediction completely pointless.

In fact, enabling AAC-Main prediction does not, in general, even recoup
the metadata losses from signalling the profile and prediction properties
in the first place. So you lose efficiency by using AAC Main.

The rumor is that it was put in the AAC spec for patent reasons, though
patent-wise, it has about as much use as a patent for a bicycle designed
for use by snakes.

The only other thing AAC Main changes is it permits 3-pole TNS filters.
When AAC's bands are absolutely tiny, except for very high frequency bands,
where you're likely to use PNS instead.

Just get rid of it.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9b11fefb88c770b9c1d4d4583c61c6abde6c033c
---

 doc/encoders.texi|  15 +-
 libavcodec/Makefile  |   1 -
 libavcodec/aaccoder.c|  13 --
 libavcodec/aacenc.c  |  44 +-
 libavcodec/aacenc.h  |  11 --
 libavcodec/aacenc_pred.c | 347 ---
 libavcodec/aacenc_pred.h |  47 ---
 libavcodec/aacenc_tns.c  |   2 +-
 libavcodec/aacenctab.h   |   1 -
 tests/fate/aac.mak   |  10 --
 10 files changed, 5 insertions(+), 486 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index c0795fe5fd..f3fcc1aa60 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -106,15 +106,8 @@ debugging by setting the option to "disable".
 Enables the use of the long term prediction extension which increases coding
 efficiency in very low bandwidth situations such as encoding of voice or
 solo piano music by extending constant harmonic peaks in bands throughout
-frames. This option is implied by profile:a aac_low and is incompatible with
-aac_pred. Use in conjunction with @option{-ar} to decrease the samplerate.
-
-@item aac_pred
-Enables the use of a more traditional style of prediction where the spectral
-coefficients transmitted are replaced by the difference of the current
-coefficients minus the previous "predicted" coefficients. In theory and 
sometimes
-in practice this can improve quality for low to mid bitrate audio.
-This option implies the aac_main profile and is incompatible with aac_ltp.
+frames. This option is implied by profile:a aac_low.
+Use in conjunction with @option{-ar} to decrease the samplerate.
 
 @item profile
 Sets the encoding profile, possible values:
@@ -132,10 +125,6 @@ MPEG4 specifications.
 Long term prediction profile, is enabled by and will enable the 
@option{aac_ltp}
 option. Introduced in MPEG4.
 
-@item aac_main
-Main-type prediction profile, is enabled by and will enable the 
@option{aac_pred}
-option. Introduced in MPEG2.
-
 @end table
 If this option is unspecified it is set to @samp{aac_low}.
 @end table
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 9630074205..82fc9c9dc6 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -199,7 +199,6 @@ OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o 
aaccoder.o aacenctab.o\
   aacenc_is.o \
   aacenc_tns.o \
   aacenc_ltp.o \
-  aacenc_pred.o \
   psymodel.o kbdwin.o \
   mpeg4audio_sample_rates.o
 OBJS-$(CONFIG_AAC_MEDIACODEC_DECODER)  += mediacodecdec.o
diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index 4ce54ca886..1999f588e4 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -48,7 +48,6 @@
 #include "aacenc_is.h"
 #include "aacenc_tns.h"
 #include "aacenc_ltp.h"
-#include "aacenc_pred.h"
 
 #include "libavcodec/aaccoder_twoloop.h"
 
@@ -1123,10 +1122,7 @@ const AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB] 
= {
 quantize_and_encode_band,
 ff_aac_encode_tns_info,
 ff_aac_encode_ltp_info,
-ff_aac_encode_main_pred,
-ff_aac_adjust_common_pred,
 ff_aac_adjust_common_ltp,
-ff_aac_apply_main_pred,
 ff_aac_apply_tns,
 ff_aac_update_ltp,
 ff_aac_ltp_insert_new_frame,
@@ -1137,7 +1133,6 @@ const AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB] 
= {
 ff_aac_search_for_ltp,
 search_for_ms,
 ff_aac_search_for_is,
-ff_aac_search_for_pred,
 },
 [AAC_CODER_TWOLOOP] = {
   

[FFmpeg-cvslog] aacenc: remove support for AAC LTP profile

2025-02-26 Thread Lynne
ffmpeg | branch: master | Lynne  | Sat Feb  8 05:03:02 2025 
+0100| [938353377068f3bcb874673b65e75367e0142aff] | committer: Lynne

aacenc: remove support for AAC LTP profile

The LTP profile of AAC is... terrible.
It was an early 90's attempt at bridging the gap between speech
codecs and general purpose codecs. It did so by trying to exploit the fact
that most speech patterns are regular.

Unfortunately, it went about it the same way as AAC Main, by taking
the previous frame's samples, modifying them through an LPC filter,
transforming them back using a forward MDCT, putting the output
coefficients back into the current frame, and using delta coding.
But once again, they ignored basic mathematics and MDCT leakage.
Thankfully, because AAC LTP is meant to operate at very low bitrates,
the extreme quantization results in most leakage being irrelevant.

Unfortunately, the result is that the output sounds pretty much
terrible regardless of whether LTP is enabled or not.

This was the first attempt at trying to couple speech coding into AAC.
No, the second attempt did not succeed either.
Nnnneither did the third. Or fourth.

For the fifth one, they literally just jammed a speech codec into AAC
with USAC once they saw Opus do it.

Just drop support for encoding AAC LTP. It was always experimental
to begin with.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=938353377068f3bcb874673b65e75367e0142aff
---

 libavcodec/Makefile |   1 -
 libavcodec/aaccoder.c   |  16 
 libavcodec/aacenc.c |  41 +
 libavcodec/aacenc.h |  20 
 libavcodec/aacenc_ltp.c | 236 
 libavcodec/aacenc_ltp.h |  41 -
 libavcodec/aacenctab.h  |   1 -
 7 files changed, 1 insertion(+), 355 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 82fc9c9dc6..499f826635 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -198,7 +198,6 @@ OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o 
aaccoder.o aacenctab.o\
   aacpsy.o aactab.o  \
   aacenc_is.o \
   aacenc_tns.o \
-  aacenc_ltp.o \
   psymodel.o kbdwin.o \
   mpeg4audio_sample_rates.o
 OBJS-$(CONFIG_AAC_MEDIACODEC_DECODER)  += mediacodecdec.o
diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index 1999f588e4..478eda86f3 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -47,7 +47,6 @@
 
 #include "aacenc_is.h"
 #include "aacenc_tns.h"
-#include "aacenc_ltp.h"
 
 #include "libavcodec/aaccoder_twoloop.h"
 
@@ -1121,16 +1120,11 @@ const AACCoefficientsEncoder 
ff_aac_coders[AAC_CODER_NB] = {
 encode_window_bands_info,
 quantize_and_encode_band,
 ff_aac_encode_tns_info,
-ff_aac_encode_ltp_info,
-ff_aac_adjust_common_ltp,
 ff_aac_apply_tns,
-ff_aac_update_ltp,
-ff_aac_ltp_insert_new_frame,
 set_special_band_scalefactors,
 search_for_pns,
 mark_pns,
 ff_aac_search_for_tns,
-ff_aac_search_for_ltp,
 search_for_ms,
 ff_aac_search_for_is,
 },
@@ -1139,16 +1133,11 @@ const AACCoefficientsEncoder 
ff_aac_coders[AAC_CODER_NB] = {
 codebook_trellis_rate,
 quantize_and_encode_band,
 ff_aac_encode_tns_info,
-ff_aac_encode_ltp_info,
-ff_aac_adjust_common_ltp,
 ff_aac_apply_tns,
-ff_aac_update_ltp,
-ff_aac_ltp_insert_new_frame,
 set_special_band_scalefactors,
 search_for_pns,
 mark_pns,
 ff_aac_search_for_tns,
-ff_aac_search_for_ltp,
 search_for_ms,
 ff_aac_search_for_is,
 },
@@ -1157,16 +1146,11 @@ const AACCoefficientsEncoder 
ff_aac_coders[AAC_CODER_NB] = {
 codebook_trellis_rate,
 quantize_and_encode_band,
 ff_aac_encode_tns_info,
-ff_aac_encode_ltp_info,
-ff_aac_adjust_common_ltp,
 ff_aac_apply_tns,
-ff_aac_update_ltp,
-ff_aac_ltp_insert_new_frame,
 set_special_band_scalefactors,
 search_for_pns,
 mark_pns,
 ff_aac_search_for_tns,
-ff_aac_search_for_ltp,
 search_for_ms,
 ff_aac_search_for_is,
 },
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index f1bc078cb0..5ed54dbcb3 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -762,11 +762,8 @@ static int encode_individual_channel(AVCodecContext 
*avctx, AACEncContext *s,
  int common_window)
 {
 put_bits(&s->pb, 8, sce->sf_idx[0]);
-if (!common_window) {
+if (!common_window)
 put_ics_info(s, &sce->ics);
-if (s->coder->encode_ltp_info)
-s->coder->encode_ltp_info(s, sce, 0);
-}
 encode_band_info(s, sce);
 e

[FFmpeg-cvslog] avformat/mov: (v4) fix get_eia608_packet

2025-02-26 Thread Pavel Koshevoy
ffmpeg | branch: release/6.1 | Pavel Koshevoy  | Sun Feb 
23 09:43:56 2025 -0700| [39cac587c4f78f7c26e0f0e5da664943d4e9fade] | committer: 
Pavel Koshevoy

avformat/mov: (v4) fix get_eia608_packet

The problem is reproducible with "Test for Quicktime 608 CC file.mov"
from https://samples.ffmpeg.org/MPEG2/subcc/

ffmpeg -i "Test for Quicktime 608 CC file.mov" -map 0 -c copy -y remuxed.mov

See https://trac.ffmpeg.org/ticket/11470

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=39cac587c4f78f7c26e0f0e5da664943d4e9fade
---

 libavformat/mov.c | 70 ++-
 1 file changed, 59 insertions(+), 11 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index d3418beab1..85675398e8 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -8921,25 +8921,73 @@ static int mov_change_extradata(MOVStreamContext *sc, 
AVPacket *pkt)
 return 0;
 }
 
-static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int size)
+static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int src_size)
 {
-int new_size, ret;
+/* We can't make assumptions about the structure of the payload,
+   because it may include multiple cdat and cdt2 samples. */
+const uint32_t cdat = AV_RB32("cdat");
+const uint32_t cdt2 = AV_RB32("cdt2");
+int ret, out_size = 0;
 
-if (size <= 8)
+/* a valid payload must have size, 4cc, and at least 1 byte pair: */
+if (src_size < 10)
 return AVERROR_INVALIDDATA;
-new_size = ((size - 8) / 2) * 3;
-ret = av_new_packet(pkt, new_size);
+
+/* avoid an int overflow: */
+if ((src_size - 8) / 2 >= INT_MAX / 3)
+return AVERROR_INVALIDDATA;
+
+ret = av_new_packet(pkt, ((src_size - 8) / 2) * 3);
 if (ret < 0)
 return ret;
 
-avio_skip(pb, 8);
-for (int j = 0; j < new_size; j += 3) {
-pkt->data[j] = 0xFC;
-pkt->data[j+1] = avio_r8(pb);
-pkt->data[j+2] = avio_r8(pb);
+/* parse and re-format the c608 payload in one pass. */
+while (src_size >= 10) {
+const uint32_t atom_size = avio_rb32(pb);
+const uint32_t atom_type = avio_rb32(pb);
+const uint32_t data_size = atom_size - 8;
+const uint8_t cc_field =
+atom_type == cdat ? 1 :
+atom_type == cdt2 ? 2 :
+0;
+
+/* account for bytes consumed for atom size and type. */
+src_size -= 8;
+
+/* make sure the data size stays within the buffer boundaries. */
+if (data_size < 2 || data_size > src_size) {
+ret = AVERROR_INVALIDDATA;
+break;
+}
+
+/* make sure the data size is consistent with N byte pairs. */
+if (data_size % 2 != 0) {
+ret = AVERROR_INVALIDDATA;
+break;
+}
+
+if (!cc_field) {
+/* neither cdat or cdt2 ... skip it */
+avio_skip(pb, data_size);
+src_size -= data_size;
+continue;
+}
+
+for (uint32_t i = 0; i < data_size; i += 2) {
+pkt->data[out_size] = (0x1F << 3) | (1 << 2) | (cc_field - 1);
+pkt->data[out_size + 1] = avio_r8(pb);
+pkt->data[out_size + 2] = avio_r8(pb);
+out_size += 3;
+src_size -= 2;
+}
 }
 
-return 0;
+if (src_size > 0)
+/* skip any remaining unread portion of the input payload */
+avio_skip(pb, src_size);
+
+av_shrink_packet(pkt, out_size);
+return ret;
 }
 
 static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)

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

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


[FFmpeg-cvslog] avformat/mov: (v4) fix get_eia608_packet

2025-02-26 Thread Pavel Koshevoy
ffmpeg | branch: release/7.1 | Pavel Koshevoy  | Sun Feb 
23 09:43:56 2025 -0700| [71889a8437d04124e8cb6919ee078f436082ab41] | committer: 
Pavel Koshevoy

avformat/mov: (v4) fix get_eia608_packet

The problem is reproducible with "Test for Quicktime 608 CC file.mov"
from https://samples.ffmpeg.org/MPEG2/subcc/

ffmpeg -i "Test for Quicktime 608 CC file.mov" -map 0 -c copy -y remuxed.mov

See https://trac.ffmpeg.org/ticket/11470

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=71889a8437d04124e8cb6919ee078f436082ab41
---

 libavformat/mov.c | 70 ++-
 1 file changed, 59 insertions(+), 11 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 63e8fe31ff..41ca280c8a 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -10526,25 +10526,73 @@ static int mov_change_extradata(AVStream *st, 
AVPacket *pkt)
 return 0;
 }
 
-static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int size)
+static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int src_size)
 {
-int new_size, ret;
+/* We can't make assumptions about the structure of the payload,
+   because it may include multiple cdat and cdt2 samples. */
+const uint32_t cdat = AV_RB32("cdat");
+const uint32_t cdt2 = AV_RB32("cdt2");
+int ret, out_size = 0;
 
-if (size <= 8)
+/* a valid payload must have size, 4cc, and at least 1 byte pair: */
+if (src_size < 10)
 return AVERROR_INVALIDDATA;
-new_size = ((size - 8) / 2) * 3;
-ret = av_new_packet(pkt, new_size);
+
+/* avoid an int overflow: */
+if ((src_size - 8) / 2 >= INT_MAX / 3)
+return AVERROR_INVALIDDATA;
+
+ret = av_new_packet(pkt, ((src_size - 8) / 2) * 3);
 if (ret < 0)
 return ret;
 
-avio_skip(pb, 8);
-for (int j = 0; j < new_size; j += 3) {
-pkt->data[j] = 0xFC;
-pkt->data[j+1] = avio_r8(pb);
-pkt->data[j+2] = avio_r8(pb);
+/* parse and re-format the c608 payload in one pass. */
+while (src_size >= 10) {
+const uint32_t atom_size = avio_rb32(pb);
+const uint32_t atom_type = avio_rb32(pb);
+const uint32_t data_size = atom_size - 8;
+const uint8_t cc_field =
+atom_type == cdat ? 1 :
+atom_type == cdt2 ? 2 :
+0;
+
+/* account for bytes consumed for atom size and type. */
+src_size -= 8;
+
+/* make sure the data size stays within the buffer boundaries. */
+if (data_size < 2 || data_size > src_size) {
+ret = AVERROR_INVALIDDATA;
+break;
+}
+
+/* make sure the data size is consistent with N byte pairs. */
+if (data_size % 2 != 0) {
+ret = AVERROR_INVALIDDATA;
+break;
+}
+
+if (!cc_field) {
+/* neither cdat or cdt2 ... skip it */
+avio_skip(pb, data_size);
+src_size -= data_size;
+continue;
+}
+
+for (uint32_t i = 0; i < data_size; i += 2) {
+pkt->data[out_size] = (0x1F << 3) | (1 << 2) | (cc_field - 1);
+pkt->data[out_size + 1] = avio_r8(pb);
+pkt->data[out_size + 2] = avio_r8(pb);
+out_size += 3;
+src_size -= 2;
+}
 }
 
-return 0;
+if (src_size > 0)
+/* skip any remaining unread portion of the input payload */
+avio_skip(pb, src_size);
+
+av_shrink_packet(pkt, out_size);
+return ret;
 }
 
 static int mov_finalize_packet(AVFormatContext *s, AVStream *st, AVIndexEntry 
*sample,

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

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


[FFmpeg-cvslog] avformat/mov: (v4) fix get_eia608_packet

2025-02-26 Thread Pavel Koshevoy
ffmpeg | branch: release/7.0 | Pavel Koshevoy  | Sun Feb 
23 09:43:56 2025 -0700| [72e64ede9446050ea06110cf4cf0342ad47051b7] | committer: 
Pavel Koshevoy

avformat/mov: (v4) fix get_eia608_packet

The problem is reproducible with "Test for Quicktime 608 CC file.mov"
from https://samples.ffmpeg.org/MPEG2/subcc/

ffmpeg -i "Test for Quicktime 608 CC file.mov" -map 0 -c copy -y remuxed.mov

See https://trac.ffmpeg.org/ticket/11470

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=72e64ede9446050ea06110cf4cf0342ad47051b7
---

 libavformat/mov.c | 70 ++-
 1 file changed, 59 insertions(+), 11 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 0f7b910a79..eae1b49ba5 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -9903,25 +9903,73 @@ static int mov_change_extradata(AVStream *st, AVPacket 
*pkt)
 return 0;
 }
 
-static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int size)
+static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int src_size)
 {
-int new_size, ret;
+/* We can't make assumptions about the structure of the payload,
+   because it may include multiple cdat and cdt2 samples. */
+const uint32_t cdat = AV_RB32("cdat");
+const uint32_t cdt2 = AV_RB32("cdt2");
+int ret, out_size = 0;
 
-if (size <= 8)
+/* a valid payload must have size, 4cc, and at least 1 byte pair: */
+if (src_size < 10)
 return AVERROR_INVALIDDATA;
-new_size = ((size - 8) / 2) * 3;
-ret = av_new_packet(pkt, new_size);
+
+/* avoid an int overflow: */
+if ((src_size - 8) / 2 >= INT_MAX / 3)
+return AVERROR_INVALIDDATA;
+
+ret = av_new_packet(pkt, ((src_size - 8) / 2) * 3);
 if (ret < 0)
 return ret;
 
-avio_skip(pb, 8);
-for (int j = 0; j < new_size; j += 3) {
-pkt->data[j] = 0xFC;
-pkt->data[j+1] = avio_r8(pb);
-pkt->data[j+2] = avio_r8(pb);
+/* parse and re-format the c608 payload in one pass. */
+while (src_size >= 10) {
+const uint32_t atom_size = avio_rb32(pb);
+const uint32_t atom_type = avio_rb32(pb);
+const uint32_t data_size = atom_size - 8;
+const uint8_t cc_field =
+atom_type == cdat ? 1 :
+atom_type == cdt2 ? 2 :
+0;
+
+/* account for bytes consumed for atom size and type. */
+src_size -= 8;
+
+/* make sure the data size stays within the buffer boundaries. */
+if (data_size < 2 || data_size > src_size) {
+ret = AVERROR_INVALIDDATA;
+break;
+}
+
+/* make sure the data size is consistent with N byte pairs. */
+if (data_size % 2 != 0) {
+ret = AVERROR_INVALIDDATA;
+break;
+}
+
+if (!cc_field) {
+/* neither cdat or cdt2 ... skip it */
+avio_skip(pb, data_size);
+src_size -= data_size;
+continue;
+}
+
+for (uint32_t i = 0; i < data_size; i += 2) {
+pkt->data[out_size] = (0x1F << 3) | (1 << 2) | (cc_field - 1);
+pkt->data[out_size + 1] = avio_r8(pb);
+pkt->data[out_size + 2] = avio_r8(pb);
+out_size += 3;
+src_size -= 2;
+}
 }
 
-return 0;
+if (src_size > 0)
+/* skip any remaining unread portion of the input payload */
+avio_skip(pb, src_size);
+
+av_shrink_packet(pkt, out_size);
+return ret;
 }
 
 static int mov_finalize_packet(AVFormatContext *s, AVStream *st, AVIndexEntry 
*sample,

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

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


[FFmpeg-cvslog] avformat/mov: (v4) fix get_eia608_packet

2025-02-26 Thread Pavel Koshevoy
ffmpeg | branch: release/6.0 | Pavel Koshevoy  | Sun Feb 
23 09:43:56 2025 -0700| [5911b7e9f5d3600274d9cc77b0f5364ab4f7aae3] | committer: 
Pavel Koshevoy

avformat/mov: (v4) fix get_eia608_packet

The problem is reproducible with "Test for Quicktime 608 CC file.mov"
from https://samples.ffmpeg.org/MPEG2/subcc/

ffmpeg -i "Test for Quicktime 608 CC file.mov" -map 0 -c copy -y remuxed.mov

See https://trac.ffmpeg.org/ticket/11470

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5911b7e9f5d3600274d9cc77b0f5364ab4f7aae3
---

 libavformat/mov.c | 70 ++-
 1 file changed, 59 insertions(+), 11 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 6810a2f3a6..2d4a1e2d8d 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -8760,25 +8760,73 @@ static int mov_change_extradata(MOVStreamContext *sc, 
AVPacket *pkt)
 return 0;
 }
 
-static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int size)
+static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int src_size)
 {
-int new_size, ret;
+/* We can't make assumptions about the structure of the payload,
+   because it may include multiple cdat and cdt2 samples. */
+const uint32_t cdat = AV_RB32("cdat");
+const uint32_t cdt2 = AV_RB32("cdt2");
+int ret, out_size = 0;
 
-if (size <= 8)
+/* a valid payload must have size, 4cc, and at least 1 byte pair: */
+if (src_size < 10)
 return AVERROR_INVALIDDATA;
-new_size = ((size - 8) / 2) * 3;
-ret = av_new_packet(pkt, new_size);
+
+/* avoid an int overflow: */
+if ((src_size - 8) / 2 >= INT_MAX / 3)
+return AVERROR_INVALIDDATA;
+
+ret = av_new_packet(pkt, ((src_size - 8) / 2) * 3);
 if (ret < 0)
 return ret;
 
-avio_skip(pb, 8);
-for (int j = 0; j < new_size; j += 3) {
-pkt->data[j] = 0xFC;
-pkt->data[j+1] = avio_r8(pb);
-pkt->data[j+2] = avio_r8(pb);
+/* parse and re-format the c608 payload in one pass. */
+while (src_size >= 10) {
+const uint32_t atom_size = avio_rb32(pb);
+const uint32_t atom_type = avio_rb32(pb);
+const uint32_t data_size = atom_size - 8;
+const uint8_t cc_field =
+atom_type == cdat ? 1 :
+atom_type == cdt2 ? 2 :
+0;
+
+/* account for bytes consumed for atom size and type. */
+src_size -= 8;
+
+/* make sure the data size stays within the buffer boundaries. */
+if (data_size < 2 || data_size > src_size) {
+ret = AVERROR_INVALIDDATA;
+break;
+}
+
+/* make sure the data size is consistent with N byte pairs. */
+if (data_size % 2 != 0) {
+ret = AVERROR_INVALIDDATA;
+break;
+}
+
+if (!cc_field) {
+/* neither cdat or cdt2 ... skip it */
+avio_skip(pb, data_size);
+src_size -= data_size;
+continue;
+}
+
+for (uint32_t i = 0; i < data_size; i += 2) {
+pkt->data[out_size] = (0x1F << 3) | (1 << 2) | (cc_field - 1);
+pkt->data[out_size + 1] = avio_r8(pb);
+pkt->data[out_size + 2] = avio_r8(pb);
+out_size += 3;
+src_size -= 2;
+}
 }
 
-return 0;
+if (src_size > 0)
+/* skip any remaining unread portion of the input payload */
+avio_skip(pb, src_size);
+
+av_shrink_packet(pkt, out_size);
+return ret;
 }
 
 static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)

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

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


[FFmpeg-cvslog] avformat/mov: (v4) fix get_eia608_packet

2025-02-26 Thread Pavel Koshevoy
ffmpeg | branch: release/5.1 | Pavel Koshevoy  | Sun Feb 
23 09:43:56 2025 -0700| [01af45c0f3d5b2113844f13061ddcc92b99fa475] | committer: 
Pavel Koshevoy

avformat/mov: (v4) fix get_eia608_packet

The problem is reproducible with "Test for Quicktime 608 CC file.mov"
from https://samples.ffmpeg.org/MPEG2/subcc/

ffmpeg -i "Test for Quicktime 608 CC file.mov" -map 0 -c copy -y remuxed.mov

See https://trac.ffmpeg.org/ticket/11470

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=01af45c0f3d5b2113844f13061ddcc92b99fa475
---

 libavformat/mov.c | 70 ++-
 1 file changed, 59 insertions(+), 11 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index d06967ecfb..25562bb995 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -8660,25 +8660,73 @@ static int mov_change_extradata(MOVStreamContext *sc, 
AVPacket *pkt)
 return 0;
 }
 
-static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int size)
+static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int src_size)
 {
-int new_size, ret;
+/* We can't make assumptions about the structure of the payload,
+   because it may include multiple cdat and cdt2 samples. */
+const uint32_t cdat = AV_RB32("cdat");
+const uint32_t cdt2 = AV_RB32("cdt2");
+int ret, out_size = 0;
 
-if (size <= 8)
+/* a valid payload must have size, 4cc, and at least 1 byte pair: */
+if (src_size < 10)
 return AVERROR_INVALIDDATA;
-new_size = ((size - 8) / 2) * 3;
-ret = av_new_packet(pkt, new_size);
+
+/* avoid an int overflow: */
+if ((src_size - 8) / 2 >= INT_MAX / 3)
+return AVERROR_INVALIDDATA;
+
+ret = av_new_packet(pkt, ((src_size - 8) / 2) * 3);
 if (ret < 0)
 return ret;
 
-avio_skip(pb, 8);
-for (int j = 0; j < new_size; j += 3) {
-pkt->data[j] = 0xFC;
-pkt->data[j+1] = avio_r8(pb);
-pkt->data[j+2] = avio_r8(pb);
+/* parse and re-format the c608 payload in one pass. */
+while (src_size >= 10) {
+const uint32_t atom_size = avio_rb32(pb);
+const uint32_t atom_type = avio_rb32(pb);
+const uint32_t data_size = atom_size - 8;
+const uint8_t cc_field =
+atom_type == cdat ? 1 :
+atom_type == cdt2 ? 2 :
+0;
+
+/* account for bytes consumed for atom size and type. */
+src_size -= 8;
+
+/* make sure the data size stays within the buffer boundaries. */
+if (data_size < 2 || data_size > src_size) {
+ret = AVERROR_INVALIDDATA;
+break;
+}
+
+/* make sure the data size is consistent with N byte pairs. */
+if (data_size % 2 != 0) {
+ret = AVERROR_INVALIDDATA;
+break;
+}
+
+if (!cc_field) {
+/* neither cdat or cdt2 ... skip it */
+avio_skip(pb, data_size);
+src_size -= data_size;
+continue;
+}
+
+for (uint32_t i = 0; i < data_size; i += 2) {
+pkt->data[out_size] = (0x1F << 3) | (1 << 2) | (cc_field - 1);
+pkt->data[out_size + 1] = avio_r8(pb);
+pkt->data[out_size + 2] = avio_r8(pb);
+out_size += 3;
+src_size -= 2;
+}
 }
 
-return 0;
+if (src_size > 0)
+/* skip any remaining unread portion of the input payload */
+avio_skip(pb, src_size);
+
+av_shrink_packet(pkt, out_size);
+return ret;
 }
 
 static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)

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

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


[FFmpeg-cvslog] avformat/mov: (v4) fix get_eia608_packet

2025-02-26 Thread Pavel Koshevoy
ffmpeg | branch: release/5.0 | Pavel Koshevoy  | Sun Feb 
23 09:43:56 2025 -0700| [76913f0b9fe9ce23c0de1d1e656c6c203f703242] | committer: 
Pavel Koshevoy

avformat/mov: (v4) fix get_eia608_packet

The problem is reproducible with "Test for Quicktime 608 CC file.mov"
from https://samples.ffmpeg.org/MPEG2/subcc/

ffmpeg -i "Test for Quicktime 608 CC file.mov" -map 0 -c copy -y remuxed.mov

See https://trac.ffmpeg.org/ticket/11470

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=76913f0b9fe9ce23c0de1d1e656c6c203f703242
---

 libavformat/mov.c | 70 ++-
 1 file changed, 59 insertions(+), 11 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 80090f0ffe..f90b4124ee 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -8203,25 +8203,73 @@ static int mov_change_extradata(MOVStreamContext *sc, 
AVPacket *pkt)
 return 0;
 }
 
-static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int size)
+static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int src_size)
 {
-int new_size, ret;
+/* We can't make assumptions about the structure of the payload,
+   because it may include multiple cdat and cdt2 samples. */
+const uint32_t cdat = AV_RB32("cdat");
+const uint32_t cdt2 = AV_RB32("cdt2");
+int ret, out_size = 0;
 
-if (size <= 8)
+/* a valid payload must have size, 4cc, and at least 1 byte pair: */
+if (src_size < 10)
 return AVERROR_INVALIDDATA;
-new_size = ((size - 8) / 2) * 3;
-ret = av_new_packet(pkt, new_size);
+
+/* avoid an int overflow: */
+if ((src_size - 8) / 2 >= INT_MAX / 3)
+return AVERROR_INVALIDDATA;
+
+ret = av_new_packet(pkt, ((src_size - 8) / 2) * 3);
 if (ret < 0)
 return ret;
 
-avio_skip(pb, 8);
-for (int j = 0; j < new_size; j += 3) {
-pkt->data[j] = 0xFC;
-pkt->data[j+1] = avio_r8(pb);
-pkt->data[j+2] = avio_r8(pb);
+/* parse and re-format the c608 payload in one pass. */
+while (src_size >= 10) {
+const uint32_t atom_size = avio_rb32(pb);
+const uint32_t atom_type = avio_rb32(pb);
+const uint32_t data_size = atom_size - 8;
+const uint8_t cc_field =
+atom_type == cdat ? 1 :
+atom_type == cdt2 ? 2 :
+0;
+
+/* account for bytes consumed for atom size and type. */
+src_size -= 8;
+
+/* make sure the data size stays within the buffer boundaries. */
+if (data_size < 2 || data_size > src_size) {
+ret = AVERROR_INVALIDDATA;
+break;
+}
+
+/* make sure the data size is consistent with N byte pairs. */
+if (data_size % 2 != 0) {
+ret = AVERROR_INVALIDDATA;
+break;
+}
+
+if (!cc_field) {
+/* neither cdat or cdt2 ... skip it */
+avio_skip(pb, data_size);
+src_size -= data_size;
+continue;
+}
+
+for (uint32_t i = 0; i < data_size; i += 2) {
+pkt->data[out_size] = (0x1F << 3) | (1 << 2) | (cc_field - 1);
+pkt->data[out_size + 1] = avio_r8(pb);
+pkt->data[out_size + 2] = avio_r8(pb);
+out_size += 3;
+src_size -= 2;
+}
 }
 
-return 0;
+if (src_size > 0)
+/* skip any remaining unread portion of the input payload */
+avio_skip(pb, src_size);
+
+av_shrink_packet(pkt, out_size);
+return ret;
 }
 
 static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)

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

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


[FFmpeg-cvslog] avformat/mov: (v4) fix get_eia608_packet

2025-02-26 Thread Pavel Koshevoy
ffmpeg | branch: release/4.4 | Pavel Koshevoy  | Sun Feb 
23 09:43:56 2025 -0700| [e60da7024c75c1226c2f6cbe5ee22afef3664403] | committer: 
Pavel Koshevoy

avformat/mov: (v4) fix get_eia608_packet

The problem is reproducible with "Test for Quicktime 608 CC file.mov"
from https://samples.ffmpeg.org/MPEG2/subcc/

ffmpeg -i "Test for Quicktime 608 CC file.mov" -map 0 -c copy -y remuxed.mov

See https://trac.ffmpeg.org/ticket/11470

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e60da7024c75c1226c2f6cbe5ee22afef3664403
---

 libavformat/mov.c | 70 ++-
 1 file changed, 59 insertions(+), 11 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 6ec6ebf0a2..06eacca4e9 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7968,25 +7968,73 @@ static int mov_change_extradata(MOVStreamContext *sc, 
AVPacket *pkt)
 return 0;
 }
 
-static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int size)
+static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int src_size)
 {
-int new_size, ret;
+/* We can't make assumptions about the structure of the payload,
+   because it may include multiple cdat and cdt2 samples. */
+const uint32_t cdat = AV_RB32("cdat");
+const uint32_t cdt2 = AV_RB32("cdt2");
+int ret, out_size = 0;
 
-if (size <= 8)
+/* a valid payload must have size, 4cc, and at least 1 byte pair: */
+if (src_size < 10)
 return AVERROR_INVALIDDATA;
-new_size = ((size - 8) / 2) * 3;
-ret = av_new_packet(pkt, new_size);
+
+/* avoid an int overflow: */
+if ((src_size - 8) / 2 >= INT_MAX / 3)
+return AVERROR_INVALIDDATA;
+
+ret = av_new_packet(pkt, ((src_size - 8) / 2) * 3);
 if (ret < 0)
 return ret;
 
-avio_skip(pb, 8);
-for (int j = 0; j < new_size; j += 3) {
-pkt->data[j] = 0xFC;
-pkt->data[j+1] = avio_r8(pb);
-pkt->data[j+2] = avio_r8(pb);
+/* parse and re-format the c608 payload in one pass. */
+while (src_size >= 10) {
+const uint32_t atom_size = avio_rb32(pb);
+const uint32_t atom_type = avio_rb32(pb);
+const uint32_t data_size = atom_size - 8;
+const uint8_t cc_field =
+atom_type == cdat ? 1 :
+atom_type == cdt2 ? 2 :
+0;
+
+/* account for bytes consumed for atom size and type. */
+src_size -= 8;
+
+/* make sure the data size stays within the buffer boundaries. */
+if (data_size < 2 || data_size > src_size) {
+ret = AVERROR_INVALIDDATA;
+break;
+}
+
+/* make sure the data size is consistent with N byte pairs. */
+if (data_size % 2 != 0) {
+ret = AVERROR_INVALIDDATA;
+break;
+}
+
+if (!cc_field) {
+/* neither cdat or cdt2 ... skip it */
+avio_skip(pb, data_size);
+src_size -= data_size;
+continue;
+}
+
+for (uint32_t i = 0; i < data_size; i += 2) {
+pkt->data[out_size] = (0x1F << 3) | (1 << 2) | (cc_field - 1);
+pkt->data[out_size + 1] = avio_r8(pb);
+pkt->data[out_size + 2] = avio_r8(pb);
+out_size += 3;
+src_size -= 2;
+}
 }
 
-return 0;
+if (src_size > 0)
+/* skip any remaining unread portion of the input payload */
+avio_skip(pb, src_size);
+
+av_shrink_packet(pkt, out_size);
+return ret;
 }
 
 static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)

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

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


[FFmpeg-cvslog] New commits on branch release/7.0

2025-02-26 Thread Git System
URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9aab014878c12cd8b5003d3d9d656d9363789ed6
Author: Michael Niedermayer 
Date:   Wed Feb 26 22:59:00 2025 +0100

update for 7.0.3

Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=33435e078f660b5122e3447a975655c33d7d3df7
Author: Michael Niedermayer 
Date:   Sun Feb 9 01:28:17 2025 +0100

avformat/iff: Check that we have a stream in read_dst_frame()

Fixes: null pointer dereference
Fixes: 
385644864/clusterfuzz-testcase-minimized-ffmpeg_dem_IFF_fuzzer-4551049565765632

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Peter Ross 
Signed-off-by: Michael Niedermayer 
(cherry picked from commit 8668957ef604bd2b99175310638bc5031ae0d991)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f43dfb5e82ad151e061d4c8e8fa4660740ba8bab
Author: Michael Niedermayer 
Date:   Fri Feb 7 02:33:21 2025 +0100

avformat/mlvdec: fix size checks

Fixes: heap-buffer-overflow
Fixes: 
391962476/clusterfuzz-testcase-minimized-ffmpeg_dem_MLV_fuzzer-5746746587676672

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
(cherry picked from commit 251d43aef0df9262f2688c1c848af993bbb67d08)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=89a792fd3b2368d2da349e9ecc5e4bccf4f5b4ba
Author: Michael Niedermayer 
Date:   Fri Feb 7 01:24:37 2025 +0100

avformat/wavdec: Fix overflow of intermediate in block_align check

Fixes: signed integer overflow: -251517880 * 32 cannot be represented in 
type 'int'
Fixes: 
385224934/clusterfuzz-testcase-minimized-ffmpeg_dem_W64_fuzzer-4909298151915520

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
(cherry picked from commit 1afbc40875069312dd729b5959fb04950c3938db)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=af1eb801daac0f249c51227d3f975e0e4d18f93a
Author: Michael Niedermayer 
Date:   Wed Feb 5 03:47:52 2025 +0100

avformat/mxfdec: Check edit unit for overflow in mxf_set_current_edit_unit()

Fixes: signed integer overflow: 9223372036854775807 + 1 cannot be 
represented in type 'long'
Fixes: 
392672068/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-6232335892152320

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Tomas Härdin 
Signed-off-by: Michael Niedermayer 
(cherry picked from commit 8a6ad9eab2f1c37a18c2f30e6660260edd7c0c16)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f28eeabd034a6005e88e08f42d65db7fe314f9a6
Author: Michael Niedermayer 
Date:   Thu Feb 6 13:09:08 2025 +0100

avformat/hls: Fix twitter

Allow mp4 with all mpegts extensions

Fixes: Ticket11435
Reviewed-by: Steven Liu 
Signed-off-by: Michael Niedermayer 
(cherry picked from commit cef3422b4819e3b6f07086625fa7890eaa8d45e7)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4d00981ce73fea81f8f386ba64db17953168649e
Author: Michael Niedermayer 
Date:   Tue Jan 28 23:07:54 2025 +0100

libavformat/hls: Be more restrictive on mpegts extensions

Signed-off-by: Michael Niedermayer 
(cherry picked from commit 0113e30806b205111344e266bc69ff9657a3ca02)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8e69f09c40d09893fb0ccf784ff4c3f3ce0ea485
Author: Michael Niedermayer 
Date:   Tue Jan 28 13:26:34 2025 +0100

avformat/hls: .ts is always ok even if its a mov/mp4

Maybe fixes: 11435

Signed-off-by: Michael Niedermayer 
(cherry picked from commit 9e12572933dc1c49e9b35d772ddcae896c2ba8a8)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=584eb8c73cc702c4042331eb714ccad8910efde8
Author: Michael Niedermayer 
Date:   Thu Jan 30 02:28:32 2025 +0100

avcodec/h263dec: Check against previous dimensions instead of coded

Fixes: out of array access
Fixes: crash-a41ef3db699013f669b076f02f36942925f5a98c

Found-by: Kacper Michajlow 
Reviewed-by: Kacper Michajlow 
Signed-off-by: Michael Niedermayer 
(cherry picked from commit 0fe33c99a26a06a6875c4abfb96362a65145264b)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f57d15139f00b19d8e8232298a6e87c31e6e3fdc
Author: Michael Niedermayer 
Date:   Tue Jan 28 12:51:58 2025 +0100

avfor

[FFmpeg-cvslog] avformat: add AV1 RTP depacketizer and packetizer

2025-02-26 Thread Chris Hodges
ffmpeg | branch: master | Chris Hodges  | Mon Aug 26 
11:29:29 2024 +0200| [330c8f8b936de66d08d5c462845e7fdcbc637b75] | committer: 
Ronald S. Bultje

avformat: add AV1 RTP depacketizer and packetizer

Add RTP packetizer and depacketizer according to (most)
of the official AV1 RTP specification. This enables
streaming via RTSP between ffmpeg and ffmpeg and has
also been tested to work with AV1 RTSP streams via
GStreamer.

It also adds the required SDP attributes for AV1.

AV1 RTP encoding is marked as experimental due to
draft specification status, debug amount reduced
and other changes suggested by Tristan.

Added optional code for searching the sequence
header to determine the first packet for broken
AV1 encoders / parsers.

Stops depacketizing on corruption until next keyframe,
no longer prematurely issues packet on decoding if
temporal unit was not complete yet.

Change-Id: I90f5c5b9d577908a0d713606706b5654fde5f910
Signed-off-by: Chris Hodges 
Signed-off-by: Ronald S. Bultje 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=330c8f8b936de66d08d5c462845e7fdcbc637b75
---

 libavformat/Makefile |   2 +
 libavformat/demux.c  |   1 +
 libavformat/rtp_av1.h| 128 
 libavformat/rtpdec.c |   1 +
 libavformat/rtpdec_av1.c | 461 +++
 libavformat/rtpdec_formats.h |   1 +
 libavformat/rtpenc.c |  14 ++
 libavformat/rtpenc.h |   1 +
 libavformat/rtpenc_av1.c | 357 +
 libavformat/sdp.c|  30 +++
 10 files changed, 996 insertions(+)

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 074efc118a..7730e7c4e6 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -47,6 +47,7 @@ OBJS-$(CONFIG_RTPDEC)+= rdt.o 
  \
 rtpdec_ac3.o\
 rtpdec_amr.o\
 rtpdec_asf.o\
+rtpdec_av1.o\
 rtpdec_dv.o \
 rtpdec_g726.o   \
 rtpdec_h261.o   \
@@ -517,6 +518,7 @@ OBJS-$(CONFIG_RTP_MUXER) += rtp.o \
 rtpenc_aac.o \
 rtpenc_latm.o\
 rtpenc_amr.o \
+rtpenc_av1.o \
 rtpenc_h261.o\
 rtpenc_h263.o\
 rtpenc_h263_rfc2190.o \
diff --git a/libavformat/demux.c b/libavformat/demux.c
index 0e39346f62..9c37be0852 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -111,6 +111,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, 
AVStream *st,
 { "aac",AV_CODEC_ID_AAC,  AVMEDIA_TYPE_AUDIO},
 { "ac3",AV_CODEC_ID_AC3,  AVMEDIA_TYPE_AUDIO},
 { "aptx",   AV_CODEC_ID_APTX, AVMEDIA_TYPE_AUDIO},
+{ "av1",AV_CODEC_ID_AV1,  AVMEDIA_TYPE_VIDEO},
 { "dts",AV_CODEC_ID_DTS,  AVMEDIA_TYPE_AUDIO},
 { "dvbsub", AV_CODEC_ID_DVB_SUBTITLE, AVMEDIA_TYPE_SUBTITLE },
 { "dvbtxt", AV_CODEC_ID_DVB_TELETEXT, AVMEDIA_TYPE_SUBTITLE },
diff --git a/libavformat/rtp_av1.h b/libavformat/rtp_av1.h
new file mode 100644
index 00..a353fc0e4e
--- /dev/null
+++ b/libavformat/rtp_av1.h
@@ -0,0 +1,128 @@
+/*
+ * Shared definitions and helper functions for
+ * AV1 (de)packetization.
+ * Copyright (c) 2024 Axis Communications
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * @brief shared defines and functions for AV1 RTP dec/enc
+ * @author Chris Hodges 
+ */
+
+#ifndef AVFORMAT_RTP_AV1_H
+#define AVFORMAT_RTP_AV1_H
+
+// define a couple of flags and bit fields
+#define AV1B_OBU_FORBIDDEN  7
+#define 

[FFmpeg-cvslog] avcodec/ffv1_parser: Rename close to ffv1_close

2025-02-26 Thread Zhao Zhili
ffmpeg | branch: master | Zhao Zhili  | Wed Feb 19 
20:33:27 2025 +0800| [584c41a4accdb729480e52d9829b34c1f9964bc9] | committer: 
Zhao Zhili

avcodec/ffv1_parser: Rename close to ffv1_close

This fixed wasm checkasm failure

$ wasm-tools validate tests/checkasm/checkasm
error: 
wasisdk://v25.0/build/sysroot/wasi-libc-wasm32-wasip1-threads/libc-top-half/musl/src/stdio/__stdio_close.c:24:9
 function `__stdio_close` failed to validate

Caused by:
0: func 4581 failed to validate
1: type mismatch: expected i32 but nothing on stack (at offset 0x43b770)

Since close is declared as static function, it's more like a bug
in wasi sdk, but we can workaround it easily.

Signed-off-by: Zhao Zhili 
Reviewed-by: James Almer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=584c41a4accdb729480e52d9829b34c1f9964bc9
---

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

diff --git a/libavcodec/ffv1_parser.c b/libavcodec/ffv1_parser.c
index f36a5dfdbd..bf61e88a2e 100644
--- a/libavcodec/ffv1_parser.c
+++ b/libavcodec/ffv1_parser.c
@@ -70,7 +70,7 @@ static int parse(AVCodecParserContext *s,
 return buf_size;
 }
 
-static void close(AVCodecParserContext *s)
+static void ffv1_close(AVCodecParserContext *s)
 {
 FFV1ParseContext *p = s->priv_data;
 
@@ -82,5 +82,5 @@ const AVCodecParser ff_ffv1_parser = {
 .codec_ids= { AV_CODEC_ID_FFV1 },
 .priv_data_size = sizeof(FFV1ParseContext),
 .parser_parse = parse,
-.parser_close = close,
+.parser_close = ffv1_close,
 };

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

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