AVI is a container, not a video codec. Converting an .avi file to .mp4 usually means decoding its video and audio tracks, encoding them into MP4-compatible formats, and writing a new container. HandBrake handles that workflow well—but the preset and track choices matter more than the filename extension.

Before you convert

  • Use media you own or are authorized to process; HandBrake is not a tool for defeating copy protection.

  • Check free disk space. During validation you need both the original and encoded file, and temporary storage may also be used.

  • Know the playback target: browser, phone, television, editor, archive, or upload service. Compatibility requirements should choose the preset.

  • Keep the original AVI as the source of truth. Transcoding is lossy unless a lossless encoder is deliberately selected, and encoding an already compressed source cannot restore missing detail.

  • For irreplaceable media, work from a verified copy and record a checksum before processing.

Install the official HandBrake build on Ubuntu

HandBrake’s current Linux documentation recommends the release it publishes through Flathub. It also warns that distribution or third-party builds can be broken or differ from upstream. The old ppa:stebbins/handbrake-releases instructions in this article are therefore retired.

1. Check whether Flatpak and Flathub are ready

Terminalbash
flatpak --version
flatpak remotes --columns=name,url

What those checks tell you

  • The first command confirms that the flatpak client is installed; it does not install or update anything.

  • The remotes list should include Flathub before you request fr.handbrake.ghb.

  • If Flatpak is missing, follow Ubuntu’s package guidance and Flathub’s setup page for your supported Ubuntu release rather than pasting an unverified repository command.

2. Install HandBrake for your user

Terminalbash
flatpak --user install flathub fr.handbrake.ghb

Risk level: caution. Review the command before running it.

Installation takeaways

  • --user installs only for the current account and normally avoids a system-wide privileged change. Remove it if your administrator intentionally manages a system-wide Flatpak installation.

  • flathub is the configured remote; fr.handbrake.ghb is HandBrake’s application ID. Review the runtime, permissions, download size, and remote shown at the confirmation prompt.

  • The official GUI Flatpak also includes HandBrakeCLI, so one installation supports both workflows.

  • Flatpak verifies content delivered through its repository, but you should still confirm you selected the intended remote and application ID.

3. Confirm the installed version

Terminalbash
flatpak info fr.handbrake.ghb
flatpak run --command=HandBrakeCLI fr.handbrake.ghb --version

Version-check takeaways

  • flatpak info identifies the installed branch, architecture, origin, runtime, commit, and installation scope.

  • The CLI version check executes the binary inside the same Flatpak application as the GUI.

  • Record the version in repeatable production workflows because preset definitions and available encoders can change between releases.

Convert AVI to MP4 in the HandBrake GUI

1. Launch HandBrake and open the source

Terminalbash
flatpak run fr.handbrake.ghb

Source-selection notes

  • Choose File and select the AVI, or drag an authorized local file into the window. HandBrake scans titles and tracks before enabling encode settings.

  • If the Flatpak cannot see the file, first move it into a normal user media directory or grant only the directory access you intend through your desktop’s Flatpak permission controls. Avoid blanket filesystem access.

  • A scan failure can mean unsupported, damaged, incomplete, encrypted, or inaccessible media; changing the extension will not repair it.

2. Start with a preset, then inspect it

For general computer and mobile playback, HandBrake documents Fast 1080p30 as a broadly compatible starting point. A preset is a complete bundle of container, encoder, resolution, frame-rate, audio, and filter choices—not merely a speed switch.

  • A 1080p30 preset caps higher-resolution and higher-frame-rate sources; it does not upscale a smaller source merely because “1080p” appears in the name.

  • Choose a device/web preset when its published constraints match the destination. Do not assume the newest codec is supported by an old TV, browser, or editing system.

  • Hardware presets can encode much faster but depend on detected GPU hardware and drivers. Compare quality and size on a representative clip before adopting one.

  • Do not pile arbitrary custom options onto a preset you do not understand. Save a named custom preset after a tested change so future jobs stay reproducible.

3. Set MP4, destination and filename

  • Confirm the Format is MP4 and choose a destination that is not the source path. A different extension does not prevent accidental overwrite if the path is otherwise wrong.

  • Use .mp4 for clarity. .m4v can also represent the MP4 family, but extension expectations vary across applications.

  • Choose Web Optimized only when progressive HTTP download is required; it rearranges MP4 metadata and does not improve picture quality.

  • Do not enable chapter markers, metadata pass-through, or alignment options by habit—retain only what the destination needs.

