* Re: [FFmpeg-devel] [FFmpeg-cvslog] avcodec/mjpegenc: Simplify allocating huffman table
[not found] <20250326040856.71D62412944@natalya.videolan.org>
@ 2025-03-27 1:16 ` Michael Niedermayer
2025-03-27 2:12 ` Andreas Rheinhardt
0 siblings, 1 reply; 4+ messages in thread
From: Michael Niedermayer @ 2025-03-27 1:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
[-- Attachment #1.1: Type: text/plain, Size: 1976 bytes --]
On Wed, Mar 26, 2025 at 04:08:55AM +0000, Andreas Rheinhardt wrote:
> ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | Mon Mar 3 02:36:55 2025 +0100| [24dbc4c2e82481f89d6fcacee1949e5038c5c2fc] | committer: Andreas Rheinhardt
>
> avcodec/mjpegenc: Simplify allocating huffman table
>
> Reuse the already computed value of macroblocks; use an array
> instead of a switch, evaluate 64 * sizeof(MJpegHuffmanCode)
> at compile-time.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>
> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=24dbc4c2e82481f89d6fcacee1949e5038c5c2fc
> ---
>
> libavcodec/mjpegenc.c | 24 ++++++++++--------------
> 1 file changed, 10 insertions(+), 14 deletions(-)
Breaks: (did not investigate why)
./ffmpeg -i lena.pnm -strict -1 -s 4096x2048 -bitexact -y /tmp/file-4096x2048.m2v && ./ffmpeg -i /tmp/file-4096x2048.m2v -y -bitexact /tmp/file-4096x2048-dec.jpg
[vost#0:0/mjpeg @ 0x5576d6b7ab00] [enc:mjpeg @ 0x5576d6b79580] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
[vf#0:0 @ 0x5576d6b7f140] Error sending frames to consumers: Cannot allocate memory
[vf#0:0 @ 0x5576d6b7f140] Task finished with error code: -12 (Cannot allocate memory)
[vf#0:0 @ 0x5576d6b7f140] Terminating thread with return code -12 (Cannot allocate memory)
[vost#0:0/mjpeg @ 0x5576d6b7ab00] [enc:mjpeg @ 0x5576d6b79580] Could not open encoder before EOF
[vost#0:0/mjpeg @ 0x5576d6b7ab00] Task finished with error code: -22 (Invalid argument)
[vost#0:0/mjpeg @ 0x5576d6b7ab00] Terminating thread with return code -22 (Invalid argument)
[out#0/image2 @ 0x5576d6b7ec80] Nothing was written into output file, because at least one of its streams received no packets.
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
What does censorship reveal? It reveals fear. -- Julian Assange
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [FFmpeg-cvslog] avcodec/mjpegenc: Simplify allocating huffman table
2025-03-27 1:16 ` [FFmpeg-devel] [FFmpeg-cvslog] avcodec/mjpegenc: Simplify allocating huffman table Michael Niedermayer
@ 2025-03-27 2:12 ` Andreas Rheinhardt
2025-03-27 11:38 ` Andreas Rheinhardt
2025-03-27 17:55 ` Michael Niedermayer
0 siblings, 2 replies; 4+ messages in thread
From: Andreas Rheinhardt @ 2025-03-27 2:12 UTC (permalink / raw)
To: ffmpeg-devel
[-- Attachment #1: Type: text/plain, Size: 1893 bytes --]
Michael Niedermayer:
> On Wed, Mar 26, 2025 at 04:08:55AM +0000, Andreas Rheinhardt wrote:
>> ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | Mon Mar 3 02:36:55 2025 +0100| [24dbc4c2e82481f89d6fcacee1949e5038c5c2fc] | committer: Andreas Rheinhardt
>>
>> avcodec/mjpegenc: Simplify allocating huffman table
>>
>> Reuse the already computed value of macroblocks; use an array
>> instead of a switch, evaluate 64 * sizeof(MJpegHuffmanCode)
>> at compile-time.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>>
>>> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=24dbc4c2e82481f89d6fcacee1949e5038c5c2fc
>> ---
>>
>> libavcodec/mjpegenc.c | 24 ++++++++++--------------
>> 1 file changed, 10 insertions(+), 14 deletions(-)
>
> Breaks: (did not investigate why)
>
> ./ffmpeg -i lena.pnm -strict -1 -s 4096x2048 -bitexact -y /tmp/file-4096x2048.m2v && ./ffmpeg -i /tmp/file-4096x2048.m2v -y -bitexact /tmp/file-4096x2048-dec.jpg
>
> [vost#0:0/mjpeg @ 0x5576d6b7ab00] [enc:mjpeg @ 0x5576d6b79580] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
> [vf#0:0 @ 0x5576d6b7f140] Error sending frames to consumers: Cannot allocate memory
> [vf#0:0 @ 0x5576d6b7f140] Task finished with error code: -12 (Cannot allocate memory)
> [vf#0:0 @ 0x5576d6b7f140] Terminating thread with return code -12 (Cannot allocate memory)
> [vost#0:0/mjpeg @ 0x5576d6b7ab00] [enc:mjpeg @ 0x5576d6b79580] Could not open encoder before EOF
> [vost#0:0/mjpeg @ 0x5576d6b7ab00] Task finished with error code: -22 (Invalid argument)
> [vost#0:0/mjpeg @ 0x5576d6b7ab00] Terminating thread with return code -22 (Invalid argument)
> [out#0/image2 @ 0x5576d6b7ec80] Nothing was written into output file, because at least one of its streams received no packets.
>
Patch attached. Thanks for testing.
- Andreas
[-- Attachment #2: 0001-avcodec-mjpegenc-Don-t-allocate-unnecessarily-much-m.patch --]
[-- Type: text/x-patch, Size: 1543 bytes --]
From 11d68061103257173a3c065b176cc84ad63885a7 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Thu, 27 Mar 2025 03:03:02 +0100
Subject: [PATCH] avcodec/mjpegenc: Don't allocate unnecessarily much memory
We need to allocate space for 64 coefficients per block;
24dbc4c2e82481f89d6fcacee1949e5038c5c2fc wanted to
perform the calculation 64*sizeof(MJpegHuffmanCode)
at compile time, yet in the end did it in a way that
made it allocate 64 times as much memory as needed.
Reported-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mjpegenc.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 668065011c..214e2b0ec1 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -291,13 +291,12 @@ static int alloc_huffman(MJPEGEncContext *const m2)
static const char blocks_per_mb[] = {
[CHROMA_420] = 6, [CHROMA_422] = 8, [CHROMA_444] = 12
};
- size_t num_blocks, num_codes;
+ size_t num_blocks;
// Make sure we have enough space to hold this frame.
num_blocks = s->c.mb_num * blocks_per_mb[s->c.chroma_format];
- num_codes = num_blocks * 64;
- m->huff_buffer = av_malloc_array(num_codes,
+ m->huff_buffer = av_malloc_array(num_blocks,
64 /* codes per MB */ * sizeof(MJpegHuffmanCode));
if (!m->huff_buffer)
return AVERROR(ENOMEM);
--
2.45.2
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [FFmpeg-cvslog] avcodec/mjpegenc: Simplify allocating huffman table
2025-03-27 2:12 ` Andreas Rheinhardt
@ 2025-03-27 11:38 ` Andreas Rheinhardt
2025-03-27 17:55 ` Michael Niedermayer
1 sibling, 0 replies; 4+ messages in thread
From: Andreas Rheinhardt @ 2025-03-27 11:38 UTC (permalink / raw)
To: ffmpeg-devel
Andreas Rheinhardt:
> Michael Niedermayer:
>> On Wed, Mar 26, 2025 at 04:08:55AM +0000, Andreas Rheinhardt wrote:
>>> ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | Mon Mar 3 02:36:55 2025 +0100| [24dbc4c2e82481f89d6fcacee1949e5038c5c2fc] | committer: Andreas Rheinhardt
>>>
>>> avcodec/mjpegenc: Simplify allocating huffman table
>>>
>>> Reuse the already computed value of macroblocks; use an array
>>> instead of a switch, evaluate 64 * sizeof(MJpegHuffmanCode)
>>> at compile-time.
>>>
>>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>>>
>>>> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=24dbc4c2e82481f89d6fcacee1949e5038c5c2fc
>>> ---
>>>
>>> libavcodec/mjpegenc.c | 24 ++++++++++--------------
>>> 1 file changed, 10 insertions(+), 14 deletions(-)
>>
>> Breaks: (did not investigate why)
>>
>> ./ffmpeg -i lena.pnm -strict -1 -s 4096x2048 -bitexact -y /tmp/file-4096x2048.m2v && ./ffmpeg -i /tmp/file-4096x2048.m2v -y -bitexact /tmp/file-4096x2048-dec.jpg
>>
>> [vost#0:0/mjpeg @ 0x5576d6b7ab00] [enc:mjpeg @ 0x5576d6b79580] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
>> [vf#0:0 @ 0x5576d6b7f140] Error sending frames to consumers: Cannot allocate memory
>> [vf#0:0 @ 0x5576d6b7f140] Task finished with error code: -12 (Cannot allocate memory)
>> [vf#0:0 @ 0x5576d6b7f140] Terminating thread with return code -12 (Cannot allocate memory)
>> [vost#0:0/mjpeg @ 0x5576d6b7ab00] [enc:mjpeg @ 0x5576d6b79580] Could not open encoder before EOF
>> [vost#0:0/mjpeg @ 0x5576d6b7ab00] Task finished with error code: -22 (Invalid argument)
>> [vost#0:0/mjpeg @ 0x5576d6b7ab00] Terminating thread with return code -22 (Invalid argument)
>> [out#0/image2 @ 0x5576d6b7ec80] Nothing was written into output file, because at least one of its streams received no packets.
>>
>
> Patch attached. Thanks for testing.
>
> - Andreas
>
Will apply soon unless there are objections.
- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [FFmpeg-cvslog] avcodec/mjpegenc: Simplify allocating huffman table
2025-03-27 2:12 ` Andreas Rheinhardt
2025-03-27 11:38 ` Andreas Rheinhardt
@ 2025-03-27 17:55 ` Michael Niedermayer
1 sibling, 0 replies; 4+ messages in thread
From: Michael Niedermayer @ 2025-03-27 17:55 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 2330 bytes --]
On Thu, Mar 27, 2025 at 03:12:57AM +0100, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > On Wed, Mar 26, 2025 at 04:08:55AM +0000, Andreas Rheinhardt wrote:
> >> ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | Mon Mar 3 02:36:55 2025 +0100| [24dbc4c2e82481f89d6fcacee1949e5038c5c2fc] | committer: Andreas Rheinhardt
> >>
> >> avcodec/mjpegenc: Simplify allocating huffman table
> >>
> >> Reuse the already computed value of macroblocks; use an array
> >> instead of a switch, evaluate 64 * sizeof(MJpegHuffmanCode)
> >> at compile-time.
> >>
> >> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> >>
> >>> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=24dbc4c2e82481f89d6fcacee1949e5038c5c2fc
> >> ---
> >>
> >> libavcodec/mjpegenc.c | 24 ++++++++++--------------
> >> 1 file changed, 10 insertions(+), 14 deletions(-)
> >
> > Breaks: (did not investigate why)
> >
> > ./ffmpeg -i lena.pnm -strict -1 -s 4096x2048 -bitexact -y /tmp/file-4096x2048.m2v && ./ffmpeg -i /tmp/file-4096x2048.m2v -y -bitexact /tmp/file-4096x2048-dec.jpg
> >
> > [vost#0:0/mjpeg @ 0x5576d6b7ab00] [enc:mjpeg @ 0x5576d6b79580] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
> > [vf#0:0 @ 0x5576d6b7f140] Error sending frames to consumers: Cannot allocate memory
> > [vf#0:0 @ 0x5576d6b7f140] Task finished with error code: -12 (Cannot allocate memory)
> > [vf#0:0 @ 0x5576d6b7f140] Terminating thread with return code -12 (Cannot allocate memory)
> > [vost#0:0/mjpeg @ 0x5576d6b7ab00] [enc:mjpeg @ 0x5576d6b79580] Could not open encoder before EOF
> > [vost#0:0/mjpeg @ 0x5576d6b7ab00] Task finished with error code: -22 (Invalid argument)
> > [vost#0:0/mjpeg @ 0x5576d6b7ab00] Terminating thread with return code -22 (Invalid argument)
> > [out#0/image2 @ 0x5576d6b7ec80] Nothing was written into output file, because at least one of its streams received no packets.
> >
>
> Patch attached. Thanks for testing.
this fixes the issue
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The difference between a dictatorship and a democracy is that every 4 years
the population together is allowed to provide 1 bit of input to the government.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-27 17:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20250326040856.71D62412944@natalya.videolan.org>
2025-03-27 1:16 ` [FFmpeg-devel] [FFmpeg-cvslog] avcodec/mjpegenc: Simplify allocating huffman table Michael Niedermayer
2025-03-27 2:12 ` Andreas Rheinhardt
2025-03-27 11:38 ` Andreas Rheinhardt
2025-03-27 17:55 ` Michael Niedermayer
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git