Skip to content
Cutfac

8 ffmpeg commands for Shorts, run with Claude Code

ffmpeg can do almost anything to a video file, and its commands are hard to remember: the order of the options changes what they do, and a command that looks right can make a file that plays wrong in one app and fine in another. With Claude Code you say what you want and it writes the command, but it still helps to know what a good command looks like and how to check what it made. This guide runs eight commands people often need for Shorts on real Shorts, and shows for each one what to ask, the command Claude Code ran, what it printed, and what each part does.

Published:

What we're working with

Three Shorts made in the guide to turning one long video into several Shorts: heat.mp4, likely.mp4 and music-box.mp4, each 1080 × 1920 at 25 frames a second, between 36 and 45 seconds long. For the last recipe, the interview they were cut from, interview.webm, 10 minutes 26 seconds of 1920 × 1080. The interview is “Interview on extreme weather with physical geographer Hannah Cloke” by the Royal Society, released under CC BY 3.0, which lets you cut and repost it with credit to the Royal Society, a link to the license, and a note that it was changed.

Each recipe stands alone, so you can jump to the one you need. They all ran with ffmpeg 9.0.2 from Homebrew on a Mac, and the times are from that Mac.

Every command, output and image below comes from that run. Claude Code added -hide_banner -loglevel error -y to the ffmpeg commands, which only quiet the log and overwrite old files; they're left out here so the commands are easier to read.

What you need

A Mac with Homebrew, Claude Code signed in with your own account, and a folder with your videos in it. Homebrew installs ffmpeg, with ffprobe alongside it:

brew install ffmpeg

Open Claude Code in the folder and ask for each recipe in plain words, as in the prompts below. Asking it to check the result as well, the way each recipe does with ffprobe, is what catches a file that looks done but isn't.

1. Trim a clip

There are two ways to cut 10 seconds out of a video, and they give different files.

Claude Code

Cut heat.mp4 from 5 seconds to 15 seconds. Then check the result's length and frames.

The fast way copies the encoded video as it is. -ss 5 before -i jumps to 5 seconds in the input, -t 10 keeps 10 seconds, and -c copy copies both video and audio without encoding. It took 0.04 seconds:

ffmpeg -ss 5 -i heat.mp4 -t 10 -c copy trim-copy.mp4
ffprobe -v error -select_streams v -show_entries stream=duration,nb_frames -of compact=p=0 trim-copy.mp4ffprobe -v error -select_streams v -count_frames -show_entries stream=nb_read_frames -of compact=p=0 trim-copy.mp4
duration=10.200000|nb_frames=376
nb_read_frames=252

The stream says 10.2 seconds and 376 frames, but only 252 are shown when it plays. Copied video can only start on a keyframe, a frame that doesn't depend on the ones before it, and heat.mp4's keyframes are at 0.04, 10.04, 19.76 and 29.76 seconds. So the file holds everything from 0.04, and a note in it, an edit list, tells players to start at 5. Most players follow it. Apps that don't, which ffmpeg imitates with -ignore_editlist 1, show 15.12 seconds that start 5 seconds early.

The exact way encodes the video again. -c:v libx264 -crf 18 makes new H.264 video at a quality close to the original, and -c:a aac -b:a 192k new audio. It took 2.17 seconds:

ffmpeg -ss 5 -i heat.mp4 -t 10 -c:v libx264 -crf 18 -c:a aac -b:a 192k trim-exact.mp4
ffprobe -v error -select_streams v -show_entries stream=duration,nb_frames -of compact=p=0 trim-exact.mp4
duration=10.000000|nb_frames=250

Exactly 10 seconds and 250 frames, 25 a second. Use -c copy when the cut can be rough or falls on a keyframe, and encode when it has to land on a given frame, or when the file goes into an app you haven't checked.

2. Join clips

Clips made the same way, with the same size, frame rate and codecs, can be joined without encoding:

Claude Code

Join heat.mp4, likely.mp4 and music-box.mp4 into one video, in that order, without re-encoding.
printf "file '%s'\n" heat.mp4 likely.mp4 music-box.mp4 > list.txtffmpeg -f concat -i list.txt -c copy joined.mp4ffprobe -v error -show_entries format=duration -of compact=p=0 joined.mp4
duration=120.941328

