How to export a video for TikTok and Reels 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.

Turn a finished edit into an MP4 that TikTok, Reels and Meta ads accept and play well: 1080×1920, H.264 High, 30 fps, AAC 48 kHz, loudness at -14 LUFS, faststart. Also a 4:5 feed cut, a cover frame and a safe-zone check. Free and local in Claude Code, Codex or Grok, or on varg (priced in credits) when the agent has no shell.

ffmpeg -i edit.mp4 -c:v libx264 -profile:v high -pix_fmt yuv420p -r 30 -b:v 8M -maxrate 10M -bufsize 16M -c:a aac -b:a 192k -ar 48000 -movflags +faststart final_9x16.mp4

Step by step

  1. Check what you have.

    ffprobe -v error -show_entries stream=codec_type,codec_name,width,height,r_frame_rate,pix_fmt -show_entries format=duration -of compact=p=0 edit.mp4
    

    Not 9:16? Fit it over a blurred copy so the whole product stays in the frame:

    ffmpeg -i edit.mp4 -filter_complex "[0:v]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,boxblur=20:2[bg];[0:v]scale=1080:-2[fg];[bg][fg]overlay=(W-w)/2:(H-h)/2,setsar=1" -c:v libx264 -crf 20 -c:a copy vertical.mp4
    
  2. Set the loudness to -14 LUFS integrated with peaks at -1 dBTP. That is the level phone apps play at, so the video is neither quieter than the next one nor clipped. Two passes: measure, then apply.

    J=$(ffmpeg -hide_banner -i edit.mp4 -af loudnorm=I=-14:TP=-1:LRA=11:print_format=json -f null - 2>&1 | sed -n '/^{/,/^}/p')
    v() { echo "$J" | grep "\"$1\"" | cut -d'"' -f4; }
    ffmpeg -i edit.mp4 -af "loudnorm=I=-14:TP=-1:LRA=11:measured_I=$(v input_i):measured_TP=$(v input_tp):measured_LRA=$(v input_lra):measured_thresh=$(v input_thresh):offset=$(v target_offset):linear=true,aresample=48000" -c:v copy -c:a aac -b:a 192k loud.mp4
    ffmpeg -hide_banner -i loud.mp4 -af ebur128 -f null - 2>&1 | grep -E "^\s+I:" | tail -1
    

    On test media this printed I: -14.0 LUFS and -13.9 LUFS.

  3. Export with the command at the top (run it on loud.mp4). -movflags +faststart puts the index at the front, so the video starts playing before it fully loads. yuv420p and the High profile play on every phone.

  4. Make a 4:5 cut for Instagram and Facebook feed placements. It keeps the frame slightly above centre, where faces and products usually sit:

    ffmpeg -i final_9x16.mp4 -vf "crop=iw:iw*5/4:0:(ih-iw*5/4)*0.4,scale=1080:1350,setsar=1" -c:v libx264 -crf 20 -c:a copy final_4x5.mp4
    
  5. Grab a cover frame with the product clearly visible:

    ffmpeg -ss 0.5 -i final_9x16.mp4 -frames:v 1 -q:v 2 cover.jpg
    
  6. Check the safe zone. The TikTok and Reels buttons, caption and username cover the top 14%, the bottom 35% and 6% at each side. Shade them and look: no text, product or face should sit in the red.

    ffmpeg -ss 1 -i final_9x16.mp4 -frames:v 1 -vf "drawbox=x=0:y=0:w=iw:h=ih*0.14:[email protected]:t=fill,drawbox=x=0:y=ih*0.65:w=iw:h=ih*0.35:[email protected]:t=fill,drawbox=x=0:y=0:w=iw*0.06:h=ih:[email protected]:t=fill,drawbox=x=iw*0.94:y=0:w=iw*0.06:h=ih:[email protected]:t=fill" safezone.png
    
  7. Confirm the result:

    ffprobe -v error -select_streams v:0 -show_entries stream=width,height,r_frame_rate,pix_fmt,profile -of compact=p=0 final_9x16.mp4
    # profile=High|width=1080|height=1920|pix_fmt=yuv420p|r_frame_rate=30/1
    

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