4. Review dimensions, filters and frame rate

  • Preserve the source aspect ratio. Stretching 4:3 to 16:9 distorts the image; cropping should remove only genuine border/overscan.

  • Use deinterlacing or detelecine only when source analysis shows the corresponding artifact. Unnecessary filters consume time and can soften progressive video.

  • “Same as source” preserves normal timing intent; constant frame rate can help editors or devices that reject variable frame rate, but it may duplicate or drop frames.

  • Test a short representative section if you are changing filters, scaling, frame rate, or encoder settings.

5. Review audio and subtitles

  • Inspect every desired language and commentary track. A preset may retain only one stereo track or drop discrete surround audio.

  • AAC stereo is widely compatible in MP4, while passthrough works only when the source codec and destination player/container support it. Configure a fallback for automation.

  • Choose whether subtitles should be selectable tracks, burned permanently into pixels, or excluded. Burning is irreversible and normally supports one rendered subtitle track.

  • Foreign-audio scan behavior is not a substitute for checking the actual output with your source.

6. Encode without deleting the evidence

  1. Set a new destination path and confirm available space.

  2. Use Preview for a short visual check when you changed picture or filter settings.

  3. Select Start Encode and watch the activity log for errors—not only the progress bar.

  4. Open the result in at least one target player, seek near the beginning/middle/end, and check every required audio/subtitle track.

  5. Retain the original until acceptance checks, backup, and downstream upload/import have succeeded.

Convert with HandBrakeCLI

The CLI is useful for repeatable jobs, servers, and scripts. Prefer a named official or tested custom preset over a long collection of unexplained flags. Preset names are case-sensitive and can differ by installed version.

List presets available on this machine

Terminalbash
flatpak run --command=HandBrakeCLI fr.handbrake.ghb --preset-list

Preset-list takeaways

  • --preset-list reports the definitions bundled with your installed version; it is safer than copying an old preset name from a blog.

  • Names containing spaces must be quoted in a shell. The match is case-sensitive.

  • A preset can limit resolution, frame rate, and tracks, so read its purpose before processing valuable media.

Encode one AVI with a compatibility preset

Terminalbash
flatpak run --command=HandBrakeCLI fr.handbrake.ghb \
  --input "$HOME/Videos/source.avi" \
  --output "$HOME/Videos/source-converted.mp4" \
  --preset "Fast 1080p30"

Risk level: caution. Review the command before running it.

CLI takeaways

  • --input reads the source and --output creates a separate destination. The command does not delete the AVI, but an existing output path can still be at risk—choose it deliberately.

  • --preset applies the full named preset. Command-line overrides after that can change its tested behavior.

  • Double quotes protect paths containing spaces and allow $HOME expansion. Keep externally supplied filenames out of shell evaluation in automation.

  • HandBrake prints its scan and encode log to the terminal. Save logs for failed production jobs, but inspect them for private paths and metadata before sharing.

Preview the exact invocation before running it

encode-one-video.shbash
#!/usr/bin/env bash
set -euo pipefail
 
input=${1:?"usage: encode-one-video.sh INPUT.avi OUTPUT.mp4"}
output=${2:?"usage: encode-one-video.sh INPUT.avi OUTPUT.mp4"}
 
[[ -f "$input" ]] || { printf "Input not found: %s\n" "$input" >&2; exit 66; }
[[ ! -e "$output" ]] || { printf "Output already exists: %s\n" "$output" >&2; exit 73; }
 
flatpak run --command=HandBrakeCLI fr.handbrake.ghb \
  --input "$input" \
  --output "$output" \
  --preset "Fast 1080p30"

A small guardrail for a single local encode; review the paths and preset before execution.

Why the wrapper is intentionally cautious

  • set -euo pipefail stops on command failure, unset variables, and failed pipeline components; it does not make arbitrary input automatically safe.

  • ${1:?...} and ${2:?...} require two positional arguments and print usage when either is missing.

  • [[ -f ... ]] requires a regular input file; [[ ! -e ... ]] refuses to overwrite any existing destination path.

  • Quoting preserves spaces and prevents pathname expansion. The filename is passed as an argument, not evaluated as shell code.

  • Exit codes 66 and 73 conventionally communicate missing input and output-creation conflicts to calling automation.