printf writes list.txt with one file line for each clip. -f concat reads that list as one input that plays the files back to back, and -c copy writes them out as they are. It took 0.10 seconds. The three are 36.4, 44.8 and 39.72 seconds, 120.92 in all, and the joined file is 120.94.

If the clips differ, say one is 1080 × 1920 and another 720 × 1280, -c copy can make a file that plays wrong after the first clip. Ask Claude Code to bring them to the same size and frame rate first, or to join them with the concat filter, which encodes.

3. Speed up

Video and audio have separate filters for speed, and both have to change by the same amount:

Claude Code

Make heat.mp4 1.25 times faster, sound included, without changing the pitch of the voice.
ffmpeg -i heat.mp4 -vf setpts=PTS/1.25 -af atempo=1.25 -c:v libx264 -crf 18 -c:a aac -b:a 192k fast.mp4ffprobe -v error -show_entries stream=codec_type,duration,nb_frames -of compact=p=0 fast.mp4
codec_type=video|duration=29.120000|nb_frames=728
codec_type=audio|duration=29.099083|nb_frames=1366

setpts=PTS/1.25 divides each frame's timestamp by 1.25, so the frames come sooner. atempo=1.25 speeds up the audio without raising the pitch. 36.4 seconds became 29.12, in 5.08 seconds. The video kept 25 frames a second, so ffmpeg dropped about one frame in five: 909 frames became 728. atempo takes 0.5 to 100; for a speed outside that, ask Claude Code to chain two.

4. Fade in and out

A half-second fade from black at the start and to black at the end, with the sound fading too:

Claude Code

Add a 0.5-second fade in and fade out to heat.mp4, picture and sound.
ffmpeg -i heat.mp4 \  -vf "fade=t=in:d=0.5,fade=t=out:st=35.9:d=0.5" \  -af "afade=t=in:d=0.5,afade=t=out:st=35.9:d=0.5" \  -c:v libx264 -crf 18 -c:a aac -b:a 192k faded.mp4

fade=t=in:d=0.5 fades in over 0.5 seconds from the start. fade=t=out:st=35.9:d=0.5 starts fading out at 35.9 seconds, half a second before the end at 36.4, so the fade needs the clip's length. afade does the same for the audio. Fades change every frame they touch, so this one has to encode: 6.19 seconds.

Average brightness, on a scale where 16 is black and 235 white, shows the fade: 23.7 on the first frame, 54.4 at 0.2 seconds, 84.9 at 0.36, and 111 from 0.52 on, where the picture is back to normal.

Four frames of a close-up of Hannah Cloke side by side, going from almost black on the left to full brightness on the right.
Frames 0, 4, 8 and 12 of faded.mp4, at 0.04, 0.20, 0.36 and 0.52 seconds.

5. Even out loudness

Loudness is measured in LUFS, which follows how loud people hear something rather than how high the waveform goes. YouTube turns loud videos down when they play, and doesn't publish the level it aims for. Making Shorts about -14 LUFS, with peaks below -1 dB, is a common choice so they sound alike and don't get turned down much; it's a convention, not a YouTube rule.

Claude Code

Measure the loudness of heat.mp4, then bring it to -14 LUFS with true peaks at most -1.5 dB, in two passes.

The ebur128 filter measures it. It reads the whole file, so -f null - throws the output away, and grep keeps the summary:

ffmpeg -nostats -i heat.mp4 -af ebur128=peak=true -f null - 2>&1 | grep -A 11 'Integrated loudness:'
  Integrated loudness:
    I:         -15.4 LUFS
    Threshold: -25.6 LUFS

  Loudness range:
    LRA:         3.1 LU
    Threshold: -35.6 LUFS
    LRA low:   -17.1 LUFS
    LRA high:  -14.0 LUFS

  True peak:
    Peak:       -1.1 dBFS

heat.mp4 is at -15.4 LUFS, a little quieter than -14. The other two Shorts measured -15.3 and -14.5, and the interview -14.8, so this source was already close; with a quiet phone recording the change would be much bigger.

loudnorm changes the level. Run once, it guesses as it goes and can drift, so it runs twice. The first pass only measures, with I=-14 as the target loudness, TP=-1.5 as the highest peak, and LRA=11 as how much the loudness may vary. It took 0.93 seconds:

