FFmpeg provides low-level control over video and audio processing, covering everything from codecs and formats to filters and bitstreams. The primary difference between these workflows lies in the difference between encoding and transcoding. Encoding compresses raw, uncompressed data into a playable format, while transcoding takes an already compressed file and reprocesses it for new formats, devices, or bandwidth constraints.

Encoding with FFmpeg

Encoding is the process of converting raw, uncompressed video or audio into a compressed, usable format for storage, streaming, or playback. Raw video frames (e.g., YUV420p) or audio samples (e.g., PCM) are too large for practical storage or transmission, and encoding reduces these massive file sizes while preserving perceptual quality.

In practice, encoding is always the first step in a digital media workflow. It transforms raw input into a distribution-ready media file, such as MP4 or MKV.

FFmpeg Encoding Example:

code
ffmpeg -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -framerate 30 -i input.yuv -c:v libx264 -preset fast -crf 23 output.mp4

Explanation:

  • -c:v libx264: Uses the H.264 codec for video compression.
  • -preset fast: Specifies the encoding speed. 'Fast' balances encoding speed with compression efficiency.
  • -crf 23: Constant Rate Factor (CRF) controls video quality vs. bitrate. Lower values yield higher quality.
Banner

Transcoding with FFmpeg

Transcoding refers to the process of converting a compressed media format into another. This involves decoding the input file and then re-encoding it into a different format, codec, or resolution. Transcoding is used to adapt media for different devices, bandwidth constraints, or streaming requirements. Unlike encoding, transcoding can result in generational loss, where repeated compressions degrade quality.

Transcoding is commonly used for format conversion, resizing, or bitrate adjustment, such as optimizing video for streaming or ensuring compatibility with various devices.

FFmpeg Transcoding Example:

code
ffmpeg -i input.mkv -c:v libx265 -preset medium -crf 28 -c:a aac -b:a 128k output.mp4

This command converts an MKV file into an MP4 file using the H.265 codec for video and AAC for audio.

Resolution and Bitrate Adjustment Example:

code
ffmpeg -i input.mp4 -vf "scale=1280:720" -c:v libx264 -b:v 2000k -c:a copy output_720p.mp4

Explanation:

  • -vf "scale=1280:720": Resizes the video to 720p.
  • -b:v 2000k: Sets the video bitrate to 2000 kbps.
  • -c:a copy: Copies the audio stream without re-encoding to save processing time and avoid quality loss.

This example transcodes a video to a lower resolution and bitrate while keeping the original audio intact, making the file more suitable for limited bandwidth environments.

FFmpeg Encoding vs Transcoding

The main difference between encoding and transcoding lies in the type of input data:

Encoding starts with raw, uncompressed data (e.g., raw video or audio) and compresses it into a usable format for playback, storage, or streaming.

Transcoding begins with already compressed media and reprocesses it into a new format, resolution, or bitrate. This typically involves both decoding the original file and re-encoding it, which can lead to quality degradation due to generational loss.

AspectEncodingTranscoding
Input TypeRaw, uncompressed (YUV, PCM, image seq.)Already encoded/compressed media (MP4, MKV, MOV)
ProcessCompresses raw data directly into the codecDecodes input, applies processing, re-encodes
Typical UseInitial compression from raw captures.Format conversion, quality adjustment, streaming.
Quality ImpactControlled; highest quality from raw.Potential generational loss due to multiple compressions.
PerformanceLess resource-intensive (no decode step).More CPU/GPU and time due to decode + encode.

Developers can distinguish encoding from transcoding in FFmpeg by examining whether the input is raw or already compressed. Encoding generates an initial compressed stream, while transcoding reprocesses an existing one, with practical outcomes in storage efficiency, device compatibility, and streaming optimization.