Using FFmpeg on Windows

Pre

Got some videos to process with, task was simple, so don’t wanna use a gui app like davinci pr or whatever.
And cli based ffmpeg is an option.

Issue

Platform

Most tutorial or usage cases are based on linux, after all FFmpeg is widely used by programers which more likely using a linux.
However there is a high chance that your best performance computer is with an Windows OS. If you don’t wanna install a wsl, you could still use a msys2 porject compiled version.
Besides it got some glitches on file system communication between wsl and Windows, and may cause system laggy occasionally, so I think it may better to execute task in Windows directly.

Tweaks on Windows

  • You may wanna try these commands in powershell, cmd is little limited on interaction for these command.
  • And you have to deal with escape character in powershell, which is different from in linux.
  • Windows has its own date function, which is conflicted with the one in the usage cases from most tutorial.
    based on the above, you have to made some tweaks.

installation

comparing with download binary file manually, it’s simple to install it with winget.

1
winget install ffmpeg

Typical error

a parse error, something like below, usually caused by wrong escape character, misplaced punctuation.

1
Unable to parse option value ""

a syntax error, something like below, usually it

1
Either text, a valid file, a timecode or text source must be provided

usage case

some cases involved with date function

escape char

the colon must be escaped with escape char

elapsed time watermark

1
ffmpeg -i output_final.mp4 -vf "drawtext=text='\%\{pts\:hms\}':fontfile='C\:/Windows/Fonts/arial.ttf':fontcolor=white:fontsize=36:x=10:y=10" output_final_timed.mp4

date function

use a Windows date, this date is different from most tutorial you could find.
if you use the below one directly, it will fail, because you’re treating a Windows date function with a linux date syntax.

1
2
ffmpeg -i sample.mp4 -vf "drawtext=text=$(date +%s):fontfile='C\:/Windows/Fonts/arial.ttf':fontcolor=white:fontsize=36:x=90:y=10" output_formated.mp4
Get-Date : can't bind "Date"...

instead you should do this to use Windows date function syntax.

date and time watermark

1
2
$startTimeSeconds = [int64](Get-Date -Year 2024 -Month 10 -Day 13 -Hour 14 -Minute 10 -Second 50 -UFormat %s)
ffmpeg -i sample.mp4 -vf "drawtext=expansion=strftime:basetime=$($startTimeSeconds)000000:fontfile='C\:/Windows/Fonts/arial.ttf':fontcolor=white:fontsize=36:x=40:y=10:text='%Y-%m-%d %H\:%M\: %S'" output_formated.mp4

if you just wanna use a date from linux, you could use $(wsl date)

1
ffmpeg -i sample.mp4 -vf "drawtext=text=$(wsl date +%s -d '2018-10-13 14:10:50')000000:fontfile='C\:/Windows/Fonts/arial.ttf':fontcolor=white:fontsize=36:x=40:y=10:text='%Y-%m-%d %H\:%M\: %S'" output_formated.mp4

basetime: A confusing ffmpeg parameter
Be careful with those 000000 at the end of the basetime parameter, if it’s not there the start time will not be what we assigned.
The reason why this happen is because the basetime accept a designated length variable, the string converted from date is not comatible with it, but we could complete it with 000000.
ref: ffmpeg添加动态时间戳的问题

in wsl

Of course you could install wsl and install ffmpeg in it, and execute tasks from there. Then most cases from tutorial could be executed flawlessly without annoying tweaks.

1
2
sudo apt install ffmpeg
ffmpeg -i sample.mp4 -vf drawtext="expansion=strftime:basetime=$(date +%s -d '2024-10-13 14:10:50'):fontfile=arial.ttf:x=w-tw:fontcolor=red:fontsize=30:text='%Y-%m-%d %H\:%M\: %S'" output_formated.mp4

Appendix: Other usage cases

corp

1
ffmpeg -i sample.mp4 -filter:v "crop=1724:970:98:110,scale=1920:1080" output_final.mp4

delogo

1
ffmpeg -i sample.mp4 -b:v 548k -vf delogo=x=1:y=55:w=720:h=55:show=1 delogo_1_55_720_55.mp4

ref

ref: ffmpeg 踩坑实录 添加实时水印(二)
ref: ffmpeg Documentation