forked from PyAV-Org/PyAV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremux.py
More file actions
76 lines (54 loc) · 1.98 KB
/
Copy pathremux.py
File metadata and controls
76 lines (54 loc) · 1.98 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
import array
import argparse
import logging
import sys
import pprint
import subprocess
from PIL import Image
from av import open, time_base
logging.basicConfig(level=logging.DEBUG)
def format_time(time, time_base):
if time is None:
return 'None'
return '%.3fs (%s or %s/%s)' % (time_base * time, time_base * time, time_base.numerator * time, time_base.denominator)
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('input')
arg_parser.add_argument('output')
arg_parser.add_argument('-F', '--iformat')
arg_parser.add_argument('-O', '--ioption', action='append', default=[])
arg_parser.add_argument('-f', '--oformat')
arg_parser.add_argument('-o', '--ooption', action='append', default=[])
arg_parser.add_argument('-a', '--noaudio', action='store_true')
arg_parser.add_argument('-v', '--novideo', action='store_true')
arg_parser.add_argument('-s', '--nosubs', action='store_true')
arg_parser.add_argument('-d', '--nodata', action='store_true')
arg_parser.add_argument('-c', '--count', type=int, default=0)
args = arg_parser.parse_args()
input_ = open(args.input,
format=args.iformat,
options=dict(x.split('=') for x in args.ioption),
)
output = open(args.output, 'w',
format=args.oformat,
options=dict(x.split('=') for x in args.ooption),
)
in_to_out = {}
for i, stream in enumerate(input_.streams):
if (
(stream.type == b'audio' and not args.noaudio) or
(stream.type == b'video' and not args.novideo) or
(stream.type == b'subtitle' and not args.nosubtitle) or
(stream.type == b'data' and not args.nodata)
):
in_to_out[stream] = ostream = output.add_stream(template=stream)
for i, packet in enumerate(input_.demux(in_to_out.keys())):
if args.count and i >= args.count:
break
print '%02d %r' % (i, packet)
print '\tin: ', packet.stream
if packet.dts is None:
continue
packet.stream = in_to_out[packet.stream]
print '\tout:', packet.stream
output.mux(packet)
output.close()