3

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
  • 440
  • 1
  • 5
  • 14

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