~heckyel/librevideoconverter

ref: 5e0be6a75ce96eabb949cfc967f0af9bfe3b3ebf librevideoconverter/lvc/basicconverters.py -rw-r--r-- 7.3 KiB
5e0be6a7 — Jesús Add more converter to WebM VP8 and WebM VP9 1 year, 5 months ago
                                                                                
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import logging
import re

from lvc import converter


class WebM_UHD_VP8(converter.FFmpegConverterInfo1080p):
    media_type = 'format'
    extension = 'webm'
    parameters = ('-f webm -vcodec libvpx -g 120 -lag-in-frames 23 '
                  '-deadline good -cpu-used 0 -vprofile 0 -qmax 51 -qmin 11 '
                  '-slices 4 -b:v 4M -acodec libvorbis -ab 128k '
                  '-map_metadata -1 '
                  '-ar 44100')


class WebM_HD_VP8(converter.FFmpegConverterInfo720p):
    media_type = 'format'
    extension = 'webm'
    parameters = ('-f webm -vcodec libvpx -g 120 -lag-in-frames 16 '
                  '-deadline good -cpu-used 0 -vprofile 0 -qmax 51 -qmin 11 '
                  '-slices 4 -b:v 2M -acodec libvorbis -ab 112k '
                  '-map_metadata -1 '
                  '-ar 44100')


class WebM_SD_VP8(converter.FFmpegConverterInfo480p):
    media_type = 'format'
    extension = 'webm'
    parameters = ('-f webm -vcodec libvpx -g 120 -lag-in-frames 16 '
                  '-deadline good -cpu-used 0 -vprofile 0 -qmax 53 -qmin 0 '
                  '-b:v 768k -acodec libvorbis -ab 112k -map_metadata -1 '
                  '-ar 44100')


class WebM_UHD_VP9(converter.FFmpegConverterInfo1080p):
    media_type = 'format'
    extension = 'webm'
    parameters = ('-f webm -vcodec libvpx-vp9 -g 120 -lag-in-frames 23 '
                  '-deadline good -cpu-used 0 -vprofile 0 -qmax 51 -qmin 11 '
                  '-slices 4 -b:v 4M -acodec libopus -ab 128k '
                  '-map_metadata -1 '
                  '-ar 44100')


class WebM_HD_VP9(converter.FFmpegConverterInfo720p):
    media_type = 'format'
    extension = 'webm'
    parameters = ('-f webm -vcodec libvpx-vp9 -g 120 -lag-in-frames 16 '
                  '-deadline good -cpu-used 0 -vprofile 0 -qmax 51 -qmin 11 '
                  '-slices 4 -b:v 2M -acodec libopus -ab 112k '
                  '-map_metadata -1 '
                  '-ar 44100')


class WebM_SD_VP9(converter.FFmpegConverterInfo480p):
    media_type = 'format'
    extension = 'webm'
    parameters = ('-f webm -vcodec libvpx-vp9 -g 120 -lag-in-frames 16 '
                  '-deadline good -cpu-used 0 -vprofile 0 -qmax 53 -qmin 0 '
                  '-b:v 768k -acodec libopus -ab 112k -map_metadata -1 '
                  '-ar 44100')


class WebM_VP9(converter.FFmpegConverterInfo):
    media_type = 'format'
    extension = 'webm'
    parameters = ('-f webm -vcodec libvpx-vp9 -g 240 -threads 4 '
                  '-quality good -crf 32 '
                  '-b:v 0 -acodec libopus -map_metadata -1')


class WebM_VP8(converter.FFmpegConverterInfo):
    media_type = 'format'
    extension = 'webm'
    parameters = ('-f webm -vcodec libvpx -g 240 -threads 4 '
                  '-quality good -crf 32 '
                  '-b:v 0 -acodec libvorbis -map_metadata -1')


class MP4(converter.FFmpegConverterInfo):
    media_type = 'format'
    extension = 'mp4'
    parameters = ('-acodec aac -ab 128k -vcodec libx264 -preset slow '
                  '-map_metadata -1 '
                  '-f mp4 -crf 22')


class MP3(converter.FFmpegConverterInfo):
    media_type = 'format'
    extension = 'mp3'
    parameters = '-f mp3 -ac 2'
    audio_only = True


class OggVorbis(converter.FFmpegConverterInfo):
    media_type = 'format'
    extension = 'ogg'
    parameters = '-f ogg -vn -acodec libvorbis -aq 60'
    audio_only = True


class OggTheora(converter.FFmpegConverterInfo):
    media_type = 'format'
    extension = 'ogv'
    parameters = ('-f ogg -vcodec libtheora -acodec libvorbis '
                  '-qscale:v 7 -qscale:a 5 -map_metadata -1')


