Imgkit - Python 2 and 3 wrapper for wkhtmltoimage utility to convert HTML to IMG using Webkit.
This Python tool is doing the most important part.
It's in the core of the process. It converts an intermediate HTML to a PNG image.
It's stored in a separate file aaa.py . Its called from a shell.
eval 'python3 ./aaa.py $j.html _$j.png'
The Imgkit is used instead of the outdated Webkit2png. The Webkit2png doesn't work with new QT.
File aaa.py:
import imgkit import sys options = { 'quiet': '', 'quality': '100' } imgkit.from_url(sys.argv[1], sys.argv[2], options=options)
It's slow!
Parameters are for a 4K output .mp4 PAL video.
#!/bin/bash f=$( ls *.mp4 ) ffmpeg -i $f -r 25 -f image2 %7d.jpg for i in $(ls | grep jpg | sort) ; do echo $i j=$( echo $i | sed '1,$ s/\(.*\)\.jpg/\1/') img2txt -W 734 -H 190 -x 3 -y 5 $i -f html3 > $j.html eval 'python3 ./aaa.py $j.html _$j.png' #convert _$j.png -trim +repage -resize '3840x' -sharpen 0x1.0 $j.png convert _$j.png -trim +repage -adaptive-resize '3840x' -adaptive-sharpen 1.0 $j.png rm $j.html _$j.png done ffmpeg -r 25 -f image2 -i %7d.png -vcodec libx264 -crf 17 -pix_fmt yuv420p $f.mkv
Parallel processing, one image per CPU core.
Parameters are for a 4K input .mp4 PAL video.
#!/bin/bash c=16 # CPU cores echo echo "############################## 1 ################################" echo f=$( ls *.mp4 ) # .mp4 input ffmpeg -i $f -r 25 -f image2 %7d.jpg # PAL 25 fps echo echo "############################## 2 ################################" echo for i in $(ls | grep jpg | sort) ; do j=$( echo $i | sed '1,$ s/\(.*\)\.jpg/\1/') ( img2txt -W 430 -H 110 $i -f html3 > $j.html ; rm $i ) & s=$( ps -ef | grep img2txt | grep -v grep | wc -l ) echo $j.html" "$s while [[ $s -ge $c ]] ; do echo -n "." sleep 1 s=$( ps -ef | grep img2txt | grep -v grep | wc -l ) if [[ $s -lt $c ]] then echo "." fi done done echo echo "############################## 3 ################################" echo for i in $(ls | grep html | sort) ; do j=$( echo $i | sed '1,$ s/\(.*\)\.html/\1/') ( eval 'python3 ./aaa.py $i _$j.png' ; rm $i ) & # the Python part echo -n _$j.png " " s=$( ps -ef | grep "aaa.py" | grep -v grep | wc -l ) echo $s while [[ $s -ge $c ]] ; do echo -n "." sleep 1 s=$( ps -ef | grep "aaa.py" | grep -v grep | wc -l ) if [[ $s -lt $c ]] then echo "." fi done done echo echo "############################## 4 ################################" echo for i in $(ls | grep _ | grep png | sort) ; do j=$( echo $i | sed '1,$ s/_\(.*\)\.png/\1/') ( convert $i -trim +repage -adaptive-resize 3840x2160\! -adaptive-sharpen 2.0 $j.png ; rm $i ) & echo -n $j.png" " s=$( ps -ef | grep convert | grep -v grep | wc -l ) echo $s while [[ $s -ge $c ]] ; do echo -n "." sleep 1 s=$( ps -ef | grep convert | grep -v grep | wc -l ) if [[ $s -lt $c ]] then echo "." fi done done echo echo "############################## 5 ################################" echo f=$( cat $f | sed '1,$ s/\(.*\)\.mp4/\1/' ) ffmpeg -r 25 -f image2 -i %7d.png -vcodec libx264 -crf 0 -pix_fmt yuv420p $f.mkv # .mkv output, crf = 0 for best quality exit 0