diff mbox series

[FFmpeg-devel] image2 decoder: Add support for -skip_initial_bytes

Message ID CACA=nmhXJ-GuQt5d3y1HNWZm11o56k1RqXqoSdahEP8u3+6QgA@mail.gmail.com
State New
Headers show
Series [FFmpeg-devel] image2 decoder: Add support for -skip_initial_bytes | expand

Checks

Context Check Description
andriy/configure_x86 warning Failed to apply patch
yinshiyou/configure_loongarch64 warning Failed to apply patch

Commit Message

Thomas Newton May 20, 2022, 8:54 p.m. UTC
Relevant questions from the patch submission checklist:
Explanation why it changes things like it does:
Sometimes input data may have custom headers that ffmpeg is not expected to
understand. It seems to me, this is why `-skip_initial_bytes` exists. From
the documentation it sounds like this option should be supported on all
muxers and demuxers but it doesn't seem to work with image2.

Summary of user visible advantages:
Users wanting to use the image2 format for files with custom headers can
now do just that.

Example using this change:
`ffmpeg -y -skip_initial_bytes 32 -f image2 -c:v rawvideo -pix_fmt rgb24
-s:v 64x64 -ts_from_file 2 -pattern_type glob -i "*.RGB8" output.mp4`
From within the example.zip I've attached. This zip file also
includes `expected_output.mp4` for what the output should look like and
`corrupt_output.mp4` for what I get without this patch.

The patch contect itself:
---
Add support for -skip_initial_bytes when using the image2 decoder.
skip_initial_bytes is useful when the input data contains a custom header.
Previously this was not supported when using the image2 format.

Signed-off-by: Thomas Newton <thomas.w.newton@gmail.com>
---
 libavformat/img2dec.c | 2 ++
 1 file changed, 2 insertions(+)


         if (par->codec_id == AV_CODEC_ID_RAWVIDEO && !par->width)
diff mbox series

Patch

diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index 5f9d1f094f..19461aa200 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -474,6 +474,8 @@  int ff_img_read_packet(AVFormatContext *s1, AVPacket
*pkt)
             ifmt = av_probe_input_format3(&pd, 1, &score);
             if (ifmt && ifmt->read_packet == ff_img_read_packet &&
ifmt->raw_codec_id)
                 par->codec_id = ifmt->raw_codec_id;
+        } else {
+            avio_skip(f[i], s1->skip_initial_bytes);
         }