Skip to content

Instantly share code, notes, and snippets.

@MekDrop
Last active November 13, 2017 16:02
Show Gist options
  • Save MekDrop/1e58cbe5dda725963eb404fcaba8b1b2 to your computer and use it in GitHub Desktop.
Save MekDrop/1e58cbe5dda725963eb404fcaba8b1b2 to your computer and use it in GitHub Desktop.
Make from one video multiple sources HTML tag
@echo off
########################################################################################
# This script will create multiple versions files from video for your video tag
# and also generates this tag.
#
# FFMPEG is needed. Most simple way to install it: choco install ffmpeg && refreshenv
#
# This small script uses public domain license so you can do whatever you want.
########################################################################################
setlocal enabledelayedexpansion
if %1. == . (
echo Syntax: %0 source_file.mov
goto :eof
)
set source_prefix=%~dpn1
set source_file=%1
set html_tag=
call :vp9
call :vp8
call :mp4
call :ogv
set "html_tag=<video controls>%html_tag%</video>"
echo !html_tag! > result.html
echo "Result.html created."
goto :eof
:vp9
set result_file="%source_prefix%.vp9.webm"
rm -rf null
ffmpeg -i !source_file! -c:v libvpx-vp9 -pass 1 -b:v 1000K -threads 1 -speed 4 -tile-columns 0 -frame-parallel 0 -auto-alt-ref 1 -lag-in-frames 25 -g 9999 -aq-mode 0 -an -f webm null
ffmpeg -i !source_file! -c:v libvpx-vp9 -pass 2 -b:v 1000K -threads 1 -speed 0 -tile-columns 0 -frame-parallel 0 -auto-alt-ref 1 -lag-in-frames 25 -g 9999 -aq-mode 0 -c:a libopus -b:a 64k -f webm %result_file%
set type=video/webm; codecs=vp9,vorbis
set ext=vp9.webm
call :create_sizes
goto :eof
:vp8
set result_file="%source_prefix%.vp8.webm"
ffmpeg -i !source_file! -vcodec libvpx -qmin 0 -qmax 50 -crf 10 -b:v 1M -acodec libvorbis %result_file%
set type=video/webm; codecs=vp8,vorbis
set ext=vp8.webm
call :create_sizes
goto :eof
:ogv
set result_file="%source_prefix%.ogv"
ffmpeg -i !source_file! -vcodec libtheora -acodec libvorbis %result_file%
set type=video/ogg
set ext=ogv
call :create_sizes
goto :eof
:mp4
set result_file="%source_prefix%.mp4"
set ext=mp4
ffmpeg -i !source_file! -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level 3 -crf 30 %result_file%
set type=video/mp4
call :create_sizes
goto :eof
:create_sizes
for %%r in (1920 1366 1280 1024) do (
set result_file2="%source_prefix%-%%r.%ext%"
ffmpeg -i !source_file! -vf scale=%%r:-1 %result_file2%
set html_tag=!html_tag!^<source src="%result_file2%" type="%type%" media="all and (max-width:%%rpx)"^>
)
goto :eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment