-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathpresets.py
More file actions
125 lines (93 loc) · 3.64 KB
/
presets.py
File metadata and controls
125 lines (93 loc) · 3.64 KB
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
from typing import ClassVar
from zimscraperlib.video.config import Config
preset_type = "video"
class VoiceMp3Low(Config):
"""Low quality mp3 audio
44Khz audio sampling
48k audio bitrate
audio-only"""
VERSION = 1
ext = "mp3"
mimetype = "audio/mp3"
options: ClassVar[dict[str, str | None]] = {
"-vn": "", # remove video stream
"-codec:a": "mp3", # audio codec
"-ar": "44100", # audio sampling rate
"-b:a": "48k", # target audio bitrate
"-ac": "2", # force stereo
}
class VideoWebmLow(Config):
"""Low Quality webm video
480:h format with height adjusted to keep aspect ratio
128k target video bitrate but stay within quality boundaries.
48k audio bitrate"""
VERSION = 3
ext = "webm"
mimetype = f"{preset_type}/webm"
options: ClassVar[dict[str, str | None]] = {
"-codec:v": "libvpx-vp9", # video codec
"-b:v": "140k", # Adjust quantizer within min/max to target this bitrate
"-qmin": "30", # Reduce the bitrate on very still videos
"-qmax": "40", # Increase the bitrate on very busy videos
"-g": "240", # Number of frames allowed between keyframes
"-quality": "good", # codec preset
"-speed": "4", # Encoding speed (compromise between quality and encoding time)
"-vf": "scale='480:trunc(ow/a/2)*2'", # frame size
"-codec:a": "libvorbis", # audio codec
"-b:a": "48k", # target audio bitrate
"-ar": "44100", # audio sampling rate
"-ac": "2", # force stereo
}
class VideoMp4Low(Config):
"""Low Quality mp4 video
480:h format with height adjusted to keep aspect ratio
300k video bitrate
48k audio bitrate
highly degraded quality (30, 42)"""
VERSION = 1
ext = "mp4"
mimetype = f"{preset_type}/mp4"
options: ClassVar[dict[str, str | None]] = {
"-codec:v": "h264", # video codec
"-b:v": "300k", # target video bitrate
"-maxrate": "300k", # max video bitrate
"-minrate": "300k", # min video bitrate
"-qmin": "30", # min quantizer scale
"-qmax": "42", # max quantizer scale
"-vf": "scale='480:trunc(ow/a/2)*2'", # frame size
"-codec:a": "aac", # audio codec
"-ar": "44100", # audio sampling rate
"-b:a": "48k", # target audio bitrate
"-movflags": "+faststart", # extra flag
"-ac": "2", # force stereo
}
class VideoWebmHigh(Config):
"""High Quality webm video
25 constant quality"""
VERSION = 2
ext = "webm"
mimetype = f"{preset_type}/webm"
options: ClassVar[dict[str, str | None]] = {
"-codec:v": "libvpx-vp9", # video codec
"-b:v": "340k", # Adjust quantizer within min/max to target this bitrate
"-qmin": "26", # Reduce the bitrate on very still videos
"-qmax": "54", # Increase the bitrate on very busy videos
"-g": "240", # Number of frames allowed between keyframes
"-quality": "good", # codec preset
"-speed": "1", # Encoding speed (compromise between quality and encoding time)
"-codec:a": "libvorbis", # audio codec
"-b:a": "48k", # target audio bitrate
"-ar": "44100", # audio sampling rate
"-ac": "2", # force stereo
}
class VideoMp4High(Config):
"""Low Quality mp4 video
20 constant quality"""
VERSION = 1
ext = "mp4"
mimetype = f"{preset_type}/mp4"
options: ClassVar[dict[str, str | None]] = {
"-codec:v": "h264", # video codec
"-codec:a": "aac", # audio codec
"-crf": "20", # constant quality, lower value gives better qual and larger size
}