ffmpeg -nostats -i heat.mp4 -af loudnorm=I=-14:TP=-1.5:LRA=11:print_format=json -vn -f null - 2>&1 | sed -n '/^{/,/^}/p'
{
	"input_i" : "-15.53",
	"input_tp" : "-1.14",
	"input_lra" : "2.90",
	"input_thresh" : "-25.70",
	"output_i" : "-14.23",
	"output_tp" : "-1.50",
	"output_lra" : "2.60",
	"output_thresh" : "-24.42",
	"normalization_type" : "dynamic",
	"target_offset" : "0.23"
}

The second pass gets those numbers back as measured_I, measured_TP, measured_LRA, measured_thresh and offset, and writes the file. -c:v copy leaves the video as it is, and -ar 48000 keeps the audio at 48 kHz, since loudnorm works at a higher rate inside. It took 1.24 seconds:

ffmpeg -i heat.mp4 \  -af loudnorm=I=-14:TP=-1.5:LRA=11:measured_I=-15.53:measured_TP=-1.14:measured_LRA=2.90:measured_thresh=-25.70:offset=0.23:linear=true:print_format=summary \  -ar 48000 -c:v copy -c:a aac -b:a 192k loud.mp4 2>&1 | grep -A 6 'Output Integrated'
Output Integrated:   -14.0 LUFS
Output True Peak:     -1.5 dBTP
Output LRA:            2.6 LU
Output Threshold:    -24.2 LUFS

Normalization Type:   Dynamic
Target Offset:        +0.0 LU

-14.0 LUFS, with peaks at -1.5. linear=true asks loudnorm to turn the whole file up by one amount, but the type came out Dynamic: raising it 1.5 dB would have pushed its loudest peak, at -1.14, past -1.5, so loudnorm turned the loud moments down a little more than the rest. For most Shorts that's fine. If it isn't, ask for a lower target or a higher peak limit.

6. Make the file smaller

When a file is too big to send or upload, encode it again at a lower quality, or at a smaller size:

Claude Code

Make heat.mp4 smaller three ways: CRF 23, CRF 28, and 720 × 1280 at CRF 23. Measure how much each loses with VMAF against the original.
ffmpeg -i heat.mp4 -c:v libx264 -crf 23 -preset medium -c:a copy -movflags +faststart crf23.mp4ffmpeg -i heat.mp4 -c:v libx264 -crf 28 -preset medium -c:a copy -movflags +faststart crf28.mp4ffmpeg -i heat.mp4 -vf scale=720:1280 -c:v libx264 -crf 23 -preset medium -c:a copy -movflags +faststart small.mp4ls -l heat.mp4 crf23.mp4 crf28.mp4 small.mp4 | awk '{print $5, $9}'
10760652 crf23.mp4
6254371 crf28.mp4
15316518 heat.mp4
5720856 small.mp4

-crf sets the quality for libx264: lower is better and bigger, and each 6 steps roughly halves or doubles the size. -preset medium is how hard it works to make the file small. -c:a copy keeps the audio as it is, and -vf scale=720:1280 shrinks the picture. They took 4.77, 4.27 and 2.69 seconds, and came out at 70%, 41% and 37% of the 15.3 MB original.

VMAF is a score from Netflix, 0 to 100, for how close a video looks to a reference. The small one is scaled back up to 1080 × 1920 first, as a phone would show it. All three took 14.6 seconds:

for f in crf23 crf28 small; do  ffmpeg -nostats -i $f.mp4 -i heat.mp4 \    -lavfi "[0:v]scale=1080:1920:flags=bicubic[d];[d][1:v]libvmaf=n_threads=8" \    -f null - 2>&1 | grep 'VMAF score'done
[Parsed_libvmaf_1 @ 0x7a5f28cc00] VMAF score: 96.287623
[Parsed_libvmaf_1 @ 0x7a68c7c6c0] VMAF score: 91.867681
[Parsed_libvmaf_1 @ 0x7cfe4046c0] VMAF score: 92.003606

CRF 23 scores 96.3, CRF 28 91.9 and the 720 × 1280 one 92.0. heat.mp4 is itself already compressed, so these measure only what the new encode loses on top. 720 × 1280 at CRF 23 is the smallest of the three and scores about the same as CRF 28.

