Skip to content
Kagami Hiiragi edited this page Jan 27, 2017 · 22 revisions

Print info on all key frames in the video

ffprobe -v quiet -show_frames -select_streams v -of compact file.webm |\
  grep key_frame=1

It may be useful if you encode a mostly static video (see note on GOP): it should be only one keyframe for the entire timeline. You may also tune some regexps above or apply wc -l at the end to see other video stats.

Alternatively, if you want only to count number of key frames:

ffprobe -v quiet -show_frames -select_streams v file.webm |\
  grep -c key_frame=1

TODO: ffprobe -show_packets and mkvinfo -v should be faster.

Or with webm_info tool (grab it here):

webm_info -i file.webm -all -noaudio | grep -c key:1

Compare two videos side by side

You can compare two videos of the same size while watching them with ffplay. Example command:

ffplay -f lavfi 'movie=their.webm,crop=w=iw/2:x=0[their];
                 movie=our.webm[our];[our][their]overlay'

Demo (our video at right, their at left):

This command can be easily tuned to compare videos with the different resolutions or to apply some other filters. You got the idea.

Print video stats

You can also draw some video stats at the screen:

t(){ echo "drawtext=x=$2:y=$3:fontsize=${4:-15}:fontcolor=${5:-white}:borderw=1:text='$1'"; }
ffplay -f lavfi "movie=our.webm,$(t OUR 5 5 20 red),
                 $(t 'Time\: %{pts\:hms}' 5 30),
                 $(t 'Frame number\: %{n}' 5 45),
                 $(t 'Frame type\: %{pict_type}' 5 60),
                 crop=w=iw/2:x=0[our];
                 movie=their.webm,$(t THEIR 450 5 20 blue),
                 $(t 'Time\: %{pts\:hms}' 450 30),
                 $(t 'Frame number\: %{n}' 450 45),
                 $(t 'Frame type\: %{pict_type}' 450 60)[their];
                 [their][our]overlay"

Demo (our video at left, their at right):

Tiled maps of videos

@echo off
@setlocal enableextensions enabledelayedexpansion
set ffmpeg=D:\Users\ANON\Downloads\ffmpeg-20150714-git-dfc5858-win64-static\bin\ffmpeg.exe
set /p "file=File: "
set "folder=%file%_ffmpeg_tmp_dir"
set /p duration="Duration: "
set /p x="Number of images in a row: "
set /p h="Height: "
set /a w=(h * 16)/9
set /a scale=%w% / %x%
set /a n=%x% * (%x%) - 1
set /a interval=%duration% / %n% + 1
set /a intervalP=%interval% + 1

set /a maxframes=%intervalP% * 25

REM If the encode fails, try lowering this number
set parallel=16

mkdir "%folder%"
%ffmpeg% -f lavfi -i color=black -vframes %maxframes% -s %w%x%h% -vf setsar=%w%/%h%,setdar=%w%/%h% %folder%/%%5d.png
for /l %%p in (0,%parallel%,%n%) do (
	mkdir "%folder%_"
	set filter="[0:v]copy[background];"
	set "input=-i !folder!\%%5d.png "
	for /l %%q in (1,1,%parallel%) do (
		set /a pass=%%p + %%q
		set /a start=!pass! * %interval% - %interval%
		set "input=!input! -ss !start! -i !file! "

		set "filter=!filter![%%q:v]scale=%scale%:-1,split=2[scaleda][scaledb];[background][scaleda]overlay=x=%scale%*((t/!interval!)-1+mod(!pass!\,%x%)):y=floor((!pass!)/(%x%))*%h%/%x%:format=rgb[background];[background][scaledb]overlay=x=%scale%*((t/!interval!)+%x%-1+mod(!pass!\,%x%)):y=(floor((!pass!)/(%x%))-1)*%h%/%x%:format=rgb[background];"


		echo [ !pass! / %n% ]
	)
	%ffmpeg% -y -thread_queue_size 256 !input! -pix_fmt rgba -r 25 -an -sn -filter_complex !filter![background]copy[out] -map [out] -t !intervalP! "%folder%_\%%5d.png"
	del /s /q /f "%folder%" >nul 2>&1
	rmdir "%folder%"
	for %%i in ("%folder%") do rename "%folder%_" "%%~nxi"
)

set /a bitrate=8*2000/%interval%
%ffmpeg% -y -i "%folder%\%%5d.png" -ss 0.04 -c:v libvpx-vp9 -b:v %bitrate%k -vf setsar=%w%/%h%,setdar=%w%/%h% -pix_fmt yuv420p -t !interval! -pass 1 %file%_huff_out.webm
%ffmpeg% -y -i "%folder%\%%5d.png" -ss 0.04 -c:v libvpx-vp9 -b:v %bitrate%k -vf setsar=%w%/%h%,setdar=%w%/%h% -pix_fmt yuv420p -t !interval! -pass 2 %file%_huff_out.webm

Other

  • FFmpeg filtering guide
  • Fancy filtering examples
  • Hardsub subtitles, hack to make it work with -ss (use -sn to remove the softsub track in order to play it in browsers: Firefox per May 2015 still can't play WebM video with included WebVTT stream fixed in 43+, but -sn still makes sense because browsers currently can't display embedded WebVTT)