class DNxHD_1080(converter.FFmpegConverterInfo1080p):
    media_type = 'format'
    extension = 'mov'
    parameters = ('-r 23.976 -f mov -vcodec dnxhd -b:v '
                  '175M -acodec pcm_s16be -ar 48000')


class DNxHD_720(converter.FFmpegConverterInfo720p):
    media_type = 'format'
    extension = 'mov'
    parameters = ('-r 23.976 -f mov -vcodec dnxhd -b:v '
                  '175M -acodec pcm_s16be -ar 48000')


class PRORES_720(converter.FFmpegConverterInfo720p):
    media_type = 'format'
    extension = 'mov'
    parameters = ('-f mov -vcodec prores -profile 2 '
                  '-acodec pcm_s16be -ar 48000')


class PRORES_1080(converter.FFmpegConverterInfo1080p):
    media_type = 'format'
    extension = 'mov'
    parameters = ('-f mov -vcodec prores -profile 2 '
                  '-acodec pcm_s16be -ar 48000')


class AVC_INTRA_1080(converter.FFmpegConverterInfo1080p):
    media_type = 'format'
    extension = 'mov'
    parameters = ('-f mov  -vcodec libx264 -pix_fmt yuv422p '
                  '-crf 0 -intra -b:v 100M -acodec pcm_s16be -ar 48000')


class AVC_INTRA_720(converter.FFmpegConverterInfo720p):
    media_type = 'format'
    extension = 'mov'
    parameters = ('-f mov  -vcodec libx264 -pix_fmt yuv422p '
                  '-crf 0 -intra -b:v 100M -acodec pcm_s16be -ar 48000')


class NullConverter(converter.FFmpegConverterInfo):
    media_type = 'format'
    extension = None

    def get_parameters(self, video):
        params = []
        if not video.audio_only and self.should_copy_video_size(video):
            # -vcodec copy copies the video data exactly.  Only use it if the
            # output video is the same size as the input video (#19664)
            params.extend(['-vcodec', 'copy'])
            params.extend(['-acodec', 'copy'])
            return params

    def should_copy_video_size(self, video):
        if self.width is None or self.height is None:
            return True
        return (video.width == self.width and video.height == self.height)

    def get_extra_arguments(self, video, output):
        if not video.container:
            logging.warn("sameformat: video.container is None. Using mp4")
            container = 'mp4'
        elif isinstance(video.container, list):
            # XXX: special case mov,mp4,m4a,3gp,3g2,mj2
            container = 'mp4'
        else:
            container = video.container
        return ['-f', container]


mp3 = MP3('MP3')
ogg_vorbis = OggVorbis('Ogg Vorbis')
audio_formats = ('Audio', [mp3, ogg_vorbis])

webm_uhd_vp8 = WebM_UHD_VP8('WebM 1080p VP8')
webm_hd_vp8 = WebM_HD_VP8('WebM 720p VP8')
webm_sd_vp8 = WebM_SD_VP8('WebM 480p VP8')
webm_vp8 = WebM_VP8('WebM VP8')

webm_uhd_vp9 = WebM_UHD_VP9('WebM 1080p VP9')
webm_hd_vp9 = WebM_HD_VP9('WebM 720p VP9')
webm_sd_vp9 = WebM_SD_VP9('WebM 480p VP9')
webm_vp9 = WebM_VP9('WebM VP9')

mp4 = MP4('MP4')
theora = OggTheora('Ogg Theora')

video_formats = ('Video',
                 [
                     webm_uhd_vp8,
                     webm_hd_vp8,
                     webm_sd_vp8,
                     webm_vp8,
                     webm_uhd_vp9,
                     webm_hd_vp9,
                     webm_sd_vp9,
                     webm_vp9,
                     mp4,
                     theora
                 ])

dnxhd_1080 = DNxHD_1080('DNxHD 1080p')
dnxhd_720 = DNxHD_720('DNxHD 720p')
prores_1080 = PRORES_1080('Prores Ingest 1080p')
prores_720 = PRORES_720('Prores Ingest 720p')
avc_intra_1080 = PRORES_1080('AVC Intra 1080p')
avc_intra_720 = PRORES_720('AVC Intra 720p')

ingest_formats = ('Ingest Formats', [dnxhd_1080, dnxhd_720, prores_1080,
                                     prores_720, avc_intra_1080,
                                     avc_intra_720])
null_converter = NullConverter('Same Format')

converters = [video_formats, audio_formats, ingest_formats, null_converter]