-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathgenassets.py
executable file
·108 lines (96 loc) · 3.12 KB
/
genassets.py
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
#!/usr/bin/env python3
###
### Copyright (C) 2018-2019 Intel Corporation
###
### SPDX-License-Identifier: BSD-3-Clause
###
import subprocess
import os
import sys
from ..lib.common import exe2os
resolutions = [(176, 144), (320, 240), (1280, 720), (1920,1080),]
res_std = {
(176, 144) : "QCIF",
(320, 240) : "QVGA",
(1280, 720) : "720p",
(1920,1080) : "1080p",
}
formats = ["NV12",]
spec = dict(
avc = dict(
encoder = "vaapih264enc ! h264parse",
decoder = "h264parse ! vaapih264dec",
extension = "h264",
),
hevc = dict(
encoder = "vaapih265enc ! h265parse",
decoder = "h265parse ! vaapih265dec",
extension = "h265",
),
jpeg = dict(
encoder = "vaapijpegenc ! jpegparse",
decoder = "jpegparse ! vaapijpegdec",
extension = "mjpg",
),
mpeg2 = dict(
encoder = "vaapimpeg2enc ! mpegvideoparse",
decoder = "mpegvideoparse ! vaapimpeg2dec",
extension = "mpeg2",
),
vp8 = dict(
encoder = "vaapivp8enc ! matroskamux",
decoder = "matroskademux ! vaapivp8dec",
extension = "webm",
),
vp9 = dict(
encoder = "vaapivp9enc ! matroskamux",
decoder = "matroskademux ! vaapivp9dec",
extension = "webm",
),
)
for codec, params in spec.items():
p = params.copy()
p.update(path = "./assets/{}".format(codec))
p.update(ypath = "./assets/yuv")
p.update(codec = codec)
if not os.path.exists(p["path"]):
os.makedirs(p["path"])
if not os.path.exists(p["ypath"]):
os.makedirs(p["ypath"])
for width, height in resolutions:
p.update(width = width, height = height, resname = res_std[(width, height)])
p.update(encoded = "{resname}.{extension}".format(**p))
subprocess.check_call(
f"{exe2os('gst-launch-1.0')} videotestsrc num-buffers=50 pattern=smpte"
" ! video/x-raw,width={width},height={height}"
" ! {encoder}"
" ! filesink location={path}/{encoded}"
"".format(**p),
shell = True)
for format in formats:
if codec not in ["jpeg", "mpeg2"]:
continue
p.update(format = format)
p.update(decoded = "{encoded}_ref.{format}.yuv".format(**p))
subprocess.check_call(
f"{exe2os('gst-launch-1.0')}"
" filesrc location={path}/{encoded}"
" ! {decoder}"
" ! videoconvert ! video/x-raw,format={format},width={width},height={height}"
" ! checksumsink2 file-checksum=false"
" frame-checksum=false plane-checksum=false dump-output=true"
" dump-location={ypath}/{decoded}"
"".format(**p),
shell = True)
for width, height in resolutions:
for format in formats:
subprocess.check_call(
f"{exe2os('gst-launch-1.0')} videotestsrc num-buffers=300 pattern=smpte"
" ! video/x-raw,width={width},height={height},format={format}"
" ! checksumsink2 file-checksum=false frame-checksum=false"
" plane-checksum=false dump-output=true"
" dump-location=./assets/yuv/{resname}_{format}.yuv".format(
width = width, height = height, format = format,
resname = res_std[(width, height)]),
shell = True)
subprocess.check_call("sync && tar cjvf assets.tbz2 assets", shell = True)