~heckyel/librevideoconverter

ref: 92152b9ee059d322629ccbba269bc6af998eabfd librevideoconverter/lvc/basicconverters.py -rw-r--r-- 5.9 KiB
92152b9e — Jesús Add WebM VP8 1 year, 6 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
import logging
import re

from lvc import converter


class WebM_UHD(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(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(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_VP9(converter.FFmpegConverterInfo):
    media_type = 'format'
    extension = 'webm'
    parameters = ('-f webm -vcodec libvpx-vp9 -g 240 -threads 8 '
                  '-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 8 '
                  '-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 = WebM_UHD('WebM UHD')
webm_hd = WebM_HD('WebM HD')
webm_sd = WebM_SD('WebM SD')
webm_vp9 = WebM_VP9('WebM VP9')
webm_vp8 = WebM_VP8('WebM VP8')
mp4 = MP4('MP4')
theora = OggTheora('Ogg Theora')

video_formats = ('Video',
                 [
                     webm_uhd,
                     webm_hd,
                     webm_sd,
                     webm_vp9,
                     webm_vp8,
                     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]