-
Notifications
You must be signed in to change notification settings - Fork 6
/
capture.py
52 lines (49 loc) · 1.86 KB
/
capture.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
#!/usr/bin/env python3
from subprocess import Popen, PIPE, STDOUT
import json
import argparse
parser = argparse.ArgumentParser(description='Video Capture')
parser.add_argument('--video_size', default="720x480", help='Video resolution setting for capture device')
parser.add_argument('--scale_to', default="640x480", help='Scale video to resolution')
parser.add_argument('--fps', default=29.97, type=float, help='Frames per second (float)')
parser.add_argument('--device', default="Conexant Polaris Video Capture", help='Capture device name')
parser.add_argument('--time', default="2:05:00", help='Capture time limit')
parser.add_argument('--crf', default=24, type=int, help='CRF setting')
parser.add_argument('--maxrate', default=2500, type=int, help='Maximum bitrate')
parser.add_argument('--out', required=True, help='Output file')
args = parser.parse_args()
cmd = [
"ffmpeg",
"-framerate", str(args.fps),
"-vsync", "1",
"-video_size", "720x480",
"-f", "dshow",
"-rtbufsize", "250000k",
"-crossbar_video_input_pin_number", "1",
"-crossbar_audio_input_pin_number", "2",
"-i", "video=" + args.device + ":audio=" + args.device,
"-t", args.time,
"-force_key_frames", ",".join(["00:00:%02d.000" % x for x in range(11)]),
"-vf", "fps=" + str(args.fps) + ",yadif=0:0:0,hqdn3d=6:4:6:4,scale=" + args.scale_to,
"-c:v", "libx264",
"-preset", "medium",
"-tune", "film",
"-profile:v", "main",
"-level", "3.1",
"-pix_fmt", "yuv420p",
"-crf", str(args.crf),
"-maxrate", str(args.maxrate) + "k",
"-bufsize", str(args.maxrate*2) + "k",
"-af", "aresample=async=1000,highpass=200,lowpass=3500",
"-c:a", "aac",
"-b:a", "96k",
"-strict", "-2",
"-r", str(args.fps),
args.out
]
print(cmd)
p = Popen(cmd, stdout=None, stderr=None)
#for line in p.stdout:
# print("FFMPEG: " + line.decode('utf-8').rstrip())
exit = p.wait()
print("FFMPEG exit code " + str(exit))