Understand quality, speed and file size

transcode-tradeoffs.txttext
source decode
     ├── filters / crop / scale / frame-rate policy
     ├── encoder + preset speed + quality target
     │          │
     │          └── CPU/GPU time ↔ compression efficiency ↔ visual quality
     ├── audio/subtitle selection and encoding
     └── MP4 muxing → new file → playback and track verification

Encoding choices are coupled; no single slider independently controls every result.

The practical tradeoffs

  • Constant-quality encoding targets visual quality rather than an exact size. A more demanding source can produce a larger file at the same quality setting.

  • Average bitrate/multi-pass is useful when a delivery budget matters, but it trades time and can allocate bits less naturally than a well-chosen quality target.

  • Slower software encoder presets usually improve compression efficiency, not source resolution or lost detail.

  • Hardware encoding prioritizes throughput. Whether its quality/size tradeoff is acceptable depends on the encoder generation, settings, source, and destination.

  • Re-encoding MP4 into MP4 again adds generation loss. Preserve an original/master and derive delivery versions from it.

Verify the output instead of trusting the extension

Terminalbash
ls -lh -- "$HOME/Videos/source.avi" "$HOME/Videos/source-converted.mp4"
file -- "$HOME/Videos/source-converted.mp4"

Basic verification takeaways

  • ls -lh compares sizes but a smaller file is not automatically better; quality and retained tracks still need inspection.

  • file identifies the container signature at a basic level. It does not validate every stream, timestamp, frame, subtitle, or decoder path.

  • -- ends command options, protecting filenames that begin with a hyphen.

  • Play and seek through the file in the actual target environment; inspect audio languages, channel layout, subtitles, duration, sync, rotation, aspect ratio, and visible artifacts.

Optional structural check with ffprobe

Terminalbash
ffprobe -v error \
  -show_entries format=format_name,duration,size:stream=index,codec_type,codec_name,width,height,channels \
  -of json \
  "$HOME/Videos/source-converted.mp4"

What ffprobe adds

  • ffprobe belongs to FFmpeg, not HandBrake, and may need a separately trusted installation.

  • The selected entries expose container names, duration, size, and key stream properties without dumping every metadata field.

  • A clean JSON report proves that ffprobe parsed the structure; it still does not replace decoding/playback and perceptual review.

  • Compare required streams with the source so a quiet encode does not hide a dropped language, subtitle, or surround track.

Troubleshooting map

  • HandBrake cannot open the AVI: verify read permission, complete transfer, actual container, and source integrity; capture the scan log.

  • Flatpak cannot see the folder: use the desktop file chooser or grant narrowly scoped directory access; do not disable the sandbox globally.

  • Output has no sound: inspect the Audio tab/preset, source track, codec compatibility, passthrough rules, and fallback.

  • Subtitles disappeared: add the intended track and choose soft subtitle versus burn-in deliberately.

  • Image is stretched or cropped: reset dimensions/crop, preserve aspect ratio, and preview representative scenes.

  • Output is unexpectedly huge: confirm the chosen preset/encoder/quality and that the source is not being upscaled; compare a short sample.

  • Encode is slow: software encoding is compute-intensive; inspect filters, preset speed, thermal throttling, and available supported hardware presets.

  • Player rejects the MP4: test its documented H.264/H.265/AV1 profile, level, frame-rate, audio, subtitle, and resolution limits—not just MP4 support.

  • Audio drifts out of sync: inspect source timestamps, variable frame-rate behavior, corruption, and activity log; test constant frame rate only when the target requires it.

  • CLI preset not found: run --preset-list on the installed version and match capitalization exactly.

A safe batch-encoding policy

  1. Test one representative file end to end and have a human approve quality and tracks.

  2. Freeze the HandBrake version and export/name the approved preset.

  3. Generate output into a separate directory; refuse collisions and partial-file promotion.

  4. Capture source checksum, command/preset, logs, exit status, output metadata, and verification result.

  5. Limit concurrency according to CPU/GPU, storage throughput, thermals, and service workload.

  6. Quarantine failures; never delete originals as a side effect of encoding.

  7. Promote outputs only after structural and playback sampling passes.

Primary references