Free lesson

Inspect files and define a CLI project

Inspect files and define a CLI project — Automate simple video editing with FFmpeg. Container and codec answer different questions; Probe before conversion; Options belong to specific inputs or outputs. Practical assignment: Inspect files and define a CLI project.

Demo edition. The materials are undergoing editorial review.

Topics covered

  • Container and codec answer different questions
  • Probe before conversion
  • Options belong to specific inputs or outputs

Container and codec answer different questions

MP4 is a container; H.264 is a video codec and AAC a possible audio codec. Matching extensions do not prove two files can be directly concatenated. In ffmpeg-lab put owned clip-a.mp4 and clip-b.mp4 under originals and create work and exports. Never edit originals in place. The fictional exercise takes five seconds from the first clip and four from the second, joins them and exports H.264/AAC locally. Sources must be long enough. Free FFmpeg does not provide free cloud hardware or rights to other people’s footage. Inspect your build and available codecs before batching. The examples use simple controlled paths; do not concatenate shell code from arbitrary filenames supplied by a document or model. Complex paths require correct process arguments, not guessed quoting. Save tool version with each recipe.

Probe before conversion

ffprobe reads structure without rewriting. Save JSON for both sources and inspect video codec, width/height, pixel format, frame rate, time_base and audio sample rate/channels. r_frame_rate and avg_frame_rate may differ; smartphone footage may be variable-frame-rate. Rotation metadata also affects display even when dimensions look horizontal. Do not choose a crop from numbers alone; view the file. Container and stream durations can differ, calling for inspection rather than automatic audio truncation. Multiple audio streams require explicit language selection. Create inventory.md with parameters and normalization intent. If ffprobe cannot open a file, check paths and permissions rather than renaming its extension and calling that codec repair. Probe describes technical structure, not picture quality or voice intelligibility.

ffprobe -v error -show_streams -show_format -of json originals/clip-a.mp4 > work/clip-a-probe.json
ffprobe -v error -show_streams -show_format -of json originals/clip-b.mp4 > work/clip-b-probe.json

Options belong to specific inputs or outputs

-i introduces an input, while an output path names the destination; many options apply to the next file. -ss before -i controls input seeking, whereas placement afterward changes its processing role. -c:v libx264 before an output selects its video encoder. -map 0:v:0 selects the first input’s first video; -map "0:a:0?" permits missing audio but does not satisfy a spoken lesson’s audio requirement. Quotes protect ? from shell globbing, especially in zsh. Use -n initially to prevent accidental output overwrites. It is not complete idempotency: a repeat simply refuses the existing path. A recipe must validate an existing artifact rather than equating file presence with success. Save commands.sh as teaching text first and inspect every input/output, ensuring originals never appears as an output destination.

Practical assignment

Inspect files and define a CLI project

Continue to learning

Course outline

  1. Inspect files and define a CLI project
  2. Trimming: fast copy or precise transcoding
  3. Normalize clips and join without accidental gaps
  4. Audio level and subtitle filters
  5. Batch execution, validation and safe reruns
  6. Verify delivery and hand off a reproducible CLI project