From patchwork Fri May 20 20:54:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Newton X-Patchwork-Id: 35855 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:9992:b0:82:461d:f3b with SMTP id ve18csp784767pzb; Fri, 20 May 2022 13:55:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznX0zXDn6DRO7EHkQ1QMqf6Wf8d+hNmTht8uNopjjoKTL1zXPlJIeMvzleXdNEZJNPr/kA X-Received: by 2002:a17:907:1c82:b0:6f4:d2ee:2f8e with SMTP id nb2-20020a1709071c8200b006f4d2ee2f8emr10608750ejc.714.1653080122130; Fri, 20 May 2022 13:55:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653080122; cv=none; d=google.com; s=arc-20160816; b=dfHBecboaaqzp3k9PfdWdruN42HhgD7k8yYsp4mD7AkPIQUG4Q32NCtNK+Rj9OGfX+ cV4zPWViThmzEzKQJk3svLurZ/0YMyr8agNZyXmyvpQtDCiSvY7XT5lSp4YCn5wsaUus UwwrJs7tU9+HILyF0YpA2shLL1R9R+NGMOYfb3E4/n0Ah5MUuQzyQWru3tYqnBnv8Vfy OcHudgi+bWrG3nyM1HUgWQD0ysbYMSmvtCx5+MQd7uYO6R40+b94FdzWd98zjPnQqYEt 7IhpWzsUze6ILQ4YkZeYbGWsUpBysr/GuSEifbt/lnKIZaBWnu9lcBG/NqA5RBtoqaNJ s70g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=fFJpUejW7hw4opp3Nd1HPT0QLWUmG3wa0iERDA4xZ8w=; b=faZt7lWeuHE+5WCSg5/PzNt9ZmDJHiS2dkJT+yCP/zo7a5Rl0Pk5EUHAEw/sni5HPc IfAEyIf63mg5U0UfKe5VV5JeRQPzvZze/mqzqHKzg/+ewNkTgXArOAJiiOiPZsPZRLzL MkcY7QyZjt+ea2xa5y2N6p4eHvoLLDJMUUVNZ7CBbEmMoNj+OjzmzrH/j5Ldrot3Yp2y VStQEmMXTVxGnHLtzXrfSzmzCPmYCfv/fJnMJrr+IHO5Xx81mpKXkCVOcG6EAmYKJ21l slaSCebsKpiEocKLt+WLW9wR80T6F+73LMvGURMRo1y3rT48zUc83sjlJQHLX0WQP2nP +VYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="A/1tgGjL"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k15-20020aa7c38f000000b0042aa0e072e0si8452214edq.612.2022.05.20.13.55.09; Fri, 20 May 2022 13:55:22 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="A/1tgGjL"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 048F068B49E; Fri, 20 May 2022 23:55:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AB8B468A214 for ; Fri, 20 May 2022 23:55:00 +0300 (EEST) Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-2ff7b90e635so33204787b3.5 for ; Fri, 20 May 2022 13:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=mUNn/gpcEdpKcV3KfylJIqT3+eo3n4iU88LaK8D84m8=; b=A/1tgGjLAi31EprfKJRoF380CLHrs7MBKdG6uQpRd5KHmGn8MBxGBnaCUvTgkZqEiY s3V9bbYzS1OXRE+KSqX0lXasV+Xrpf+b5BrirZQPbcPoXgY7Y8AI5cBzo7nSvVwuyh7D sUmI9GjNALyJ0AfAVz3R9+XoNNlvqg9xqela5o1Tz0rlaVHIRkWWKLCKWuX74M1v5S9p Evpk2zM0hZfPcZ9kl6jqK0cxcTqDPxk5d6jh5ncQBMzSc+FtVPeUab5U2tZDvynNvtTh K03bBj2o6JP1rpZc4SPVrPvyZeOfFpZC66FUoUO526CefyFhN3qwbRX9DyvmJ8CsnYdd g8vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=mUNn/gpcEdpKcV3KfylJIqT3+eo3n4iU88LaK8D84m8=; b=NvVqjmWcwI/pRzmER+3jXZQXX53nYcJmJR/uV2/+dfJCfyhzd2GlJKAZssajQGXNfQ 1j12rpXooxIEq01bvn+LZSqCNGQjth9G89JYJc4KKgVel/PezkGQHqyGVaTzHPLPIiRY W7CsNWtpGa+iTN8zbozQd77S4o/NYiPHq99hZCOiN87FmC+ADxlhlVy/xryjoB6gWjwb z0w7gI6xYfQQjWuvQgUSZ54J8fVlIpiXhcd1GRYv0w2+vnGUu5IQ8RlPiLp1pJpJuxi6 vDGWMvXkuS/cfNYNnrKoYOCnHk79PCJvar0fCth1sRh/SzFvHJmzGUfzLYm5SODM+t5W qFrg== X-Gm-Message-State: AOAM532XW64RWKoxrZsTSIevsn6Upr5On7b0OPZFon+PXWpZogxALHCt 0KEslKMVUQykImSOvytGwAnXbUzLSEfzAFvR/K1wIyQvnMY= X-Received: by 2002:a81:38c6:0:b0:2fe:dd1c:70f with SMTP id f189-20020a8138c6000000b002fedd1c070fmr11920814ywa.91.1653080095700; Fri, 20 May 2022 13:54:55 -0700 (PDT) MIME-Version: 1.0 From: Thomas Newton Date: Fri, 20 May 2022 21:54:43 +0100 Message-ID: To: ffmpeg-devel@ffmpeg.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [FFmpeg-devel] [PATCH] image2 decoder: Add support for -skip_initial_bytes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: KhaAhoy5lM63 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 --- libavformat/img2dec.c | 2 ++ 1 file changed, 2 insertions(+) if (par->codec_id == AV_CODEC_ID_RAWVIDEO && !par->width) 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); }