Back to Subtitle Style Generator
Developer Guide

How FFmpeg Works

A practical introduction to FFmpeg's multimedia processing pipeline, libraries, filtering system, and subtitle rendering.

What is FFmpeg?

FFmpeg is an open-source multimedia framework used to process video, audio, images, and subtitles. It provides command-line tools and libraries for reading, converting, filtering, encoding, decoding, and combining multimedia streams.

It is commonly used for tasks such as converting video formats, compressing media, extracting audio, resizing video, adding subtitles, and preparing media for different platforms.

The subtitle style generator on this website uses FFmpeg's subtitle filtering capabilities to help you experiment with subtitle appearance before processing a video.

The Core FFmpeg Workflow

A typical FFmpeg operation follows a pipeline that reads an input file, processes its media streams, and produces an output file. Depending on the command, FFmpeg may demux, decode, filter, encode, and mux the media.

[Input File] → (Demuxer) → [Encoded Packets] → (Decoder)

→ [Raw Frames] → (Filters / Processing) → [Raw Frames]

→ (Encoder) → [Encoded Packets] → (Muxer) → [Output File]

Not every FFmpeg operation requires every stage. For example, copying an existing stream without re-encoding can avoid the decoding and encoding stages. Subtitle rendering, however, requires video filtering and therefore produces processed video frames.

Containers, Streams, and Codecs

A video file such as an MP4 or MKV file is a container that can hold multiple media streams. These streams can include video, audio, subtitles, metadata, and other information.

A codec defines how a particular audio or video stream is encoded and decoded. For example, H.264 and H.265 are commonly used video codecs, while AAC is commonly used for audio.

FFmpeg separates these concepts so that the container format, individual streams, and codecs can be processed independently.

The FFmpeg Libraries

FFmpeg is more than a command-line application. Its functionality is provided by several libraries that can also be used by other software projects.

libavcodec

Provides encoders and decoders for many audio and video formats.

libavformat

Handles multimedia container formats and provides the functionality required for muxing and demuxing streams.

libavfilter

Provides the filtering framework used for operations such as scaling, color processing, video effects, and subtitle rendering.

libswscale

Provides image scaling and pixel format conversion functionality for video processing.

FFmpeg Filtering

FFmpeg filters process multimedia streams as part of the video or audio pipeline. Filters can modify frames, transform their dimensions, change colors, add effects, or render additional information onto the media.

A filter can be selected with the -vf option when working with video.

-vf "scale=1280:720"

The example above scales a video to 1280 by 720 pixels. Multiple filters can also be combined into a filter chain.

Rendering Subtitles with FFmpeg

FFmpeg can render subtitles onto video using the subtitles video filter.

A simple example looks like this:

ffmpeg -i input.mp4 -vf "subtitles=subtitles.srt" output.mp4

In this example, FFmpeg reads the input video, processes the subtitle file through the subtitles filter, renders the subtitles onto the video frames, and writes the processed video to the output file.

Understanding force_style

The force_style option can be used with the subtitles filter to override selected subtitle style properties during rendering.

This allows subtitle appearance to be controlled directly from the FFmpeg command instead of requiring the original subtitle file to contain every desired style setting.

For example, a command can specify properties such as font size, colors, bold or italic text, outline width, shadow, alignment, and vertical margins.

ffmpeg -i input.mp4 \
-vf "subtitles=subtitles.srt:force_style='FontName=Arial,FontSize=22,Bold=1,Alignment=2'" \
-c:a copy output.mp4

ASS Subtitle Styling

ASS, or Advanced SubStation Alpha, is a subtitle format that supports detailed styling information. It is commonly used when subtitles require more control over typography and positioning than basic subtitle formats provide.

FFmpeg's subtitle rendering pipeline can use ASS-style properties such as font name, font size, primary color, outline color, background color, alignment, margins, and other style attributes.

The exact appearance can depend on the subtitle renderer, available fonts, video dimensions, and the options supplied to FFmpeg.

Common Subtitle Style Parameters

FontName

Defines the font family used to render the subtitle text. The selected font must be available to the environment performing the rendering.

FontSize

Controls the size of the subtitle text. The appropriate value depends on the video resolution and the desired visual hierarchy.

PrimaryColour

Defines the primary color of the subtitle text using the color representation expected by ASS-style subtitle rendering.

OutlineColour

Defines the color used for the outline around subtitle characters. An outline can improve readability against complex backgrounds.

BackColour

Defines the background or shadow color used by the subtitle style, depending on the selected border configuration.

Bold and Italic

These properties control whether the subtitle text is rendered using bold or italic styling.

Outline

Controls the size of the subtitle outline. A larger outline can make text more readable when the video background has high visual complexity.

Shadow

Controls the subtitle shadow effect. Shadows can provide additional separation between subtitle text and the video.

Alignment

Determines the general position of the subtitle on the video, including top, middle, and bottom positions.

MarginV

Controls the vertical margin used when positioning subtitles. It is useful for moving subtitles farther from the corresponding edge of the video.

Using the Subtitle Style Generator

The FFmpeg Subtitle Style Generator provides a visual interface for experimenting with these styling parameters.

Instead of manually editing a long FFmpeg command, you can change the styling options in the browser and immediately see the result in the portrait and landscape previews.

When the style is ready, the generator creates an FFmpeg command containing the selected parameters.

Understanding the Generated Command

A typical generated command has this structure:

ffmpeg -i input.mp4 -vf "subtitles='YOUR_SUBS_FILE.srt':force_style='...'" -c:a copy output.mp4

Replace input.mp4 with the path to your source video and replace YOUR_SUBS_FILE.srt with your subtitle file.

The -c:a copy option tells FFmpeg to copy the audio stream without re-encoding it, when the selected output format supports the existing audio stream.

Example Subtitle Workflow

A typical workflow using the generator is:

  1. Open the subtitle style generator.
  2. Enter representative subtitle text.
  3. Choose the font size and text color.
  4. Adjust the background, outline, and shadow.
  5. Select the desired subtitle alignment.
  6. Preview the result in portrait and landscape formats.
  7. Copy the generated FFmpeg command.
  8. Replace the example input and subtitle file paths.
  9. Run the command with FFmpeg.

Things to Keep in Mind

A browser preview is useful for comparing styles, but the final appearance can vary slightly when the command is executed by FFmpeg. Differences can result from the installed fonts, subtitle renderer, video resolution, pixel format, and other processing settings.

For production video workflows, always test the generated command with the actual video and subtitle files that you intend to use.

Frequently Asked Questions

Is FFmpeg free?

FFmpeg is free and open-source software distributed under its applicable open-source licenses.

What is libavfilter?

libavfilter is the FFmpeg library responsible for the framework used to apply audio and video filters during media processing.

What is force_style?

force_style is an option of the subtitles filter that allows selected subtitle style properties to be overridden during rendering.

Does FFmpeg edit the original video?

FFmpeg normally reads the input file and creates a new output file. The original input remains unchanged unless a workflow explicitly replaces or modifies files outside the FFmpeg processing operation.

Why can subtitle rendering look different on different systems?

Font availability, renderer behavior, video resolution, subtitle format, and encoding settings can affect the final appearance.

Official FFmpeg Documentation

For complete technical details, filter options, command-line documentation, and implementation information, consult the official FFmpeg documentation.

Visit Official Documentation →

Ready to Create a Subtitle Style?

Use the generator to experiment with subtitle styling and create an FFmpeg command based on your selected options.

Open Subtitle Style Generator →