From patchwork Mon Oct 2 09:42:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 5374 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.61.8 with SMTP id n8csp1318727jan; Mon, 2 Oct 2017 02:42:36 -0700 (PDT) X-Received: by 10.223.163.148 with SMTP id l20mr4570952wrb.73.1506937356371; Mon, 02 Oct 2017 02:42:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506937356; cv=none; d=google.com; s=arc-20160816; b=RjU8jTl3IhAa8T8nfB25ichxFY/3XA8K/DwJBncXxw+kuCHBfedLbgmCHLTDw26z02 b6uqHHRiqfNVTnxfU4mjZXP9bJyMcASNHFJJX/HzRzTqXd4lRBkFgCJZQM6+7ycj3QR4 W9m3puKRaTqw8uFtxiHLoRApWiSqd9do/BO3aVgTSTER5n4TOKRQQ8Th26BIKgLDULeM 6jwxV5Iw0t95m2ViWtJKAdZJGpXH1fAuHhlgnDIKtq7Ez4TLuEBCp/FMVtgNvA4oCf24 HYpky3BfCVCHIOstwS0ST+b3HZbeFVvKDPMx9Ebf8+OhBIJs2x5IgLNbdTtprUC7auPT wcaA== 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:references:in-reply-to:mime-version :dkim-signature:delivered-to:arc-authentication-results; bh=cxJD0o7N4PPg1mdVVoUeceswK8cjieEC2J7/LacLazc=; b=ngt1FmhXK4teSK7xgHBMbn07ZYPOHV3bqQCL2B7UDFc6uCqb+Qb1BJbmKRNgy2DsM0 /hSjbrRvaomWZNBrA2ehFRY4UHm5ZakREbApUbzq9n9VDdLOXDsu/q+rI2fjnO18hTwX H9G5hu6X/0OQKcyXAx6lJRw3K53gLIRTDfAhJN+9NRoLaUeXMW7xum3uDmZL35804GkC pkob3QG0adLIYCyEnajAGscwo3eUpz/36aj4gatfgU5J49SoZpuf8ySepGwTCgtSxct9 jYfM6ntghboW215/p5VOi/y9/+uvyRQlpoJ60ll+MNeNjotJ/BqhNxn/GxbmI6iphuKt yrlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=E6N1iXJd; 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=NONE 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 h142si363392wma.113.2017.10.02.02.42.35; Mon, 02 Oct 2017 02:42:36 -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=20161025 header.b=E6N1iXJd; 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=NONE 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 026AC68975C; Mon, 2 Oct 2017 12:42:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io0-f180.google.com (mail-io0-f180.google.com [209.85.223.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 12E67689A7F for ; Mon, 2 Oct 2017 12:42:11 +0300 (EEST) Received: by mail-io0-f180.google.com with SMTP id g32so4256808ioj.2 for ; Mon, 02 Oct 2017 02:42:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=tuUrwZXCr3ZI6ez08FKcA7bI/UqDKLPamFi+LRKz4gA=; b=E6N1iXJdVTivte9vDDoG0w3GKx7Qmut3MLxlSJVldgY1D1SHCjkXuLgxKfembD/OdB WvBNl0dFs2qSwu7Tjcqa+FiKdgfJKzUiKE1iwCCdXKjBZ+8YgR0nyVFevD+JsD9ebDut hK6qChcHOXf8/V7iU1uqIO3if0oG/wE2yb7mxr/chibsWsWYYRrmi2Zqe7gYV3L/prB+ D4oxwEczXM83F55htoLQLMylWcPC0hr+IQfZX7AQo125Ce0nn0WWrVEKl6R1DCyv7myf hWEIJ3M8WY13jOsXBHKfDG8YdBmVhVjogrgw7Vj3/lwlMQw+2F52PjP0lIBc3qisgrNb TYiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=tuUrwZXCr3ZI6ez08FKcA7bI/UqDKLPamFi+LRKz4gA=; b=oSXcuY+w90JZvd+tISpoA7A6K/P9vquMJ74g9bN1fCrlfS2UOdkGd/wSv/5QjjOFTF C/XmnUnhPnwEEUIYWIA50fuJ1p4K7UScUC+pWh+4F+I+mSO8JoQTBVT/3eB1ELM5e150 WyGE7peelTOMK5T6mn8nBwvz+CZZ2imDbpJjZWrPu4miAvHI6ZI/AdnyICAPjtJl/gFD +0yATIVTZazE/ISwuvlK6ZcS4IbE4VTdSrBW4qCcXYt40ckbvfL0ff3WiHkv2g2qymdO U7PaL3NIi6kgqqtI/YFwSzQpB4SXAoj+m1WIMQFPsIijAQcalMAfpXuGBZHlf4uMc7HV NzvQ== X-Gm-Message-State: AMCzsaUgv58Mf+imclkYAS8Gpl4yGJv/kT/D0rrTuvpNa5V5AZM610M1 m5WUNDfde//dCae5kRoFHhWiq+WN2i8lngDgR8c= X-Google-Smtp-Source: AOwi7QAtHoDzdODAIAqMz76Z1LYyRAGPIIwm/z3VB7rBPj7fK8/7Vt4ikgqcWukL3xCndcHTLbjh2oH+r947mcvO6io= X-Received: by 10.107.10.141 with SMTP id 13mr22536821iok.302.1506937343773; Mon, 02 Oct 2017 02:42:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.2.81.137 with HTTP; Mon, 2 Oct 2017 02:42:02 -0700 (PDT) In-Reply-To: <20171002055251.GF388@golem.pkh.me> References: <20171002055251.GF388@golem.pkh.me> From: Carl Eugen Hoyos Date: Mon, 2 Oct 2017 11:42:02 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH]lavf/img2dec: Auto-detect svg images X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" 2017-10-02 7:52 GMT+02:00 Clément Bœsch : > On Mon, Oct 02, 2017 at 01:20:15AM +0200, Carl Eugen Hoyos wrote: >> Hi! >> >> Attached patch implements auto-detection of svg images. >> >> Please review, Carl Eugen > >> From f06137f38f166740565e58d5c7c88777508f59ec Mon Sep 17 00:00:00 2001 >> From: Carl Eugen Hoyos >> Date: Mon, 2 Oct 2017 01:13:29 +0200 >> Subject: [PATCH] lavf/img2dec: Auto-detect svg images. >> >> --- >> libavformat/img2dec.c | 17 +++++++++++++++-- >> 1 file changed, 15 insertions(+), 2 deletions(-) >> >> diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c >> index 19cae87..468c820 100644 >> --- a/libavformat/img2dec.c >> +++ b/libavformat/img2dec.c >> @@ -34,6 +34,7 @@ >> #include "internal.h" >> #include "img2.h" >> #include "libavcodec/mjpeg.h" >> +#include "subtitles.h" >> >> #if HAVE_GLOB >> /* Locally define as 0 (bitwise-OR no-op) any missing glob options that >> @@ -875,8 +876,20 @@ static int sunrast_probe(AVProbeData *p) >> >> static int svg_probe(AVProbeData *p) >> { >> - if (av_match_ext(p->filename, "svg") || av_match_ext(p->filename, "svgz")) >> - return AVPROBE_SCORE_EXTENSION + 1; >> + const uint8_t *b = p->buf; >> + const uint8_t *end = p->buf + p->buf_size; >> + if (memcmp(p->buf, "> + return 0; >> + while (b < end) { >> + b += ff_subtitles_next_line(b); >> + if (b >= end) >> + return 0; > >> + if (!strstr(b, "> + continue; > > at least the svg from inkscape do not have a doctype Wrong check, thank you. >> + b += 9; >> + if (strstr(b, "svg")) >> + return AVPROBE_SCORE_MAX; >> + } > > don't you want to keep an extension fallback? That's done by the image2 demuxer. > also, I would guess strstr() is going to be slow, so maybe > just look for a line starting with " Date: Mon, 2 Oct 2017 11:38:34 +0200 Subject: [PATCH] lavf/img2dec: Auto-detect svg images. --- libavformat/img2dec.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index 19cae87..ecf64ea 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -34,6 +34,7 @@ #include "internal.h" #include "img2.h" #include "libavcodec/mjpeg.h" +#include "subtitles.h" #if HAVE_GLOB /* Locally define as 0 (bitwise-OR no-op) any missing glob options that @@ -875,8 +876,17 @@ static int sunrast_probe(AVProbeData *p) static int svg_probe(AVProbeData *p) { - if (av_match_ext(p->filename, "svg") || av_match_ext(p->filename, "svgz")) - return AVPROBE_SCORE_EXTENSION + 1; + const uint8_t *b = p->buf; + const uint8_t *end = p->buf + p->buf_size; + if (memcmp(p->buf, "= end - 4) + return 0; + if (!memcmp(b, "