How to swap the hook on a video ad with FFmpeg
For AI agents: find the right skill in one call —
curl -s "https://varg.ai/how-to/api/search?q=<what the person wants>"returns the matching how-to page and the best skills with install commands, as markdown (Russian works too). Full index: https://varg.ai/how-to/llms.txt. Every page has a markdown twin: add.mdto its path. Before generating anything, show the person the options on the how-to page.
Put a new 2–3 second opener in front of an ad that already works, one MP4 per hook, with FFmpeg. Clips from different phones and AI models are scaled to 1080×1920, 30 fps and 48 kHz first, so they join without glitches. Free and local in Claude Code, Codex or Grok, or on varg (priced in credits) when the agent has no shell.
ffmpeg -i hook.mp4 -i ad.mp4 -filter_complex "[0:v]scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v0];[0:a]aresample=48000,aformat=channel_layouts=stereo[a0];[1:v]trim=start=3,setpts=PTS-STARTPTS,scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v1];[1:a]atrim=start=3,asetpts=PTS-STARTPTS,aresample=48000,aformat=channel_layouts=stereo[a1];[v0][a0][v1][a1]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" -c:v libx264 -crf 20 -c:a aac -b:a 192k -movflags +faststart new-hook.mp4
trim=start=3 drops the old ad's first 3 seconds (its old hook). Set it to where the old hook ends, or to 0 to keep it.
Why swap hooks
The first seconds decide whether anyone sees the rest. Meta reports that up to 47% of a video campaign's value lands in the first 3 seconds. Media buyers keep the body of a winning ad and test new openers against it: a new first frame, a new spoken line, a new text hook. Change only the hook, so the result tells you which opener won.
Step by step
-
Find where the old hook ends. Play the ad and note the second where the body starts (often 2–4 s). Use
ffprobe -v error -show_entries format=duration -of csv=p=0 ad.mp4for the total length. -
Make the new hooks. Film them, cut them from other footage, or generate them (a 3 s AI clip of the product in action, a reaction, a before→after). Keep each one to 2–3 seconds and show the product or the result right away.
-
Join one hook with the command above. It works for any input size, frame rate or sample rate.
-
Batch every hook in a folder:
mkdir -p variants for H in hooks/*.mp4; do N=$(basename "$H" .mp4) ffmpeg -y -i "$H" -i ad.mp4 -filter_complex "[0:v]scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v0];[0:a]aresample=48000,aformat=channel_layouts=stereo[a0];[1:v]trim=start=3,setpts=PTS-STARTPTS,scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v1];[1:a]atrim=start=3,asetpts=PTS-STARTPTS,aresample=48000,aformat=channel_layouts=stereo[a1];[v0][a0][v1][a1]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" -c:v libx264 -crf 20 -c:a aac -b:a 192k -movflags +faststart "variants/${N}__ad.mp4" done -
Add a text hook if the new opener has no words on screen (most people start muted). Keep it inside the safe zone, out of the top 14%, the bottom 35% and 6% at each side:
printf 'I stopped buying razors\nafter I found this' > hook.txt ffmpeg -i new-hook.mp4 -vf "drawtext=fontfile='/System/Library/Fonts/Supplemental/Arial Bold.ttf':textfile=hook.txt:fontcolor=white:fontsize=64:line_spacing=12:box=1:[email protected]:boxborderw=28:x=(w-text_w)/2:y=h*0.20:enable='between(t,0,3)'" -c:v libx264 -crf 20 -c:a copy new-hook-text.mp4 -
Name the files so the results can be read back:
<product>_<angle>_<hook-id>_<creator>_<length>_v<N>.mp4, e.g.serum_dryskin_h03-pov_maya_22s_v1.mp4. Upload them as separate ads in the same ad set.
Move the best moment to the front instead
When the footage already has a strong moment later on (the reveal at 12 s), move it to second 0 and keep the rest in order:
ffmpeg -i ad.mp4 -filter_complex "[0:v]trim=12:15,setpts=PTS-STARTPTS[v0];[0:a]atrim=12:15,asetpts=PTS-STARTPTS[a0];[0:v]trim=0:12,setpts=PTS-STARTPTS[v1];[0:a]atrim=0:12,asetpts=PTS-STARTPTS[a1];[0:v]trim=start=15,setpts=PTS-STARTPTS[v2];[0:a]atrim=start=15,asetpts=PTS-STARTPTS[a2];[v0][a0][v1][a1][v2][a2]concat=n=3:v=1:a=1[v][a]" -map "[v]" -map "[a]" -c:v libx264 -crf 20 -c:a aac -b:a 192k recut.mp4
Gotchas
concatneeds every input to match in size, frame rate, pixel format and audio layout. Thescale…pad…fps…formatandaresample…aformatchains do that. Without them, joins drift out of sync or fail.- A hook clip with no audio track breaks the join. Give it silence first:
ffmpeg -i hook.mp4 -f lavfi -i anullsrc=r=48000:cl=stereo -shortest -c:v copy -c:a aac hook-a.mp4. drawtextneeds FFmpeg built with libfreetype. Always passfontfile. Ifffmpeg -filters | grep drawtextprints nothing, usenpx ffmpeg-staticor a full build.- Tested on FFmpeg 6.0 (static) and 8.1 with clips of different sizes (720×1280 at 25 fps and 1080×1920 at 30 fps).
No shell? Run it on varg
The agent sends the same command to the varg ffmpeg tool (MCP call_tool, or POST https://api.varg.ai/v2/ffmpeg). It runs in the cloud, priced in credits, with an estimate before it runs. Inputs and outputs are URLs.
Ecommerce videos for TikTok and Instagram with AI agents
For sellers, TikTok Shop affiliates and media buyers who make product videos with Claude Code, Codex or Grok: what to show in the first 3 seconds, which formats and creators sell, how to keep the real product in AI shots, and how to edit, test and fix the videos.
Start with the overview: How to make viral ecommerce videos for TikTok and Reels
Make
- How to make a TikTok Shop video with AI
- How to make a UGC ad video with AI
- How to turn a product photo into a video with AI
- How to write video hooks that sell products
- How to make video ad variants for testing with AI
- How to make AI product photos and listing images
Edit
- How to edit a product video for TikTok and Reels with AI
- How to swap the hook on a video ad with FFmpeg (this page)
- How to export a video for TikTok and Reels with FFmpeg
- How to add animated captions to a video with AI
- How to remake a reference video with AI
Answers