FFmpeg Ignores Input SVG Files’ Resolution, Produces 100x100 Video
When working with SVG files and FFmpeg to produce a video series in the .ogg format on a Linux system, a common issue that might arise is that FFmpeg seems to ignore the input SVG files’ resolution, resulting in a 100x100 video output.
Understanding the issue
Scalable Vector Graphics (SVG) is an XML-based vector image format for two-dimensional graphics with support for interactivity and animation. SVG images are defined in XML text files, which means they can be searched, indexed, scripted, and compressed.
FFmpeg is a free and open-source project consisting of a vast software suite of libraries and programs for handling video, audio, and other multimedia files and streams. It is widely used for format conversion, streaming, and playing multimedia content.
When attempting to convert a series of SVG files to an .ogg video format using FFmpeg on a Linux system, the following command might have been used:
ffmpeg -y -r 1.2 -i %06d.svg -qscale:v 10 path.ogg
However, this command produces a video of the size 100x100 instead of using the resolution of the input SVG files. This can result in low-quality output, which is not ideal.
Why FFmpeg ignores the SVG input files’ resolution
FFmpeg does not inherently support SVG input format. This is why FFmpeg cannot parse the input SVG files and determine their resolution.
To handle SVG files, FFmpeg relies on an external library, such as ImageMagick or Inkscape. These libraries can parse SVG files, extract their content, and rasterize them into a bitmap format that FFmpeg can understand.
However, these libraries do not provide the necessary information about the input SVG files’ resolution to FFmpeg.
Solutions
To work around this issue, there are several possible solutions. Here are a few:
-
Specifying an explicit resolution for the output video.
ffmpeg -y -s 1920x1080 -r 1.2 -i %06d.svg -qscale:v 10 path.oggThis will force FFmpeg to output a video of the specified resolution.
-
Using an external tool to determine the input files’ resolution and pass that information to FFmpeg through a filter.
ffmpeg -y -i %06d.svg -vf "fps=1.2,scale=-1:1080" -qscale:v 10 path.oggThis command will scale the input SVG files so that their height is 1080 pixels while preserving their aspect ratio.
-
Using a different tool than FFmpeg to convert SVG files to video.
For example, you could use the
imagemagickcommand-line tool to convert SVG files to individual frames and then use FFmpeg to convert those frames to a video.
- SVG is an XML-based vector image format for two-dimensional graphics
- FFmpeg does not inherently support SVG input format
- FFmpeg relies on external libraries to handle SVG input format
- The external libraries do not provide information about the input files’ resolution
- Specify an explicit resolution for the output video or scale the input files using a filter as a solution