Tips for video encoding settings for minimal file size💦
I. Core Principles & Codec Choice:
- Prioritize HEVC (H.265): For optimal compression, choose H.265 (HEVC) over H.264 if your target devices support it, as it offers 25-50% better efficiency for similar quality.
- Understand Your Goal: True "minimal file size" means a balance with "acceptable quality." Decide what quality compromise you're willing to make.
- Use Lossy Compression: Embrace that some data will be discarded to shrink the file. Lossless is rarely practical for minimal size.
- Know Your Target Devices: Ensure your chosen codecs and settings are compatible with where the video will be played.
- Use Modern Encoding Tools: Always use the latest stable versions of encoders (e.g.,
libx264
,libx265
) for the best algorithms.
- CRF (Constant Rate Factor) is King: For maximum quality-per-bit at minimal file size, use CRF for H.264/H.265.
- Find Your CRF "Sweet Spot": Start with higher CRF values (e.g., 23 for H.264, 28 for HEVC) and incrementally increase them until quality is unacceptable. Higher CRF = smaller size.
- Avoid ABR/CBR (if not streaming): Average Bit Rate (ABR) and Constant Bit Rate (CBR) are generally less efficient for file size than CRF. Use primarily for strict bandwidth targets.
- Two-Pass Encoding for ABR/CBR: If you must use ABR/CBR, always opt for two-pass encoding for better bit distribution and smaller files.
- Target Low Bitrates for Static Content: For videos with a static image, aim for extremely low video bitrates (e.g., 10-50 kbps) or use very high CRF values.
- Downscale Resolution Judiciously: The single biggest file size reducer. Only encode at the resolution needed for your target screen.
- Reduce Frame Rate: For content without fast motion (e.g., slideshows, talking heads), reduce frame rate to 24, 20, or even 15 fps.
- Crop Black Bars/Unwanted Content: Remove any dead space around the video frame before encoding.
- Deinterlace Properly: If your source is interlaced, deinterlace it correctly to progressive frames; interlacing artifacts waste bits.
- Remove Noise/Grain: Clean up excessive video noise (e.g., using a denoiser) before encoding, as noise is very hard to compress efficiently.
- Trim Unnecessary Content: Edit out any blank sections, long pauses, or irrelevant footage. Every second counts.
- Stabilize Shaky Footage: Stabilizing helps, as motion compensation for shaky video wastes bits.
- Avoid Unnecessary Filters: Don't apply filters that add complexity or noise unless absolutely essential for the content.
- Choose the Right Preset: Use slower presets (
slow
,medium
,fast
) for better compression efficiency (smaller file size) at the cost of encoding time.medium
is often a good balance.
- Optimize GOP Size: Set GOP (Group of Pictures) size to 2-4 seconds (e.g., 48-96 frames for 24fps video). Longer GOPs can save space but affect seeking.
- Maximize B-frames: Allow sufficient B-frames (e.g.,
bframes=3
to8
for x264/x265) for better compression.
- Increase Reference Frames: Use
ref=4
to8
to allow the encoder to reference more previous frames, improving prediction and saving bits.
- Use
tune
Settings: Apply the appropriatetune
(e.g.,film
,animation
,grain
,stillimage
) to optimize the encoder for your specific content type.stillimage
is critical for static backgrounds.
- Enable Adaptive Quantization (AQ): Keep AQ enabled (usually default); it intelligently distributes bits to visually important areas, making quality appear better at lower bitrates.
- Use Psycho-Visual Optimizations: Enable
psy-rd
andpsy-trellis
if available (often on by default inmedium
presets) for perceptually better quality at lower bitrates.
- Disable Deblocking Filter (Cautiously): While deblocking generally improves visuals, for extreme file size reduction, some might disable it to save a minuscule amount of bits, but beware of blocky artifacts.
- Avoid Excessive Slicing: Don't force too many slices or threads manually, as this can slightly reduce compression efficiency.
- Choose Appropriate Profile/Level: Stick to "Main" profile and common levels (e.g., 4.0 or 4.1 for H.264) for compatibility and good efficiency.
- Subpixel Motion Estimation: Use higher subpixel motion estimation settings for better motion prediction, reducing residual data that needs encoding.
- Utilize
lookahead
: Allow the encoder to look ahead at upcoming frames to make better encoding decisions (often controlled bylookahead-threads
or similar).
- Choose an Efficient Audio Codec: Use
AAC
orOpus
.Opus
is often more efficient for speech and general audio thanAAC
.
- Reduce Audio Bitrate: For
AAC
, start at 128 kbps (stereo) or 96 kbps (mono). ForOpus
, you can go lower (e.g., 64-96 kbps) for similar quality.
- Match Audio Channels: Encode in mono if the source audio is mono and stereo isn't necessary.
- Lower Sample Rate (Carefully): Consider reducing the audio sample rate from 48kHz to 44.1kHz or even 32kHz if quality loss is acceptable. Do not go below 22.05kHz for music.
- Normalize Audio Volume: Prevent audio peaks that might require higher bitrates to avoid clipping, ensuring consistent quality at lower bitrates.
- Trim Silence: Remove extended periods of silence from the audio track.
- Passthrough Audio if Possible: If the audio is already in an optimal format and bitrate, simply "copy" (passthrough) it to avoid re-encoding.
- Choose an Efficient Container:
.mp4
is widely supported and efficient for H.264/H.265..mkv
is also excellent.
- Minimize Metadata: Remove unnecessary metadata (tags, comments, etc.) from the final file.
- External Subtitles: Use external subtitle files (.srt, .vtt) instead of embedding them into the video stream (which uses more bits).
- Disable Chapter Markers (if unnecessary): If not needed, removing chapter markers can shave off a tiny bit of overhead.
- Test on Short Clips: Don't encode your entire video. Test settings on a small, representative segment to quickly evaluate results.
- Compare File Sizes & Quality: Always render multiple versions with different settings and compare their actual file size and visual/auditory quality.
- Use Objective Quality Metrics: For serious optimization, use tools that can calculate VMAF, SSIM, or PSNR to objectively compare quality between encodes.
- Iterate and Refine: Encoding is often an iterative process. Be prepared to adjust settings multiple times to find the optimal balance.
- Check Playback on Target Devices: Always test the final output on the devices your audience will use to ensure compatibility and smooth playback.
- Use a "Dummy" Video Stream for Audio-Only: If your primary content is audio with a truly static image (e.g., a podcast with a cover image), use video settings like
crf=51
or60
with a GOP of 1 and 0 B-frames. This makes the video portion almost negligible in file size.
- Consider CPU vs. GPU Encoding: For maximum compression efficiency per bit, CPU-based software encoders (like
libx264
/libx265
) are generally superior to hardware encoders (e.g., NVENC, Quick Sync), though slower.
- Avoid Unnecessary Keyframes: Only place keyframes (I-frames) where absolutely necessary (e.g., scene changes, or at regular intervals for seeking) to avoid wasting bits on redundant full frames.
- Stay Updated: Encoding algorithms and efficiency improve constantly. Keep your encoding software and libraries updated for the latest advancements.
How to set Video Encoding Settings for Minimal File Size in shotcut
Adjusted Video Encoding Settings for Minimal File Size (Static Image)
Codec:
libx264
- Keep as is. This is the correct codec for our purpose.
Rate control:
Quality-based VBR
- Keep as is. This mode uses CRF, which is ideal for this scenario.
Quality:
- Change
55 %
to something very low, representing a very high CRF value. The slider might move from100%
(lossless, CRF 0) down to0%
(lowest quality, highest CRF). You'll want to push this slider as far down as it can go while still being a valid H.264 stream. - Change
crf=23
tocrf=51
(or even higher if the software allows, e.g.,crf=60
or70
).crf=51
is the technical maximum for H.264 compression (lowest quality before becoming invalid) in standard encoders. For a static image, this is perfect for tiny file size.- If the slider is tied to CRF inversely (higher % means lower CRF), you might have to drag the slider to 0% or close to it to get CRF 51.
- Change
GOP:
- Change
150
frames to1
or2
frames.- For a static image, you essentially want only one keyframe (
I-frame
) at the start. A GOP of 1 or 2 ensures this. The encoder will then realize there are no changes and compress subsequent frames almost to nothing.
- For a static image, you essentially want only one keyframe (
- Change
B frames:
- Change
3
to0
.- B-frames provide compression benefits for moving video. For a static image, they offer no significant advantage and can add slight overhead, so disabling them is best.
- Change
Codec threads:
0
(0 = auto)
- Keep as is.
Auto
is fine. For such low data, the number of threads won't impact file size much.
- Keep as is.
Disable video: (checkbox)
- Keep unchecked. You still need a video stream, albeit an extremely compressed one.
Summary of Changes:
No comments:
Post a Comment