From patchwork Thu Nov 25 19:36:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alex Xu (Hello71)" X-Patchwork-Id: 31707 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp1246395iob; Thu, 25 Nov 2021 11:36:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3h/8mMP3SM72zNVmaWuCJUDbE0V+ug6IcMI+NpKgg8TJpAM8FXV3hPul4+Baufw9l0qUj X-Received: by 2002:aa7:c390:: with SMTP id k16mr42696919edq.161.1637868999995; Thu, 25 Nov 2021 11:36:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637868999; cv=none; d=google.com; s=arc-20160816; b=E2Z1KQN4V26R/8d+InaULGf8eAaaYhtQgBvOLiHSspz97jbwYyU1hC9E1t3+D2q+Wx 3TsXGjSzE9XXAw7g/kqs5+eiKY0iy2pehfSlnnJ2tXyNs2BNQWHzehttmBHDsAwt2MK8 XOuOUPOSKpRow5Wbx9SHVIle0OOzUxnbLSCYHqAADaKxoEBD1GNze07go0/9W3Oyb1YF AHtX/QB32pHTbwSAV84eHfuXb9o0cbau3bk+10hFFaJ/XtGH9dciohrD7MIgtD//a9I7 92CPp5R3qAtR01GcbyHvwa+s0sz/0c25gVQxyPeEPtV9v1rbT8gMtT//5EMICwasiIw8 SchA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:message-id:mime-version:references:to:from:date :dkim-signature:delivered-to; bh=B832Od0OewHwHPcLPzrmErn8Tgk/5nhUZVFM/TqIsqw=; b=tXBnbowL7cIn1ubIPSk22t33qyx/aVQ1o1e/aWRZzDmNZN9ynaEnXpWg/F7uFv/FO7 7h1PiyyLWcjxPX4l4QVJ48Ug6x5Vk2T8cvExWCfcl/dG3FQ62YKdLBpJpPE9PiE3Wfzr n/tpCPv/6Hr9L9Lj0VrnERBoHuRdizre1E76FPGqNK9/0Cms9QybUhsdEIaz+xG4cBhR gWhfI3BckGV+GI2gVrAYif42duWfCZiy/+qwEp+6vaCYwYQlG636E0+tA7kQ1jZJxdO1 8B184glU5R1YEG1Evw1526MhYlHUsyeVOSkgxqatIH2bVIUISRrUQsb7+hd9pPfiXudU u/zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@yahoo.ca header.s=s2048 header.b=YBOWwwJM; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e1si10452896ejs.40.2021.11.25.11.36.38; Thu, 25 Nov 2021 11:36:39 -0800 (PST) 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=@yahoo.ca header.s=s2048 header.b=YBOWwwJM; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3FD2F68ADC0; Thu, 25 Nov 2021 21:36:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from sonic314-20.consmr.mail.gq1.yahoo.com (sonic314-20.consmr.mail.gq1.yahoo.com [98.137.69.83]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 51DD9680610 for ; Thu, 25 Nov 2021 21:36:28 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.ca; s=s2048; t=1637868986; bh=b10AZ8wSOqCSK/AomprnjaUmhHrEcuouuDBGWp4zNSA=; h=Date:From:Subject:To:References:From:Subject:Reply-To; b=YBOWwwJMd0AGveb8ofs3MY4Hn0tCdgHYKr4Fs+StYk0ifzxBn7uYl6ePuOauCJVeuyQXUDtEe3FkbuN+n9HaFaV9+IEJxMdT89ZBs7g08N1mknATazo6KYLApDeeXQ2MkYnB83xXweE5rOT1hJ0MBEPsXLTumrhqef40ScemygYdQ6mUlq/Kp03Ss7EVo7gEA4jMlme9ANDVwtAvInMaKZbLNIynHl3QWznndrs8ZiGOK89bcGYtECEqriSIJvWdKe7mwfQrivNGLI+YGbtTlyvaSuNMQXfNPCkZJNuCApr2j4Kunce9Wy8Ew+VKuHxRJyo28ONHh/ODkmMAs/1MqQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1637868986; bh=pcLCT2FjInVpQPQVmY8hm5ru74durgkSq5gBGVrxVMb=; h=X-Sonic-MF:Date:From:Subject:To:From:Subject; b=AP/aOzkddBVdgbEd3UEVNKK/jZcuQ1v9oMVggKwU6D/4vg2MQF9u5LkJo3lnaghqn/sVnHLiS4vdxtAOHyaelqlWtk6Kqn9Gc8NlvzoYuwB4nYsWGNfxe2BYv4rjoI02QydlG6QhlBokRwS6N19PgNw1q0vQSeicsl7nsIwfRNpxLfCUckrY1E1l0ZP6qs3A4Ho3rRFaG87o44OSoEVs9X4357zcIQh2Xyw+0W3a99sKcYEZS+tQo5NBU4vs0kz4rR411dZDiIZPqpcufYL2wSkN/rl3Rq9SolDVWmJFCGwZa/GSwPl8NNtrqVc3O3UWAhNX28a04q/xuUlJR9a8qg== X-YMail-OSG: JLY57IcVM1mOh9P83znMEVJKSO0goRjLeKya0jJpJDSLtY4huz0tELFukA70oXI 0wJ4i7.yv_JalzS7u3OJmiyqx3RJhiYKzcC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tW5tEySFbpnLpUioYhYe7pblTqsP.jtW2Vy9Lo8- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.gq1.yahoo.com with HTTP; Thu, 25 Nov 2021 19:36:26 +0000 Received: by kubenode512.mail-prod1.omega.bf1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 602428142aea96bec5e165218cc7dde7; Thu, 25 Nov 2021 19:36:20 +0000 (UTC) Date: Thu, 25 Nov 2021 14:36:46 -0500 From: "Alex Xu (Hello71)" To: ffmpeg-devel@ffmpeg.org References: <20211117174827.81449-1-alex_y_xu.ref@yahoo.ca> MIME-Version: 1.0 Message-Id: <1637868248.utcsp6528a.none@localhost> X-Mailer: WebService/1.1.19306 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Subject: [FFmpeg-devel] [PATCH] avformat/img2dec: probe JFIF/Exif header 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: DLvWdjysJLXC Due to reasons, mpv doesn't pass filename when probing. mpv also sets default probescore threshold to 26. Since the current jpeg_probe implementation returns 25 until EOI, it means that the whole image needs to be probed to succeed. Worse, the whole image is not passed at once; increasingly large buffers are tried before that. Adding it up together, if many demuxers are enabled, moderately large JPEG files (few MB) can take several seconds to open, despite taking less than 1 second to actually decode. Therefore, adjust the heuristic to be more optimistic if proper JFIF or Exif segments are found. While not strictly required, the vast majority of JPEG-ish files have one or the other or both. --- libavformat/img2dec.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index b535831e1c..a6084ceef0 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -749,7 +749,7 @@ static int j2k_probe(const AVProbeData *p) static int jpeg_probe(const AVProbeData *p) { const uint8_t *b = p->buf; - int i, state = SOI; + int i, state = SOI, got_header = 0; if (AV_RB16(b) != 0xFFD8 || AV_RB32(b) == 0xFFD8FFF7) @@ -789,7 +789,11 @@ static int jpeg_probe(const AVProbeData *p) break; case DQT: case APP0: + if (AV_RL32(&b[i + 4]) == MKTAG('J','F','I','F')) + got_header = 1; case APP1: + if (AV_RL32(&b[i + 4]) == MKTAG('E','x','i','f')) + got_header = 1; case APP2: case APP3: case APP4: @@ -817,7 +821,7 @@ static int jpeg_probe(const AVProbeData *p) if (state == EOI) return AVPROBE_SCORE_EXTENSION + 1; if (state == SOS) - return AVPROBE_SCORE_EXTENSION / 2; + return AVPROBE_SCORE_EXTENSION / 2 + got_header; return AVPROBE_SCORE_EXTENSION / 8 + 1; }