2

Is there a way to convert svg files to png using ffmpeg on Windows 10 64bit?

I obviously tried ffmpeg -i "file.svg" "file.png" and it doesn't work by default.

Perhaps there is something to do that would make it work? Couldn't find anything for win10.

Something users can do using --enable-librsvg perhaps? Is there a command? Or do you have to download something?

EDIT:

If not ffmpeg, anything that works on win10 is welcomed, as long as I can convert lots of svg files at once.

goldnick7
  • 372
  • 2
  • 14
  • 1
    Can you edit your question and explain *why* this conversion must be done with ffmpeg, or, if not, what tools would be acceptable (e.g. anything FLOSS that runs in Windows 10). – bitinerant Jan 30 '21 at 01:05
  • @bitinerant done – goldnick7 Jan 30 '21 at 01:55
  • Have you tried IrfanView? It's as close a thing as there is to a universal image viewer/editor for Windows, and should be able to open SVG files and save them as PNG. – music2myear Jan 30 '21 at 02:23
  • `ffmpeg` requires to be compiled with `--enable-librsvg`. Unfortunately I do not see this included in the pre-compiled `ffmpeg` executables for Windows provided by [Gyan](https://www.gyan.dev/ffmpeg/builds/) or [BtbN](https://github.com/BtbN/FFmpeg-Builds/releases). So you would have to compile it yourself or ask one of them to include it. (Looks like [someone already asked Gyan](https://github.com/GyanD/codexffmpeg/issues/1)). – llogan Jan 30 '21 at 18:20
  • Refer to this answer may it will help you. https://superuser.com/a/260071/1073152 – HarshShah Feb 02 '21 at 06:08
  • BtbN says librsvg would make the build image too big because of all of the dependencies for librsvg. See [build with librsvg #24](https://github.com/BtbN/FFmpeg-Builds/issues/24) – llogan Feb 03 '21 at 17:23

1 Answers1

4

You best bet is to use Inkscape's command-line mode:

"C:\Program Files\Inkscape\bin\inkscape.exe" -o compass.png -w 1440 compass.svg

Full manpage here:

https://inkscape.org/doc/inkscape-man.html

From what I can tell, to do many images at once will require wrapping it in a loop in a batch file. Maybe something like:

FOR %%I in (*.svg) DO "C:\Program Files\Inkscape\bin\inkscape.exe" -o %%~nI.png -w 1440 %%I

EDIT:

You can also use Inkscape's --shell mode:

The input file (let's call it input.txt) should look something like this:

file-open:0001.svg;export-filename:0001.png;export-do;file-close;
file-open:0002.svg;export-filename:0002.png;export-do;file-close;
file-open:0003.svg;export-filename:0003.png;export-do;file-close;
file-open:0004.svg;export-filename:0004.png;export-do;file-close;
quit-inkscape;

Put as many input and output files into it as you'd like (though I found around 300 files was as much as I was comfortable doing at once, since sometimes it hangs). The SVG files have to exist already, and the PNG files will be created.

And you run it something like:

cd /path/to/folder/with/svgs
cat input.txt | inkscape --shell

Or, for Windows:

cd C:\path\to\folder\with\svgs
type input.txt | inkscape.exe --shell

What I actually ended up doing was putting it in a Python module. Single-threaded version:

https://github.com/clawsoon/chromosome_movie/blob/master/chromosome_movie/svg2png_basic.py

Multi-threaded version that runs multiple Inkscape instances in parallel in order to take advantage of multiple cores, since Inkscape itself seems to be limited to a single core:

https://github.com/clawsoon/chromosome_movie/blob/master/chromosome_movie/svg2png.py

I used this Python module to process almost a million SVGs for this video series:

https://www.youtube.com/watch?v=YbYzvS45vYI&list=PL0elTBjXjW_7oDLwWQCaDxKPSzCus5fAB

  • Works! 1. Downloaded & Installed Inkscape 2. Tested both commands and both worked at first try. Thanks! – goldnick7 May 05 '21 at 15:48
  • FWIW, I've since found a much faster way using Inkscape's shell mode. You create a text file with one line per SVG, where each line is "file-open:filename01.svg;export-filename:filename01.png;export-do;file-close;". You then pipe the text file into "inkscape.exe --shell" with something like "type svg_commands.txt | inkscape.exe --shell". I converted a couple of million fairly complex SVGs with a Python version of this, in batches of a few hundred at a time, at a rate of about 1 per second. – Andrew Klaassen Dec 23 '21 at 22:25
  • could you add all the `batch` files and the `instructions.txt` in a `ZIP` .. then upload it and share link? Otherwise maybe share a video showing the steps? Or make a post somewhere (google docs, reddit, pastebin) ... if it's easy... otherwise nvm... I rarely need to deal with svg files... your original solution is good enough for me. – goldnick7 Dec 24 '21 at 00:03
  • I'm in the middle of other projects right now, but I'll keep that in the back of my mind as something I could do when I get the time. Thanks for the suggestion. – Andrew Klaassen Dec 24 '21 at 16:33
  • I'm also interested in seeing this. Please post – Артем Jan 12 '23 at 22:02
  • I've added a section about inkscape --shell to my answer which will hopefully be enough to get people started. – Andrew Klaassen Jan 14 '23 at 14:13