-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvideo_output_CACA.sh
158 lines (112 loc) · 3.69 KB
/
video_output_CACA.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/bash
# -*- coding: UTF-8 -*-
# Video Export
# Ref: http://stariocek.asuscomm.com/watch-ascii-libcaca.html
# 0. Preset Input
read -p "Enter the path of the input video: " RAW_INPUT
read -p "Enter the resolution of the original video (e.g. 1920x1080): " video_resolution
read -p "Enter the FPS of the original video: " video_fps
PAD_ADD='Y'
PAD_NOT_ADD='N'
OUTPUT_UNSCALED_ONLY='1'
OUTPUT_SCALED_ONLY='2'
OUTPUT_BOTH='3'
VERBOSE_MODE='4'
read -p "
Please Choose a Output Mode:
1 -- Output Unscaled Only
2 -- Output Scaled Only
3 -- Both 1 and 2,
4 -- Verbose Mode
Mode Choice: " output_mode
if [ $output_mode != $OUTPUT_UNSCALED_ONLY ]; then
read -p "Would you like to add a black pad as background? (Y/N) " pad_add_choice_input
pad_add_choice=$(echo $pad_add_choice_input | tr "[:lower:]" "[:upper:]")
fi
read -p "Enter the number of FFmpeg's thread amount: " thread_amount
# 1. video2jpg
echo "Step 1: Video to JPG"
ffmpeg -threads $thread_amount \
-i "$RAW_INPUT" \
-r $video_fps -s $video_resolution -f image2 \
%07d.jpg
# 2. img2txt
echo "Step 2: JPG to TXT (HTML):"
for ascii in *.jpg; do
img2txt -W 128 -H 36 -x 3 -y 5 $ascii -f html > $(basename $ascii .jpg).html;
# "... -W 128" means 128 ASCII columns.
# "... -H 36" means 36 rows.
# "... -x 3 -y 5" means font size 3x5.
done
# 3. html2png
echo "Step 3: TXT (HTML) to PNG"
for LibCaca in *.html; do
webkit2png -F -o $(basename $LibCaca .html) $LibCaca;
done
# 4. png2video
echo "Step 4: PNG to Video"
# for i in *-full.png; do
# mv $i $(basename $i -full.png).png
# done
if [ $output_mode == $OUTPUT_UNSCALED_ONLY ]; then
ffmpeg -threads $thread_amount -start_number 1 \
-i %07d-full.png \
-i "$RAW_INPUT" \
-movflags +faststart \
-c:v libx264 -pix_fmt yuv420p -r $video_fps \
-preset slower -profile:v high -level 5.1 \
-vf "crop=2458:1296:16:16" \
-map 0:v:0 -map 1:a:0 output_yuv420.mp4
elif [ $output_mode == $OUTPUT_SCALED_ONLY ]; then
ffmpeg -threads $thread_amount -start_number 1 \
-i %07d-full.png \
-i "$RAW_INPUT" \
-movflags +faststart \
-c:v libx264 -pix_fmt yuv420p -r $video_fps \
-preset slower -profile:v high -level 5.1 \
-vf "crop=2458:1296:16:16, scale=1920:1080:force_original_aspect_ratio=decrease" \
-map 0:v:0 -map 1:a:0 output_yuv420.mp4
# Frame Size Modify (Including Scale and Pad)
INPUT=output_yuv420.mp4
OUTPUT=output_1080p.mp4
if [ $pad_add_choice == $PAD_NOT_ADD ]; then
ffmpeg -threads $thread_amount -i $INPUT -c:a copy \
-vf "scale=1920:1080:force_original_aspect_ratio=decrease" \
$OUTPUT
elif [ $pad_add_choice == $PAD_ADD ]; then
ffmpeg -threads $thread_amount \
-i $INPUT -c:a copy \
-vf "scale=1920:1080:force_original_aspect_ratio=decrease, pad=1920:1080:0:(1080-in_h)/2:black" \
$OUTPUT
fi
elif [ $output_mode == $OUTPUT_BOTH ]; then
ffmpeg -threads $thread_amount -start_number 1 \
-i %07d-full.png \
-i "$RAW_INPUT" \
-movflags +faststart \
-c:v libx264 -pix_fmt yuv420p -r $video_fps \
-preset slower -profile:v high -level 5.1 \
-vf "crop=2458:1296:16:16" \
-map 0:v:0 -map 1:a:0 output_yuv420.mp4
# Frame Size Modify (Including Scale and Pad)
INPUT=output_yuv420.mp4
OUTPUT=output_1080p.mp4
if [ $pad_add_choice == $PAD_NOT_ADD ]; then
ffmpeg -threads $thread_amount -i $INPUT -c:a copy \
-vf "scale=1920:1080:force_original_aspect_ratio=decrease" \
$OUTPUT
elif [ $pad_add_choice == $PAD_ADD ]; then
ffmpeg -threads $thread_amount \
-i $INPUT -c:a copy \
-vf "scale=1920:1080:force_original_aspect_ratio=decrease, pad=1920:1080:0:(1080-in_h)/2:black" \
$OUTPUT
fi
fi
if [ $output_mode != $VERBOSE_MODE ]; then
rm *.jpg
rm *.html
rm *.png
fi
# Ref
# 4:3 --> 16:9
# -vf cropdetect, pad=ih*16/9:ih:(ow-iw)/2:0:black, scale=1920:1080