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 .md to 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

  1. 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.mp4 for the total length.

  2. 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.

  3. Join one hook with the command above. It works for any input size, frame rate or sample rate.

  4. 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
    
  5. 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
    
  6. 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

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

Edit

Answers