Using HTML5
With ffmpeg
rep=$(basename `pwd`) ; mkdir $rep ; mkdir $rep/pwg_representative ; for a ; do b=`echo "$a" | cut -d'.' -f1` ; ffmpeg -i $a -ar 44100 -b:v 1000k -movflags faststart $rep/$b.mp4 ; ffmpeg -i $a -r 1 -t 00:00:01 -ss 0:0:05 -s 640x480 -f image2 $b.jpg ; convert -resize 128x128 $b.jpg $rep/pwg_representative/$b.jpg ; rm $b.jpg ; done exit
the magic part is -movflags faststart that installs the mp4 index at the start of the file, allowing streaming without loading all
Scripting HandBrake
I printed the cli help (HandBrakeCli -h > handbrake-help.txt) - it's sorted by tag. I also notice one can display each preset line (HandBrakeCLI -z).
I even find the setup for "web optimization" : -O, --optimize Optimize mp4 files for HTTP streaming ("fast start")
Script 16x9
This script manage to compile mp4 video that are said to play on any browser or mobile device html5 compatible (no more necessary to have duplicate ogv or webm files). If ever you have better solution or problem with the script, please feel free to write to me jdd (at) dodin.org.
Comments can be omitted, they are mostly inserted for documentation.
handbrake exists for almost any platform, the setup below gives very good quality video, at the expense of a slow compilation (hence the script), and large size.
#!/bin/bash # echo usage: movtomp4-html5.sh *.MOV # MOV can be any video file extension that can be read by handbrake and ffmpeg # that is at least all the video formats I know of :-) mkdir -p html5/pwg_representative # this is to generate thumbnails for piwigo. # Only the html5 folder is necessary if you don't need thumbnails for a ; do b=`echo "$a" | cut -d'.' -f1` ; # Find the file name HandBrakeCLI -i "$a" -t 1 --angle 1 -c 1 -o "html5/$b.mp4" -f mp4 -O -w 960 --crop 0:0:0:0 --loose-anamorphic --modulus 2 -e x264 -q 22 -r 30 --pfr -a 1 -E av_aac -6 dpl2 -R Auto -B 160 -D 0 --gain 0 --audio-fallback ac3 --encoder-level="3.1" --encoder-profile=high --verbose=1 # This have to be only one line in the script. It's the result of handbrake options for ipad, with the "web" option ticked (the web option writes the file index on the beginning of the file, necessary for streaming) ffmpeg -i $a -r 1 -ss 00:00:10 -t 00:0:01 -f image2 $b.jpg ; # extract an image, suppose the video is at least 10s long. 10s to avoid initial fade convert -resize 128x128 $b.jpg html5/pwg_representative/$b.jpg ; # thumbnail size for piwigo rm $b.jpg ; # remove temporary file done exit
Script 720x576:
#!/bin/bash # echo usage: movtomp4-html5.sh *.MOV #for 720x576 non anamorphic video mkdir -p html5/pwg_representative for a ; do b=`echo "$a" | cut -d'.' -f1` ; HandBrakeCLI -i "$a" -t 1 --angle 1 -c 1 -o "html5/$b.mp4" -f mp4 -O -w 720 -l 576 --crop 0:0:0:0 --custom-anamorphic --modulus 2 -e x264 -q 22 -r 30 --pfr -a 1 -E av_aac -6 dpl2 -R Auto -B 160 -D 0 --gain 0 --audio-fallback ac3 --encoder-level="3.1" --encoder-profile=high --verbose=1 --display-width 720 ffmpeg -i $a -r 1 -ss 00:00:10 -t 00:0:01 -f image2 $b.jpg ; convert -resize 128x128 $b.jpg html5/pwg_representative/$b.jpg ; rm $b.jpg ; done exit