Re: [FFmpeg-devel] [PATCH 2/2] avformat/dv: use av_packet_alloc() to allocate packets
On Fri, Apr 30, 2021 at 03:07:01PM -0300, James Almer wrote: > As avpriv_dv_get_packet can fail now, make it return < 0 on error, 0 on no > packet found, and > 0 on packet found. > > Signed-off-by: James Almer > --- > libavdevice/iec61883.c | 2 +- > libavformat/avidec.c | 4 +++- > libavformat/dv.c | 51 ++ > 3 files changed, 36 insertions(+), 21 deletions(-) crashes, but i guess thats what andreas already reported but if its something else or you need a testcase then ill retest this and provide a better report and test sample, just ask me if you need it thx [avi @ 0x2ced4680] Switching to NI mode, due to poor interleaving ==21022== Invalid read of size 8 ==21022==at 0x10F6A73: av_buffer_ref (in ffmpeg_g) ==21022==by 0x72C6D0: av_packet_ref (in ffmpeg_g) ==21022==by 0x7AA48B: avcodec_send_packet (in ffmpeg_g) ==21022==by 0x6AE90A: try_decode_frame (in ffmpeg_g) ==21022==by 0x6B98D8: avformat_find_stream_info (in ffmpeg_g) ==21022==by 0x2DB293: open_input_file (in ffmpeg_g) ==21022==by 0x2DEBB3: ffmpeg_parse_options (in ffmpeg_g) ==21022==by 0x2D3391: main (in ffmpeg_g) ==21022== Address 0x2d0a8748 is 8 bytes inside a block of size 24 free'd ==21022==at 0x4C32D3B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==21022==by 0x10F6ABC: av_buffer_unref (in ffmpeg_g) ==21022==by 0x72C640: av_packet_unref (in ffmpeg_g) ==21022==by 0x59B371: avpriv_dv_produce_packet (in ffmpeg_g) ==21022==by 0x577F4F: avi_read_packet (in ffmpeg_g) ==21022==by 0x6B3D5A: ff_read_packet (in ffmpeg_g) ==21022==by 0x6B4AFA: read_frame_internal (in ffmpeg_g) ==21022==by 0x6B95FC: avformat_find_stream_info (in ffmpeg_g) ==21022==by 0x2DB293: open_input_file (in ffmpeg_g) ==21022==by 0x2DEBB3: ffmpeg_parse_options (in ffmpeg_g) ==21022==by 0x2D3391: main (in ffmpeg_g) ==21022== Block was alloc'd at ==21022==at 0x4C33E76: memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==21022==by 0x4C33F91: posix_memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==21022==by 0x110C0E2: av_malloc (in ffmpeg_g) ==21022==by 0x110C308: av_mallocz (in ffmpeg_g) ==21022==by 0x10F6925: av_buffer_create (in ffmpeg_g) ==21022==by 0x10F69E6: av_buffer_alloc (in ffmpeg_g) ==21022==by 0x72BE07: av_grow_packet (in ffmpeg_g) ==21022==by 0x6AEFD9: append_packet_chunked (in ffmpeg_g) ==21022==by 0x577F02: avi_read_packet (in ffmpeg_g) ==21022==by 0x6B3D5A: ff_read_packet (in ffmpeg_g) ==21022==by 0x6B4AFA: read_frame_internal (in ffmpeg_g) ==21022==by 0x6B95FC: avformat_find_stream_info (in ffmpeg_g) ==21022==by 0x2DB293: open_input_file (in ffmpeg_g) ==21022==by 0x2DEBB3: ffmpeg_parse_options (in ffmpeg_g) ==21022==by 0x2D3391: main (in ffmpeg_g) [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB While the State exists there can be no freedom; when there is freedom there will be no State. -- Vladimir Lenin 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 2/2] avformat/dv: use av_packet_alloc() to allocate packets
On 5/2/2021 1:10 AM, Andreas Rheinhardt wrote: James Almer: As avpriv_dv_get_packet can fail now, make it return < 0 on error, 0 on no packet found, and > 0 on packet found. Signed-off-by: James Almer --- libavdevice/iec61883.c | 2 +- libavformat/avidec.c | 4 +++- libavformat/dv.c | 51 ++ 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/libavdevice/iec61883.c b/libavdevice/iec61883.c index 18ad704066..de9f48b8fc 100644 --- a/libavdevice/iec61883.c +++ b/libavdevice/iec61883.c @@ -191,7 +191,7 @@ static int iec61883_parse_queue_dv(struct iec61883_data *dv, AVPacket *pkt) int size; size = avpriv_dv_get_packet(dv->dv_demux, pkt); -if (size > 0) +if (size) return size; packet = dv->queue_first; diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 2d0d2a7389..2f493e42a6 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -1440,8 +1440,10 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) if (CONFIG_DV_DEMUXER && avi->dv_demux) { int size = avpriv_dv_get_packet(avi->dv_demux, pkt); -if (size >= 0) +if (size > 0) return size; +else if (size < 0) +return AVERROR(ENOMEM); else goto resync; } diff --git a/libavformat/dv.c b/libavformat/dv.c index a948fc0b98..1adc9fdb7b 100644 --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -45,7 +45,7 @@ struct DVDemuxContext { AVFormatContext* fctx; AVStream* vst; AVStream* ast[4]; -AVPacket audio_pkt[4]; +AVPacket *audio_pkt[4]; uint8_t audio_buf[4][8192]; int ach; int frames; @@ -261,11 +261,11 @@ static int dv_extract_audio_info(DVDemuxContext *c, const uint8_t *frame) c->ast[i]->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; c->ast[i]->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; -av_init_packet(&c->audio_pkt[i]); -c->audio_pkt[i].size = 0; -c->audio_pkt[i].data = c->audio_buf[i]; -c->audio_pkt[i].stream_index = c->ast[i]->index; -c->audio_pkt[i].flags |= AV_PKT_FLAG_KEY; +av_packet_unref(c->audio_pkt[i]); +c->audio_pkt[i]->size = 0; +c->audio_pkt[i]->data = c->audio_buf[i]; +c->audio_pkt[i]->stream_index = c->ast[i]->index; +c->audio_pkt[i]->flags |= AV_PKT_FLAG_KEY; } c->ast[i]->codecpar->sample_rate= dv_audio_frequency[freq]; c->ast[i]->codecpar->channels = 2; @@ -327,6 +327,9 @@ void avpriv_dv_close_demux(DVDemuxContext **pc) if (!c) return; +for (int i = 0; i < 4; i++) +av_packet_free(&c->audio_pkt[i]); + av_freep(pc); } @@ -336,6 +339,12 @@ static int dv_init_demux(AVFormatContext *s, DVDemuxContext *c) if (!c->vst) return AVERROR(ENOMEM); +for (int i = 0; i < 4; i++) { +c->audio_pkt[i] = av_packet_alloc(); +if (!c->audio_pkt[i]) + return AVERROR(ENOMEM); +} + c->fctx = s; c->vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; c->vst->codecpar->codec_id = AV_CODEC_ID_DVVIDEO; @@ -361,13 +370,14 @@ DVDemuxContext *avpriv_dv_init_demux(AVFormatContext *s) int avpriv_dv_get_packet(DVDemuxContext *c, AVPacket *pkt) { -int size = -1; +int size = 0; int i; for (i = 0; i < c->ach; i++) { -if (c->ast[i] && c->audio_pkt[i].size) { -*pkt = c->audio_pkt[i]; -c->audio_pkt[i].size = 0; +if (c->ast[i] && c->audio_pkt[i]->size) { +if (av_packet_ref(pkt, c->audio_pkt[i]) < 0) +return -1; +c->audio_pkt[i]->size = 0; size = pkt->size; break; } @@ -392,9 +402,9 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, /* FIXME: in case of no audio/bad audio we have to do something */ size = dv_extract_audio_info(c, buf); for (i = 0; i < c->ach; i++) { -c->audio_pkt[i].pos = pos; -c->audio_pkt[i].size = size; -c->audio_pkt[i].pts = (c->sys->height == 720) ? (c->frames & ~1) : c->frames; +c->audio_pkt[i]->pos = pos; +c->audio_pkt[i]->size = size; +c->audio_pkt[i]->pts = (c->sys->height == 720) ? (c->frames & ~1) : c->frames; ppcm[i] = c->audio_buf[i]; } if (c->ach) @@ -404,15 +414,15 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, * channels 0,1 and odd 2,3. */ if (c->sys->height == 720) { if (buf[1] & 0x0C) { -c->audio_pkt[2].size = c->audio_pkt[3].size = 0; +c->audio_pkt[2]->size = c->audio_pkt[3]->size = 0;
Re: [FFmpeg-devel] [PATCH 2/2] avformat/dv: use av_packet_alloc() to allocate packets
On 5/2/2021 6:21 AM, Michael Niedermayer wrote: On Fri, Apr 30, 2021 at 03:07:01PM -0300, James Almer wrote: As avpriv_dv_get_packet can fail now, make it return < 0 on error, 0 on no packet found, and > 0 on packet found. Signed-off-by: James Almer --- libavdevice/iec61883.c | 2 +- libavformat/avidec.c | 4 +++- libavformat/dv.c | 51 ++ 3 files changed, 36 insertions(+), 21 deletions(-) crashes, but i guess thats what andreas already reported but if its something else or you need a testcase then ill retest this and provide a better report and test sample, just ask me if you need it Can this file (or a portion of it) be added to FATE? Looking at coverage, these avpriv_ functions are only used with the raw DV demuxer. Both the AVI and MOV implementations are untested. I also see three mov files in the FATE samples repo that are not being used. None of them have audio, though. thx [avi @ 0x2ced4680] Switching to NI mode, due to poor interleaving ==21022== Invalid read of size 8 ==21022==at 0x10F6A73: av_buffer_ref (in ffmpeg_g) ==21022==by 0x72C6D0: av_packet_ref (in ffmpeg_g) ==21022==by 0x7AA48B: avcodec_send_packet (in ffmpeg_g) ==21022==by 0x6AE90A: try_decode_frame (in ffmpeg_g) ==21022==by 0x6B98D8: avformat_find_stream_info (in ffmpeg_g) ==21022==by 0x2DB293: open_input_file (in ffmpeg_g) ==21022==by 0x2DEBB3: ffmpeg_parse_options (in ffmpeg_g) ==21022==by 0x2D3391: main (in ffmpeg_g) ==21022== Address 0x2d0a8748 is 8 bytes inside a block of size 24 free'd ==21022==at 0x4C32D3B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==21022==by 0x10F6ABC: av_buffer_unref (in ffmpeg_g) ==21022==by 0x72C640: av_packet_unref (in ffmpeg_g) ==21022==by 0x59B371: avpriv_dv_produce_packet (in ffmpeg_g) ==21022==by 0x577F4F: avi_read_packet (in ffmpeg_g) ==21022==by 0x6B3D5A: ff_read_packet (in ffmpeg_g) ==21022==by 0x6B4AFA: read_frame_internal (in ffmpeg_g) ==21022==by 0x6B95FC: avformat_find_stream_info (in ffmpeg_g) ==21022==by 0x2DB293: open_input_file (in ffmpeg_g) ==21022==by 0x2DEBB3: ffmpeg_parse_options (in ffmpeg_g) ==21022==by 0x2D3391: main (in ffmpeg_g) ==21022== Block was alloc'd at ==21022==at 0x4C33E76: memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==21022==by 0x4C33F91: posix_memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==21022==by 0x110C0E2: av_malloc (in ffmpeg_g) ==21022==by 0x110C308: av_mallocz (in ffmpeg_g) ==21022==by 0x10F6925: av_buffer_create (in ffmpeg_g) ==21022==by 0x10F69E6: av_buffer_alloc (in ffmpeg_g) ==21022==by 0x72BE07: av_grow_packet (in ffmpeg_g) ==21022==by 0x6AEFD9: append_packet_chunked (in ffmpeg_g) ==21022==by 0x577F02: avi_read_packet (in ffmpeg_g) ==21022==by 0x6B3D5A: ff_read_packet (in ffmpeg_g) ==21022==by 0x6B4AFA: read_frame_internal (in ffmpeg_g) ==21022==by 0x6B95FC: avformat_find_stream_info (in ffmpeg_g) ==21022==by 0x2DB293: open_input_file (in ffmpeg_g) ==21022==by 0x2DEBB3: ffmpeg_parse_options (in ffmpeg_g) ==21022==by 0x2D3391: main (in ffmpeg_g) [...] ___ 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 1/3] avformat/dv: stop using av_init_packet()
Signed-off-by: James Almer --- libavformat/dv.c | 24 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/libavformat/dv.c b/libavformat/dv.c index cbb38cbd7d..d7909683c3 100644 --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -40,12 +40,22 @@ #include "dv.h" #include "libavutil/avassert.h" +// Must be kept in sync with AVPacket +struct DVPacket { +int64_t pts; +uint8_t *data; +int size; +int stream_index; +int flags; +int64_t pos; +}; + struct DVDemuxContext { const AVDVProfile* sys;/* Current DV profile. E.g.: 525/60, 625/50 */ AVFormatContext* fctx; AVStream* vst; AVStream* ast[4]; -AVPacket audio_pkt[4]; +struct DVPacket audio_pkt[4]; uint8_t audio_buf[4][8192]; int ach; int frames; @@ -261,11 +271,12 @@ static int dv_extract_audio_info(DVDemuxContext *c, const uint8_t *frame) c->ast[i]->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; c->ast[i]->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; -av_init_packet(&c->audio_pkt[i]); c->audio_pkt[i].size = 0; c->audio_pkt[i].data = c->audio_buf[i]; c->audio_pkt[i].stream_index = c->ast[i]->index; c->audio_pkt[i].flags |= AV_PKT_FLAG_KEY; +c->audio_pkt[i].pts = AV_NOPTS_VALUE; +c->audio_pkt[i].pos = -1; } c->ast[i]->codecpar->sample_rate= dv_audio_frequency[freq]; c->ast[i]->codecpar->channels = 2; @@ -358,7 +369,13 @@ int avpriv_dv_get_packet(DVDemuxContext *c, AVPacket *pkt) for (i = 0; i < c->ach; i++) { if (c->ast[i] && c->audio_pkt[i].size) { -*pkt = c->audio_pkt[i]; +pkt->size = c->audio_pkt[i].size; +pkt->data = c->audio_pkt[i].data; +pkt->stream_index = c->audio_pkt[i].stream_index; +pkt->flags= c->audio_pkt[i].flags; +pkt->pts = c->audio_pkt[i].pts; +pkt->pos = c->audio_pkt[i].pos; + c->audio_pkt[i].size = 0; size = pkt->size; break; @@ -404,7 +421,6 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, /* Now it's time to return video packet */ size = dv_extract_video_info(c, buf); -av_init_packet(pkt); pkt->data = buf; pkt->pos = pos; pkt->size = size; -- 2.31.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/3] avcodec/avi: don't save a copy of the packet's AVBufferRef on DV streams
It's no longer needed. Signed-off-by: James Almer --- libavformat/avidec.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavformat/avidec.c b/libavformat/avidec.c index d5dcab6193..e0d868e074 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -1494,10 +1494,8 @@ resync: } if (CONFIG_DV_DEMUXER && dv_demux) { -AVBufferRef *avbuf = pkt->buf; size = avpriv_dv_produce_packet(avi->dv_demux, pkt, pkt->data, pkt->size, pkt->pos); -pkt->buf= avbuf; pkt->flags |= AV_PKT_FLAG_KEY; if (size < 0) av_packet_unref(pkt); -- 2.31.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/3] avcodec/mov: don't save a copy of the packet's AVBufferRef on DV streams
It's no longer needed. Signed-off-by: James Almer --- libavformat/mov.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index ca8f06c4cd..ca6a0f2db4 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7930,9 +7930,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) } #if CONFIG_DV_DEMUXER if (mov->dv_demux && sc->dv_audio_container) { -AVBufferRef *buf = pkt->buf; ret = avpriv_dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size, pkt->pos); -pkt->buf = buf; av_packet_unref(pkt); if (ret < 0) return ret; -- 2.31.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 4/4] avcodec/jpeglsdec: Set alpha plane in PAL8 so image is not 100% transparent
Fixes: tickets/3933/128.jls Signed-off-by: Michael Niedermayer --- libavcodec/jpeglsdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c index bd9224d97d..c61cb14f49 100644 --- a/libavcodec/jpeglsdec.c +++ b/libavcodec/jpeglsdec.c @@ -124,7 +124,7 @@ int ff_jpegls_decode_lse(MJpegDecodeContext *s) for (i=s->palette_index; i<=maxtab; i++) { uint8_t k = i << shift; -pal[k] = 0; +pal[k] = wt < 4 ? 0xFF00 : 0; for (j=0; jgb, 8) << (8*(wt-j-1)); } -- 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 3/4] avcodec/mjpegdec: Decode to PAL8 independant of the location of LSE
This simply performs a 2nd pass if a LSE is encountered with GRAY8 Fixes: tickets/3933/128.jls Signed-off-by: Michael Niedermayer --- libavcodec/jpeglsdec.c | 6 -- libavcodec/mjpegdec.c | 10 +++--- libavcodec/mjpegdec.h | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c index d79bbe1ee3..bd9224d97d 100644 --- a/libavcodec/jpeglsdec.c +++ b/libavcodec/jpeglsdec.c @@ -118,8 +118,10 @@ int ff_jpegls_decode_lse(MJpegDecodeContext *s) shift = 8 - s->avctx->bits_per_raw_sample; } -s->picture_ptr->format = -s->avctx->pix_fmt = AV_PIX_FMT_PAL8; +s->force_pal8 = 1; +if (!pal) +return 1; + for (i=s->palette_index; i<=maxtab; i++) { uint8_t k = i << shift; pal[k] = 0; diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 7c66ff8637..0691148027 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -582,7 +582,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) case 0x4300: case 0x4400: if(s->bits <= 8) -s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; +s->avctx->pix_fmt = s->force_pal8 ? AV_PIX_FMT_PAL8 : AV_PIX_FMT_GRAY8; else s->avctx->pix_fmt = AV_PIX_FMT_GRAY16; break; @@ -681,7 +681,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) } else if (s->nb_components != 1) { av_log(s->avctx, AV_LOG_ERROR, "Unsupported number of components %d\n", s->nb_components); return AVERROR_PATCHWELCOME; -} else if (s->palette_index && s->bits <= 8) +} else if (s->palette_index && s->bits <= 8 || s->force_pal8) s->avctx->pix_fmt = AV_PIX_FMT_PAL8; else if (s->bits <= 8) s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; @@ -2398,6 +2398,8 @@ int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) int ret = 0; int is16bit; +s->force_pal8 = 0; + if (avctx->codec_id == AV_CODEC_ID_SMVJPEG && s->smv_next_frame > 0) return smv_process_frame(avctx, frame); @@ -2411,7 +2413,7 @@ int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) ret = mjpeg_get_packet(avctx); if (ret < 0) return ret; - +redo_for_pal8: buf_ptr = s->pkt->data; buf_end = s->pkt->data + s->pkt->size; while (buf_ptr < buf_end) { @@ -2542,6 +2544,8 @@ int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) if (!CONFIG_JPEGLS_DECODER || (ret = ff_jpegls_decode_lse(s)) < 0) goto fail; +if (ret == 1) +goto redo_for_pal8; break; case EOI: eoi_parser: diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index 2400a179f1..648dd714e1 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -117,6 +117,7 @@ typedef struct MJpegDecodeContext { uint8_t *last_nnz[MAX_COMPONENTS]; uint64_t coefs_finished[MAX_COMPONENTS]; ///< bitmask of which coefs have been completely decoded (progressive mode) int palette_index; +int force_pal8; ScanTable scantable; BlockDSPContext bdsp; HpelDSPContext hdsp; -- 2.17.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 2/2 v2] avcodec/mjpegdec: postpone calling ff_get_buffer() until the SOS marker
On Sat, May 01, 2021 at 12:18:02PM -0300, James Almer wrote: > On 5/1/2021 12:06 PM, James Almer wrote: > > On 5/1/2021 11:30 AM, James Almer wrote: > > > On 5/1/2021 11:17 AM, Michael Niedermayer wrote: > > > > On Sat, May 01, 2021 at 09:41:55AM -0300, James Almer wrote: > > > > > On 5/1/2021 4:01 AM, Michael Niedermayer wrote: > > > > > > On Thu, Apr 22, 2021 at 02:02:33PM -0300, James Almer wrote: > > > > > > > With JPEG-LS PAL8 samples, the JPEG-LS extension > > > > > > > parameters signaled with > > > > > > > the LSE marker show up after SOF but before SOS. For > > > > > > > those, the pixel format > > > > > > > chosen by get_format() in SOF is GRAY8, and then > > > > > > > replaced by PAL8 in LSE. > > > > > > > This has not been an issue given both pixel formats > > > > > > > allocate the second data > > > > > > > plane for the palette, but after the upcoming soname > > > > > > > bump, GRAY8 will no longer > > > > > > > do that. This will result in segfauls when > > > > > > > ff_jpegls_decode_lse() attempts to > > > > > > > write the palette on a buffer originally allocated as a GRAY8 one. > > > > > > > > > > > > > > Work around this by calling ff_get_buffer() after > > > > > > > the actual pixel format is > > > > > > > known. > > > > > > > > > > > > What if the LSE occurs after the SOS ? > > > > > > What if there are 2 LSE ? > > > > > > It seems allowed by the specification > > > > > > > > > > > > "The LSE marker segment may be present where tables or > > > > > > miscellaneous marker segments may appear. If tables > > > > > > specified > > > > > > in this marker segment for a given table ID appear > > > > > > more than once, each specification shall replace the > > > > > > previous > > > > > > specification." > > > > > > > > > > > > Maybe iam missing something but a implemenattion of this would seem > > > > > > to > > > > > > require scanning through the image, finding all LSE and > > > > > > checking if they all > > > > > > are compatible with the PAL8 format before allocating the image in > > > > > > SOF > > > > > > > > > > > > The implemenattion here which delays allocation slightly seems to > > > > > > make > > > > > > the code much more unstable allowing the frame > > > > > > configuration or allocation > > > > > > to be partly done, double done, redone, without the matching > > > > > > partner. > > > > > > Also it does not seem to implement the related > > > > > > specification completely. > > > > > > > > > > Well, it was a hack to replace a previous hack (allocate a > > > > > gray buffer then > > > > > silently treat it as PAL8 once an LSE showed up). It's no > > > > > wonder it may not > > > > > perfectly follow the spec and consider all potential cases. > > > > > > > > yes and i wouldnt mind but the new hack is leading to crashes ... > > > > and the fixes to the crashes all in all start looking a bit ugly > > > > and iam not > > > > sure if any more remain. So id like to take a bit a step back > > > > here and see > > > > if there isnt a easier/cleaner solution. > > > > > > > > > > > > > > > > > > > > > > > > > A complete implemenattion may reqire RGB24 or 48 to be > > > > > > selected in some cases > > > > > > like when each scan uses its own palette, which unless > > > > > > iam missing something > > > > > > seems allowed. > > > > > > But then maybe iam missing something, in which case please correct > > > > > > me! > > > > > > > > > > You're probably not wrong, since unlike me you actually know > > > > > this code and > > > > > format. I tried to workaround an issue and it seemed to work > > > > > and not break > > > > > any file anyone here could test. > > > > > > > > > > If you think it's not good enough then just revert it and > > > > > maybe allocate the > > > > > data[1] pointer for the palette with av_buffer_alloc(), > > > > > get_buffer2() custom > > > > > implementations be damned. But i don't think the previous > > > > > code even did half > > > > > the things you listed above. > > > > > > > > how can i reproduce the issue you where trying to fix with this patch ? > > > > > > It's the crash you reported in > > > https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2021-April/279350.html > > > > > > The explanation of why it started crashing is in c8197f73e6. > > > Basically, since GRAY8 no longer unnecessarily allocates a fixed > > > palette, the old hack of changing pix_fmt from GRAY8 to PAL8 after > > > having called ff_get_buffer() with the former, editing the palette > > > plane buffer, and have things magically work is not possible > > > anymore, because no palette buffer was ever allocated. > > > ff_get_buffer() is meant to be called once the actual pix_fmt is > > > known to correctly allocate all plane buffers. > > > > Another possible solution instead of my suggestion above (revert and > > then manually allocate a palette plane buffer, which can potentially > > piss off custom get_buffer2() implementations), is to revert and then > > initially set
[FFmpeg-devel] [PATCH 2/4] Revert "avcodec/mjpegdec: postpone calling ff_get_buffer() until the SOS marker"
This reverts commit c8197f73e684b0edc450f3dc2b2b4b3fb9dedd0d. --- libavcodec/jpeglsdec.c | 6 ++- libavcodec/mjpegbdec.c | 1 - libavcodec/mjpegdec.c | 83 +- libavcodec/mjpegdec.h | 3 -- libavcodec/mxpegdec.c | 2 +- 5 files changed, 39 insertions(+), 56 deletions(-) diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c index bf51d63c3a..d79bbe1ee3 100644 --- a/libavcodec/jpeglsdec.c +++ b/libavcodec/jpeglsdec.c @@ -108,8 +108,9 @@ int ff_jpegls_decode_lse(MJpegDecodeContext *s) if (s->palette_index > maxtab) return AVERROR_INVALIDDATA; -if (s->avctx->pix_fmt == AV_PIX_FMT_GRAY8 || s->avctx->pix_fmt == AV_PIX_FMT_PAL8) { -uint32_t *pal = s->palette; +if ((s->avctx->pix_fmt == AV_PIX_FMT_GRAY8 || s->avctx->pix_fmt == AV_PIX_FMT_PAL8) && +(s->picture_ptr->format == AV_PIX_FMT_GRAY8 || s->picture_ptr->format == AV_PIX_FMT_PAL8)) { +uint32_t *pal = (uint32_t *)s->picture_ptr->data[1]; int shift = 0; if (s->avctx->bits_per_raw_sample > 0 && s->avctx->bits_per_raw_sample < 8) { @@ -117,6 +118,7 @@ int ff_jpegls_decode_lse(MJpegDecodeContext *s) shift = 8 - s->avctx->bits_per_raw_sample; } +s->picture_ptr->format = s->avctx->pix_fmt = AV_PIX_FMT_PAL8; for (i=s->palette_index; i<=maxtab; i++) { uint8_t k = i << shift; diff --git a/libavcodec/mjpegbdec.c b/libavcodec/mjpegbdec.c index abc607176a..87eebb8771 100644 --- a/libavcodec/mjpegbdec.c +++ b/libavcodec/mjpegbdec.c @@ -55,7 +55,6 @@ static int mjpegb_decode_frame(AVCodecContext *avctx, buf_ptr = buf; buf_end = buf + buf_size; -s->seen_sof = 0; s->got_picture = 0; s->adobe_transform = -1; diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 16aed078f6..7c66ff8637 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -138,7 +138,6 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) s->buffer= NULL; s->start_code= -1; s->first_picture = 1; -s->seen_sof = 0; s->got_picture = 0; s->orig_height= avctx->coded_height; avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; @@ -430,7 +429,6 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) memcpy(s->h_count, h_count, sizeof(h_count)); memcpy(s->v_count, v_count, sizeof(v_count)); s->interlaced = 0; -s->seen_sof = 0; s->got_picture = 0; /* test interlaced mode */ @@ -683,13 +681,11 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) } else if (s->nb_components != 1) { av_log(s->avctx, AV_LOG_ERROR, "Unsupported number of components %d\n", s->nb_components); return AVERROR_PATCHWELCOME; -} else if (s->bits <= 8) { -avpriv_set_systematic_pal2(s->palette, s->avctx->pix_fmt); -if (s->palette_index) -s->avctx->pix_fmt = AV_PIX_FMT_PAL8; -else -s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; -} else +} else if (s->palette_index && s->bits <= 8) +s->avctx->pix_fmt = AV_PIX_FMT_PAL8; +else if (s->bits <= 8) +s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; +else s->avctx->pix_fmt = AV_PIX_FMT_GRAY16; } @@ -723,12 +719,25 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) if (s->avctx->skip_frame == AVDISCARD_ALL) { s->picture_ptr->pict_type = AV_PICTURE_TYPE_I; s->picture_ptr->key_frame = 1; -s->seen_sof = 1; +s->got_picture= 1; return 0; } -} -s->seen_sof = 1; +av_frame_unref(s->picture_ptr); +if (ff_get_buffer(s->avctx, s->picture_ptr, AV_GET_BUFFER_FLAG_REF) < 0) +return -1; +s->picture_ptr->pict_type = AV_PICTURE_TYPE_I; +s->picture_ptr->key_frame = 1; +s->got_picture= 1; + +for (i = 0; i < 4; i++) +s->linesize[i] = s->picture_ptr->linesize[i] << s->interlaced; + +ff_dlog(s->avctx, "%d %d %d %d %d %d\n", +s->width, s->height, s->linesize[0], s->linesize[1], +s->interlaced, s->avctx->height); + +} if ((s->rgb && !s->lossless && !s->ls) || (!s->rgb && s->ls && s->nb_components > 1) || @@ -755,6 +764,18 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) memset(s->coefs_finished, 0, sizeof(s->coefs_finished)); } +if (s->avctx->hwaccel) { +s->hwaccel_picture_private = +av_mallocz(s->avctx->hwaccel->frame_priv_data_size); +if (!s->hwaccel_picture_private) +return AVERROR(ENOMEM); + +ret = s->avctx->hwaccel->start_frame(s->avctx, s->raw_image_buffer, +
[FFmpeg-devel] [PATCH 1/4] Revert "avcodec/mjpegdec: fix SOF check in EOI"
This reverts commit fb5e2d71127ccae19c3f80ec363bb67d1871cb74. --- libavcodec/mjpegdec.c | 7 +-- 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index c829172200..16aed078f6 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -2560,16 +2560,11 @@ eoi_parser: s->progressive && s->cur_scan && s->got_picture) mjpeg_idct_scan_progressive_ac(s); s->cur_scan = 0; -if (!s->seen_sof) { +if (!s->got_picture) { av_log(avctx, AV_LOG_WARNING, "Found EOI before any SOF, ignoring\n"); break; } -if (!s->got_picture && avctx->skip_frame != AVDISCARD_ALL) { -av_log(avctx, AV_LOG_WARNING, - "Found EOI before any SOS, ignoring\n"); -break; -} if (s->interlaced) { s->bottom_field ^= 1; /* if not bottom field, do not output image yet */ -- 2.17.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 2/4] Revert "avcodec/mjpegdec: postpone calling ff_get_buffer() until the SOS marker"
On 5/2/2021 10:59 AM, Michael Niedermayer wrote: This reverts commit c8197f73e684b0edc450f3dc2b2b4b3fb9dedd0d. Applying this alone will break fate-jpegls, which is not good for bisectabiliy. Can you merge it with patch 3/4 before pushing? Or temporarily disable the tests in a separate commit before applying this one if you want 3/4 to be standalone, so the actual fix is readable in git history instead of lost merged with a revert. --- libavcodec/jpeglsdec.c | 6 ++- libavcodec/mjpegbdec.c | 1 - libavcodec/mjpegdec.c | 83 +- libavcodec/mjpegdec.h | 3 -- libavcodec/mxpegdec.c | 2 +- 5 files changed, 39 insertions(+), 56 deletions(-) diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c index bf51d63c3a..d79bbe1ee3 100644 --- a/libavcodec/jpeglsdec.c +++ b/libavcodec/jpeglsdec.c @@ -108,8 +108,9 @@ int ff_jpegls_decode_lse(MJpegDecodeContext *s) if (s->palette_index > maxtab) return AVERROR_INVALIDDATA; -if (s->avctx->pix_fmt == AV_PIX_FMT_GRAY8 || s->avctx->pix_fmt == AV_PIX_FMT_PAL8) { -uint32_t *pal = s->palette; +if ((s->avctx->pix_fmt == AV_PIX_FMT_GRAY8 || s->avctx->pix_fmt == AV_PIX_FMT_PAL8) && +(s->picture_ptr->format == AV_PIX_FMT_GRAY8 || s->picture_ptr->format == AV_PIX_FMT_PAL8)) { +uint32_t *pal = (uint32_t *)s->picture_ptr->data[1]; int shift = 0; if (s->avctx->bits_per_raw_sample > 0 && s->avctx->bits_per_raw_sample < 8) { @@ -117,6 +118,7 @@ int ff_jpegls_decode_lse(MJpegDecodeContext *s) shift = 8 - s->avctx->bits_per_raw_sample; } +s->picture_ptr->format = s->avctx->pix_fmt = AV_PIX_FMT_PAL8; for (i=s->palette_index; i<=maxtab; i++) { uint8_t k = i << shift; diff --git a/libavcodec/mjpegbdec.c b/libavcodec/mjpegbdec.c index abc607176a..87eebb8771 100644 --- a/libavcodec/mjpegbdec.c +++ b/libavcodec/mjpegbdec.c @@ -55,7 +55,6 @@ static int mjpegb_decode_frame(AVCodecContext *avctx, buf_ptr = buf; buf_end = buf + buf_size; -s->seen_sof = 0; s->got_picture = 0; s->adobe_transform = -1; diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 16aed078f6..7c66ff8637 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -138,7 +138,6 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) s->buffer= NULL; s->start_code= -1; s->first_picture = 1; -s->seen_sof = 0; s->got_picture = 0; s->orig_height= avctx->coded_height; avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; @@ -430,7 +429,6 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) memcpy(s->h_count, h_count, sizeof(h_count)); memcpy(s->v_count, v_count, sizeof(v_count)); s->interlaced = 0; -s->seen_sof = 0; s->got_picture = 0; /* test interlaced mode */ @@ -683,13 +681,11 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) } else if (s->nb_components != 1) { av_log(s->avctx, AV_LOG_ERROR, "Unsupported number of components %d\n", s->nb_components); return AVERROR_PATCHWELCOME; -} else if (s->bits <= 8) { -avpriv_set_systematic_pal2(s->palette, s->avctx->pix_fmt); -if (s->palette_index) -s->avctx->pix_fmt = AV_PIX_FMT_PAL8; -else -s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; -} else +} else if (s->palette_index && s->bits <= 8) +s->avctx->pix_fmt = AV_PIX_FMT_PAL8; +else if (s->bits <= 8) +s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; +else s->avctx->pix_fmt = AV_PIX_FMT_GRAY16; } @@ -723,12 +719,25 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) if (s->avctx->skip_frame == AVDISCARD_ALL) { s->picture_ptr->pict_type = AV_PICTURE_TYPE_I; s->picture_ptr->key_frame = 1; -s->seen_sof = 1; +s->got_picture= 1; return 0; } -} -s->seen_sof = 1; +av_frame_unref(s->picture_ptr); +if (ff_get_buffer(s->avctx, s->picture_ptr, AV_GET_BUFFER_FLAG_REF) < 0) +return -1; +s->picture_ptr->pict_type = AV_PICTURE_TYPE_I; +s->picture_ptr->key_frame = 1; +s->got_picture= 1; + +for (i = 0; i < 4; i++) +s->linesize[i] = s->picture_ptr->linesize[i] << s->interlaced; + +ff_dlog(s->avctx, "%d %d %d %d %d %d\n", +s->width, s->height, s->linesize[0], s->linesize[1], +s->interlaced, s->avctx->height); + +} if ((s->rgb && !s->lossless && !s->ls) || (!s->rgb && s->ls && s->nb_components > 1) || @@ -755,6
Re: [FFmpeg-devel] [PATCH 3/4] avcodec/mjpegdec: Decode to PAL8 independant of the location of LSE
On 5/2/2021 10:59 AM, Michael Niedermayer wrote: This simply performs a 2nd pass if a LSE is encountered with GRAY8 Fixes: tickets/3933/128.jls Signed-off-by: Michael Niedermayer --- libavcodec/jpeglsdec.c | 6 -- libavcodec/mjpegdec.c | 10 +++--- libavcodec/mjpegdec.h | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c index d79bbe1ee3..bd9224d97d 100644 --- a/libavcodec/jpeglsdec.c +++ b/libavcodec/jpeglsdec.c @@ -118,8 +118,10 @@ int ff_jpegls_decode_lse(MJpegDecodeContext *s) shift = 8 - s->avctx->bits_per_raw_sample; } -s->picture_ptr->format = -s->avctx->pix_fmt = AV_PIX_FMT_PAL8; +s->force_pal8 = 1; +if (!pal) +return 1; + for (i=s->palette_index; i<=maxtab; i++) { Can maxtab be < 255? The palette may need to be zeroed in that case, because get_buffer2 does not require this from implementations. avcodec_default_get_buffer2() does it when allocating buffers in the pool, though, but not after fetching them, so reused buffers may be dirty. They will also be dirty if memory_poisoning is enabled. Alternatively, avpriv_set_systematic_pal2() could be called with GRAY8 as pix_fmt argument, to maintain the pre-bump behavior of setting such initial values. uint8_t k = i << shift; pal[k] = 0; diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 7c66ff8637..0691148027 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -582,7 +582,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) case 0x4300: case 0x4400: if(s->bits <= 8) -s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; +s->avctx->pix_fmt = s->force_pal8 ? AV_PIX_FMT_PAL8 : AV_PIX_FMT_GRAY8; else s->avctx->pix_fmt = AV_PIX_FMT_GRAY16; break; @@ -681,7 +681,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) } else if (s->nb_components != 1) { av_log(s->avctx, AV_LOG_ERROR, "Unsupported number of components %d\n", s->nb_components); return AVERROR_PATCHWELCOME; -} else if (s->palette_index && s->bits <= 8) +} else if (s->palette_index && s->bits <= 8 || s->force_pal8) s->avctx->pix_fmt = AV_PIX_FMT_PAL8; else if (s->bits <= 8) s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; @@ -2398,6 +2398,8 @@ int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) int ret = 0; int is16bit; +s->force_pal8 = 0; + if (avctx->codec_id == AV_CODEC_ID_SMVJPEG && s->smv_next_frame > 0) return smv_process_frame(avctx, frame); @@ -2411,7 +2413,7 @@ int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) ret = mjpeg_get_packet(avctx); if (ret < 0) return ret; - +redo_for_pal8: buf_ptr = s->pkt->data; buf_end = s->pkt->data + s->pkt->size; while (buf_ptr < buf_end) { @@ -2542,6 +2544,8 @@ int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) if (!CONFIG_JPEGLS_DECODER || (ret = ff_jpegls_decode_lse(s)) < 0) goto fail; +if (ret == 1) +goto redo_for_pal8; break; case EOI: eoi_parser: diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index 2400a179f1..648dd714e1 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -117,6 +117,7 @@ typedef struct MJpegDecodeContext { uint8_t *last_nnz[MAX_COMPONENTS]; uint64_t coefs_finished[MAX_COMPONENTS]; ///< bitmask of which coefs have been completely decoded (progressive mode) int palette_index; +int force_pal8; ScanTable scantable; BlockDSPContext bdsp; HpelDSPContext hdsp; ___ 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/decode: stop trying to initialize palette values in avcodec_default_get_buffer2()
avpriv_set_systematic_pal2() is meant to fill fixed vales for formats that until recently were marked as "pseudo pal". It's not being called for them anymore in here, and it's a no-op when used on real PAL formats. Signed-off-by: James Almer --- libavcodec/decode.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index cd98c98a97..75bc7ad98e 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1425,8 +1425,6 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic) pic->data[i] = NULL; pic->linesize[i] = 0; } -if (desc->flags & AV_PIX_FMT_FLAG_PAL) -avpriv_set_systematic_pal2((uint32_t *)pic->data[1], pic->format); if (s->debug & FF_DEBUG_BUFFERS) av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p\n", pic); -- 2.31.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] [GSOC] avfilter: added guided filter
Added guided filter with subsampling and multithreading for speedup. --- doc/filters.texi | 25 +++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_guided.c | 400 +++ 4 files changed, 427 insertions(+) create mode 100644 libavfilter/vf_guided.c diff --git a/doc/filters.texi b/doc/filters.texi index 36e35a175b..856969f51f 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -12918,6 +12918,31 @@ greyedge=difford=1:minknorm=0:sigma=2 @end itemize +@section guided +Apply guided filter, spatial smoothing while preserving edges. + +The filter accepts the following options: +@table @option +@item radius +Set the spatial blur radius in pixels. +Allowed range is 1 to 1024. Default is 8. + +@item eps +Set regularization parameter (without square) as in the original paper. +Allowed range is 0 to 1. Default is 0.1. + +@item sub +Set subsampling ratio. +Allowed range is 1 to 1024. Default is 4. + +@item planes +Set planes to filter. Default is first only. +@end table + +@subsection Commands + +This filter supports the all above options as @ref{commands}. + @anchor{haldclut} @section haldclut diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 5a287364b0..f66c6ef65b 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -174,6 +174,7 @@ OBJS-$(CONFIG_AVGBLUR_FILTER)+= vf_avgblur.o OBJS-$(CONFIG_AVGBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o \ opencl/avgblur.o boxblur.o OBJS-$(CONFIG_AVGBLUR_VULKAN_FILTER) += vf_avgblur_vulkan.o vulkan.o +OBJS-$(CONFIG_GUIDED_FILTER) += vf_guided.o OBJS-$(CONFIG_BBOX_FILTER) += bbox.o vf_bbox.o OBJS-$(CONFIG_BENCH_FILTER) += f_bench.o OBJS-$(CONFIG_BILATERAL_FILTER) += vf_bilateral.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 931d7dbb0d..962f656abc 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -270,6 +270,7 @@ extern const AVFilter ff_vf_geq; extern const AVFilter ff_vf_gradfun; extern const AVFilter ff_vf_graphmonitor; extern const AVFilter ff_vf_greyedge; +extern const AVFilter ff_vf_guided; extern const AVFilter ff_vf_haldclut; extern const AVFilter ff_vf_hflip; extern const AVFilter ff_vf_histeq; diff --git a/libavfilter/vf_guided.c b/libavfilter/vf_guided.c new file mode 100644 index 00..2bb640f686 --- /dev/null +++ b/libavfilter/vf_guided.c @@ -0,0 +1,400 @@ +/* + * Copyright (c) 2021 Andrey Moskalenko + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 + * Guided filter. + * Principle of operation: + * Implemented the approach from the original article + * with multithread speedup of boxfilter and subsampling technique. + */ + +#include "libavutil/imgutils.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" +#include "avfilter.h" +#include "formats.h" +#include "internal.h" +#include "video.h" + +typedef struct GuidedContext { +const AVClass *class; +int radius; +float eps; +int sub; +int planes; +int nb_planes; +int depth; +int planewidth[4]; +int planeheight[4]; +float *I_mean; +float *I_pow; +float *A; +float *B; +float *buffer; +int (*filter_horizontally)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); +int (*filter_vertically)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); +} GuidedContext; + +#define OFFSET(x) offsetof(GuidedContext, x) +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM + +static const AVOption guided_options[] = { +{ "radius", "The box radius in pixels", OFFSET(radius), AV_OPT_TYPE_INT, {.i64=8}, 1, 1024, FLAGS }, +{ "eps", "Regularization parameter (without square)",OFFSET(eps), AV_OPT_TYPE_FLOAT, {.dbl=0.1}, 0.0, 1, FLAGS }, +{ "sub", "Subsampling ratio", OFFSET(sub), AV_OPT_TYPE_INT, {.i64=4}, 1, 1024, FLAGS }, +{ "planes", "Set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=1}, 0, 0xF, FLAGS }, +{ NULL } +}; + +typedef struct ThreadData { +int height; +int width; +float *ptr; +int
Re: [FFmpeg-devel] [PATCH] Add optional NIT table generation
On Tue, 27 Apr 2021, Ubaldo Porcheddu wrote: Signed-off-by: Ubaldo Porcheddu --- libavformat/mpegtsenc.c | 110 ++-- 1 file changed, 106 insertions(+), 4 deletions(-) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index a357f3a6aa..d03eaaa009 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -76,10 +76,12 @@ typedef struct MpegTSWrite { const AVClass *av_class; MpegTSSection pat; /* MPEG-2 PAT table */ MpegTSSection sdt; /* MPEG-2 SDT table context */ +MpegTSSection nit; /* MPEG-2 NIT table context */ MpegTSService **services; AVPacket *pkt; int64_t sdt_period; /* SDT period in PCR time base */ int64_t pat_period; /* PAT/PMT period in PCR time base */ +int64_t nit_period; /* NIT period in PCR time base */ int nb_services; int64_t first_pcr; int first_dts_checked; @@ -112,10 +114,13 @@ typedef struct MpegTSWrite { int tables_version; int64_t pat_period_us; int64_t sdt_period_us; +int64_t nit_period_us; int64_t last_pat_ts; int64_t last_sdt_ts; +int64_t last_nit_ts; int omit_video_pes_length; +int nit_enable; Instead of this, you should add a new MPEGTS_FLAG. } MpegTSWrite; /* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */ @@ -227,6 +232,7 @@ static int mpegts_write_section1(MpegTSSection *s, int tid, int id, #define SDT_RETRANS_TIME 500 #define PAT_RETRANS_TIME 100 #define PCR_RETRANS_TIME 20 +#define NIT_RETRANS_TIME 500 typedef struct MpegTSWriteStream { int pid; /* stream associated pid */ @@ -796,6 +802,75 @@ static void mpegts_write_sdt(AVFormatContext *s) data, q - data); } +static void mpegts_write_nit(AVFormatContext *s) +{ +int i, len=0, provider_len=0, desc_len=0, virtual_channel_value; +MpegTSWrite *ts = s->priv_data; +uint8_t data[SECTION_LENGTH], *q, *desc_len_ptr, *loop_len_ptr; +AVDictionaryEntry *provider, *virtual_channel; +AVProgram *program; +const char *provider_name; + +q = data; + +//network name +provider = av_dict_get(s->metadata, "service_provider", NULL, 0); +provider_name = provider ? provider->value : DEFAULT_PROVIDER_NAME; +provider_len = strlen(provider_name); +put16(&q, 0xf000 | provider_len); +*q++ = 0x40; +*q++ = provider_len; +putbuf(&q, provider_name, provider_len); encode_str8 should be used instead. Better yet, you should pre-calculate that at init time, and used the already encoded value here directly. + +//TS loop +loop_len_ptr = q; +q += 2; +put16(&q, ts->transport_stream_id); +put16(&q, ts->original_network_id); + +//transport descriptor +desc_len_ptr = q; +q += 2; + +//service list +len = 3 * ts->nb_services; +desc_len += len; +*q++ = 0x41; //tag +*q++ = len; +for(i = 0; i < ts->nb_services; i++) { + put16(&q, ts->services[i]->sid);//service_ID + *q++ = 0x01; //service type 0x01 for Digital TV Service ts->service_type Preferably you should use 4 space indentation. +} + +//private data +desc_len += 6 + 2; +*q++ = 0x5F; +*q++ = 4; +*q++ = 0x00; +*q++ = 0x00; +put16(&q, 40); What are these? + +//virtual channel +len = 4 * ts->nb_services; +desc_len += len + 2; +*q++ = 0x83; +*q++ = len; Simply *q++ = 4 * ts->nb_services +for (i = 0; i < ts->nb_services; i++) { + program = s->programs[i]; + virtual_channel = av_dict_get(program->metadata, "virtual_channel", NULL, 0); + virtual_channel_value = virtual_channel ? atoi(virtual_channel->value) : 1000+i; + put16(&q, ts->services[i]->sid); + put16(&q, 0xfc00 | virtual_channel_value); indentation +} + +//calculate lengths +put16(&desc_len_ptr, 0xf000 | desc_len); +put16(&loop_len_ptr, 0xf000 | desc_len+6); You should not calculate desc_len, you should use (q - desc_len_ptr) directly, it is less error-prone that way. + +mpegts_write_section1(&ts->nit, NIT_TID, ts->original_network_id, ts->tables_version, 0, 0, + data, q - data); +} + /* This stores a string in buf with the correct encoding and also sets the * first byte as the length. !str is accepted for an empty string. * If the string is already encoded, invalid UTF-8 or has no multibyte sequence @@ -1022,6 +1097,12 @@ static int mpegts_init(AVFormatContext *s) ts->sdt.write_packet = section_write_packet; ts->sdt.opaque = s; +ts->nit.pid = NIT_PID; +ts->nit.cc = 15; +ts->nit.discontinuity= ts->flags & MPEGTS_FLAG_DISCONT; +ts->nit.write_packet = section_write_packet; +ts->nit.opaque = s; + ts->pkt = av_packet_alloc(); if (!ts->pkt) return AVERROR(ENOMEM); @@ -1143,8 +1224,10 @@ static int mpegts_init(AVFormatContext *s) ts->last_pat_ts = AV_NOPTS_VALUE; ts->last_sdt_ts = AV_NOPTS_V
[FFmpeg-devel] [PATCH] avfilter/vf_subtitles: allow using embedded fonts
ASS subtitles can have encoded fonts embedded into the subtitle file itself. Allow libass to load those, to render subs as intended. --- A sample file for ASS with embedded font can be at the following link. If everything works, the 'A' will render as a quad; see image: https://raw.githubusercontent.com/TheOneric/libass-regression-tests-tmp/master/regression/embedded-font/efont.ass https://raw.githubusercontent.com/TheOneric/libass-regression-tests-tmp/master/regression/embedded-font/efont-1000.png Prior to libass commit 1140b6b885c89d37eef13dc1f31f144e9a76a4d7, included in libass release 0.15.1, a libass-bug would have prevented this from actually working. To test this a recent libass is therefore required. 'ass_extract_fonts' itself however has been part of libass' API ever since its first standalone release, so calling this does not break compatibility with older versions and at worst just nothing happens. Use eg the follwoing to check: ./ffmpeg -f lavfi -i "color=cyan:640x480:d=5" -vf "ass=efont.ass" -f matroska - | ./ffplay -autoexit - --- libavfilter/vf_subtitles.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c index 493eb5f424..ab32e1b7f3 100644 --- a/libavfilter/vf_subtitles.c +++ b/libavfilter/vf_subtitles.c @@ -111,6 +111,7 @@ static av_cold int init(AVFilterContext *ctx) ass_set_message_cb(ass->library, ass_log, ctx); ass_set_fonts_dir(ass->library, ass->fontsdir); +ass_set_extract_fonts(ass->library, 1); ass->renderer = ass_renderer_init(ass->library); if (!ass->renderer) { -- 2.20.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] ffmpeg: stop accessing private AVStream.codec_info_nb_frames
On 4/29/2021 11:38 AM, James Almer wrote: Use AVSTREAM_EVENT_FLAG_NEW_PACKETS instead, which should provide the same information in this case. Finishes removing all uses of this field as started by 87f0c8280c. Signed-off-by: James Almer --- fftools/ffmpeg_opt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index c0b9f023bd..849d24b16d 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2272,7 +2272,8 @@ static int open_output_file(OptionsContext *o, const char *filename) for (i = 0; i < nb_input_streams; i++) { int score; ist = input_streams[i]; -score = ist->st->codecpar->channels + 1*!!ist->st->codec_info_nb_frames +score = ist->st->codecpar->channels ++ 1 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS) + 500*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT); if (ist->user_set_discard == AVDISCARD_ALL) continue; Will apply. ___ 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] avutil/imgutils: don't add offsets to NULL pointers
Signed-off-by: James Almer --- libavutil/imgutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c index 53faad889a..aaee0dfb7a 100644 --- a/libavutil/imgutils.c +++ b/libavutil/imgutils.c @@ -166,7 +166,7 @@ int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int hei } data[0] = ptr; -for (i = 1; i < 4 && sizes[i]; i++) +for (i = 1; i < 4 && data[i - 1] && sizes[i]; i++) data[i] = data[i - 1] + sizes[i - 1]; return ret; -- 2.31.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".