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

Thomas Newton thomas.w.newton at gmail.com
Fri May 20 23:54:43 EEST 2022


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 at gmail.com>
---
 libavformat/img2dec.c | 2 ++
 1 file changed, 2 insertions(+)

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);
         }

         if (par->codec_id == AV_CODEC_ID_RAWVIDEO && !par->width)
-- 
2.36.1
---
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example.zip
Type: application/x-zip-compressed
Size: 4393 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20220520/20a35e68/attachment.bin>


More information about the ffmpeg-devel mailing list