Four close crops of the same frame of Hannah Cloke's eyes and nose side by side. They look almost the same; the third and fourth are slightly softer around the eyes.
The same 272 × 272 part of the frame at 18.92 seconds, at full size: heat.mp4, crf23.mp4, crf28.mp4 and small.mp4 scaled back up.

-movflags +faststart moves the moov atom, the index of where everything is in the file, to the front, so a browser can start playing before the whole file has loaded. ffmpeg puts it at the end otherwise. ffprobe's trace log shows the order, here for the exact trim from recipe 1, made without it, and for crf23.mp4:

for f in trim-exact.mp4 crf23.mp4; do  echo $f; ffprobe -v trace $f 2>&1 | grep -o "type:'\(moov\|mdat\)'"done
trim-exact.mp4
type:'mdat'
type:'moov'
crf23.mp4
type:'moov'
type:'mdat'

7. Pull out the audio

Three kinds of audio file from the same Short, for three uses:

Claude Code

Take the audio out of heat.mp4 three ways: as it is, as an MP3, and as 16 kHz mono WAV for transcription.
ffmpeg -i heat.mp4 -vn -c:a copy heat.m4affmpeg -i heat.mp4 -vn -c:a libmp3lame -q:a 2 heat.mp3ffmpeg -i heat.mp4 -vn -ar 16000 -ac 1 heat.wavfor f in heat.m4a heat.mp3 heat.wav; do  ffprobe -v error -show_entries stream=codec_name,sample_rate,channels:format=duration -of compact=p=0 $fdone
codec_name=aac|sample_rate=48000|channels=2
duration=36.360000
codec_name=mp3|sample_rate=48000|channels=2
duration=36.360000
codec_name=pcm_s16le|sample_rate=16000|channels=1
duration=36.360000

-vn drops the video. -c:a copy keeps the AAC audio as it is, 734 KB in 0.04 seconds. libmp3lame -q:a 2 makes an MP3 at a variable bitrate, about 127 kbps here, 577 KB in 0.23 seconds, for apps that want MP3. -ar 16000 -ac 1 makes 16 kHz mono, which speech-to-text tools such as Whisper work at, and the .wav name makes it uncompressed WAV: 1.16 MB in 0.06 seconds.

8. Convert WebM to MP4

YouTube takes WebM uploads, so there's no need to convert for YouTube itself. Some editors and phone apps don't open it, though, and then MP4 with H.264 and AAC is the safe choice:

Claude Code

Convert interview.webm to an MP4 that opens anywhere.
ffmpeg -i interview.webm -c:v libx264 -crf 18 -pix_fmt yuv420p -c:a aac -b:a 192k -movflags +faststart interview.mp4ffprobe -v error -show_entries stream=codec_name,profile,width,height,pix_fmt -of compact=p=0 interview.mp4
codec_name=h264|profile=High|width=1920|height=1080|pix_fmt=yuv420p
codec_name=aac|profile=LC

WebM's VP9 video and Opus audio can't be copied into an MP4 that every app opens, so both are encoded again: libx264 at -crf 18, AAC at 192 kbps. -pix_fmt yuv420p keeps the color format that every player decodes, and +faststart puts the index first. The 10-minute interview took 85.66 seconds and grew from 85.5 MB to 236.4 MB, 3.02 Mbps against the WebM's 1.09: CRF 18 is set to keep the picture close to the source, and H.264 needs more data than VP9 for that. For a smaller file, raise the CRF as in recipe 6.

YouTube's page of recommended upload settings asks for more: a keyframe every half second, two B-frames, and a closed GOP. With those added, the same interview came out at 418 MB, 77% bigger, and YouTube encodes every upload again anyway. Those settings matter little for a Short; the plain command above is enough.

Where it gets hard

Each command ran in seconds. The work is in what they leave to you: where a cut should land, which clips to join, how fast is too fast, and which of a few versions looks right. With more Shorts, choosing those and saying what to change on each is most of the work.

Cutfac is a Mac app we make for that part. It runs Claude Code or Codex for each video, lets you select a range or draw a box on the frame and say what to change, and keeps versions side by side to compare and pick from. You can do everything in this guide without it.

Sources

Questions