-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf2textmovie.sh
executable file
·65 lines (59 loc) · 2.09 KB
/
pdf2textmovie.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Author: Shyamal Suhana Chandra
# Date: August 14, 2021 @11:02 PM
# Function: To convert PDFs into Text Movies (1st Draft)
#!/bin/bash
function convert_PDF_into_text_movie {
local counterlocal="$1"
local elementlocal="$2"
convert -size 1920x1080 -background white -fill black -gravity center caption:"$elementlocal" frame`echo $counterlocal`.png
say -v "Zoe (Premium)" -o frame$counterlocal.aiff "$elementlocal"
ffmpeg -loglevel quiet -y -threads 4 -i frame$counterlocal.aiff -c:a libopus -b:a 96K frame$counterlocal.opus
local seconds=0
local seconds=`ffprobe -i frame$counterlocal.opus -show_entries format=duration -v quiet -of csv="p=0"`
ffmpeg -loglevel quiet -y -loop 1 -i frame$counterlocal.png -c:v libx264 -t `echo $seconds | perl -nl -MPOSIX -e 'print ceil($_);'` -pix_fmt yuv420p -vf scale=1920:1080 frame$counterlocal.mp4
ffmpeg -loglevel quiet -y -i frame$counterlocal.mp4 -i frame$counterlocal.opus -t `echo $seconds | perl -nl -MPOSIX -e 'print ceil($_);'` frame_$counterlocal.mp4
ls -lstr frame_$counterlocal.mp4
}
rm files.txt
rm frame_*.mp4
rm frame_lessig.mp4
rm frame*.mp4
rm frame*.opus
rm frame*.aiff
rm frame*.png
touch files.txt
export FILE=`ls -Art *.pdf | tail -n 1`
export TEXT_FILE=`echo $FILE | cut -d "." -f1| awk '{print $0".txt"}'`
echo "Convert PDF to text"
pdftotext $FILE $TEXT_FILE
sed '/^[t|s]*$/d' $TEXT_FILE > no_lines.txt
echo $TEXT_FILE
IFS=$(echo -en "\n")
IFS=$'\r\n' GLOBIGNORE='*' command eval 'array=($(cat no_lines.txt))'
len_array=${#array[@]}
COUNTER=1
declare -i TOTAL=$((100))
export cnt=`bc -l <<< $len_array/$TOTAL`
for element in "${array[@]}":
do
convert_PDF_into_text_movie "$COUNTER" "$element" &
COUNTER=$((COUNTER+1))
while [ `ps -f | grep -c pdf2textmovie.sh` -ge 33 ]
do
echo "\n$COUNTER of $len_array videos"
for i in {1..5}
do
echo ".\c"
sleep 1
done
done
done
wait
echo "All subvideos done!"
echo "$len_array"
for (( element = 1; element <= ${#array[@]} ; element++ ))
do
echo "file 'frame_$element.mp4'" >> files.txt
done
ffmpeg -loglevel quiet -threads 8 -f concat -i files.txt -c copy frame_lessig.mp4
echo "Metavideo done!"