Clean cuts for talking-head video
You cannot hear the video. You only see a transcript, and a transcript is wrong in two ways:
- It hides words. Speech models tidy up speech. A line said twice may be written once, and an "umm" or a false start may be missing. You cannot remove what you cannot see.
- Its timestamps are off. A word's start and end time can miss the real sound by tens or hundreds of milliseconds. A cut placed on the timestamp lands inside a word.
So follow this rule for every cut: choose WHAT to keep from the transcript, but place WHERE to cut on the audio. The scripts in scripts/ do the audio part. Never write your own ffmpeg cut from transcript times.
Before you start
- Tools:
ffmpeg,ffprobe, Python 3.9+ withnumpy. GEMINI_API_KEYfor the last check in Step 6.ELEVENLABS_API_KEYmust be set in the environment. If it is missing, stop and ask the user for it. Do not switch to Whisper silently: it drops repeats and false starts, which are the exact words you need to see.- Work on the raw clips (voice only). Do not transcribe a version that already has music.
Step 1. Transcribe every clip
python3 scripts/transcribe.py take1.mov --lang hi # leave out --lang to auto-detect
This writes take1.mov.words.json and take1.mov.words.txt next to the clip. The clip is split at silences into chunks of 12 seconds or less before it is sent, because a long clip sent whole can hide quick restarts.
Read the .words.txt file. Every word has an index. A blank line marks a pause. LONG marks a word that lasts more than 0.9 seconds: it may hide a restart, so do not start or end a segment next to it without checking.
Transcribe each clip once. Word indexes change a little between two runs. If you transcribe again, write the cut list again.
Step 2. Choose what to keep
Write a cut list, in playing order. Each segment is a run of words, named by index:
[
{"clip": "take1.mov", "first": 25, "last": 49, "why": "opening line, second take, complete"},
{"clip": "take1.mov", "first": 50, "last": 73, "why": "states the problem"}
]
Rules for choosing:
- Whole sentences only. A segment starts on the first word of a sentence and ends on the last word of a sentence. Never start or end inside one.
- End where the speaker pauses. Prefer a last word that is followed by a blank line (a pause) in
.words.txt. If the speaker runs two sentences together with no pause, keep both or drop both. - Retakes: keep the last good take. When a line is said more than once, keep the latest take that is complete, fluent and correct. If the last attempt is weaker, keep the earlier good one. Cut the others completely.
- A half-finished phrase followed by a restart is a retake. Cut the half-finished part.
- Write the reason for every segment in
why. The user must be able to audit each cut.
Step 3. Dry run, and fix every flagged cut
python3 scripts/cut.py cutlist.json -o out.mp4 --dry
For each segment the script:
- Start: looks at the 220 ms before the first word and cuts in the quietest 20 ms.
- End: ignores the last word's end time. It scans forward from inside the last word until the audio stays below -42 dB for 180 ms, then cuts 80 ms into that silence.
- Measures the level at every cut and prints it.
A line marked CHECK means a cut is louder than -40 dB, so it sits in sound. Fix it by moving that segment's first or last word to a real pause (extend the segment to the next pause, or end it at the previous one). Run the dry run again. Repeat until no cut is flagged.
If a cut cannot be moved because the speaker never pauses there, tell the user which cut it is and let them decide. Only then use --allow-loud.
Step 4. Render
python3 scripts/cut.py cutlist.json -o out.mp4
python3 scripts/cut.py cutlist.json -o out.mp4 --scale 1080:1920 # optional resize
Every segment gets a 15 ms audio fade in and a 20 ms fade out, is re-encoded, and is cut on a whole frame. The script also writes out.mp4.cuts.json, which records where each cut landed.
Step 5. Check the result
python3 scripts/check.py out.mp4 --lang hi
This transcribes the finished video again and compares it with the words you planned. It fails if a 3-word phrase is heard more often than planned (a retake got through) or if more than 5% of the planned words are missing or different (a word got clipped). If it fails, fix the cut list and render again. Do not hand over a video that failed.
Step 6. Last check: let Gemini watch and listen
python3 scripts/review.py out.mp4
Always run this on the final video before you hand it over. You cannot hear, and the transcript check cannot find a pop at a join, a jump in loudness, or a cut that looks wrong on screen. Gemini takes the picture and the sound together and lists problems with timestamps.
It needs GEMINI_API_KEY. If the key is missing, ask the user for it. If they do not want to use Gemini, tell them plainly that this check was skipped and nobody has listened to the result.
Gemini is a second opinion. It does not decide. It can mishear words and report problems that are not there. Treat each item as a ticket and verify it:
- It reports a cut at a time: look in
out.mp4.cuts.json. If no segment starts or ends there, there is no cut, and the speaker simply said it that way. - It reports a missing or clipped word: look for that word in the transcript of the final video from Step 5.
- It reports a pop or a loud join: check the cut level of that segment in the dry-run report.
Fix the real ones, render again, and run Steps 5 and 6 again. Tell the user which reported items you checked and found to be false.
Only send the finished video to Gemini, never the raw clips, unless the user says raw footage may be uploaded.
What to tell the user
- How many cuts landed in silence (for example "23 of 23").
- The result of the transcript check.
- What Gemini reported, and what you found when you verified each item.
- Any cut you could not place in silence, with its time, so they can listen to it.
- That you could not listen to the audio yourself. Your checks are measurements, and Gemini's review is a second opinion.
Limits
- Made for one person speaking to camera. Not tested on interviews, crosstalk or speech over music.
- It makes cuts clean. It does not decide whether the edit is interesting.
- A very fast speaker who never pauses gives you few clean places to cut. Say so rather than forcing a cut.