forked from idlerun/vhs-convert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
capture.py
113 lines (102 loc) · 3.59 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
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
#!/usr/bin/env python3
from subprocess import Popen, PIPE, STDOUT
import json
import argparse
import subprocess
import server
import threading
import time
from multiprocessing import Process
MY_VI_DEVICE = "USB2.0 Grabber"
MY_AU_DEVICE = "Digitale Audioschnittstelle (USB Audio Interface)"
V_CH = "0"
A_CH = "4"
END_SEQUENCE ="q"
e_dict = {
"E-30": "01:05:00",
"E-60": "02:07:00",
"E-90": "03:07:00",
"E-120": "04:09:00",
"E-150": "05:09:00",
"E-180": "06:10:00",
"E-195": "06:38:00",
"E-200": "06:46:00",
"E-210": "07:14:00",
"E-240": "08:17:00",
"E-270": "09:20:00",
"E-300": "10:21:00"
}
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=MY_VI_DEVICE, help='Capture device name')
parser.add_argument("--time", default="12:10:00", help='Capture time limit')
parser.add_argument("--crf", default=24, type=int, help='CRF setting')
parser.add_argument("--maxrate", default=25000, type=int, help='Maximum bitrate')
parser.add_argument("--out", required=True, help='Output file')
parser.add_argument("--preset", default="fast", help="ffmpeg capture preset `veryslow`, `slower`, `slow`, `medium`, `fast`, `faster`, `veryfast`.")
parser.add_argument("--shutdown", required=False, help="add flag to shudown after finisch..", default=False, action="store_true")
parser.add_argument("--start", required=False, help="promt for key before start", default=False, action="store_true")
parser.add_argument("--socket", required=False, help="use socket", default=False, action="store_true")
args, unkown = parser.parse_known_args()
def shutdown():
print("shutting down in 120sec..")
subprocess.call(["shutdown", "/s", "/t", "120"])
def e_to_time(s):
return e_dict[s]
# rotes audio kebel hernehmen!
# convert E-** to time **:**:** https://en.wikipedia.org/wiki/VHS "PAL market"
if args.time.startswith("E"):
if args.time in e_dict.keys():
print("convert E-** to timeformat...")
args.time = e_to_time(args.time)
cmd = [
"ffmpeg",
"-framerate", str(args.fps),
"-vsync", "1",
"-video_size", "720x480",
"-f", "dshow",
"-rtbufsize", "450000k",
"-crossbar_video_input_pin_number", V_CH, # video pin
"-crossbar_audio_input_pin_number", A_CH, # audio pin
"-i", "video=" + MY_VI_DEVICE + ":audio=" + MY_AU_DEVICE, # MY_AU_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", args.preset,
"-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
]
def main():
print("".join(cmd) + "\n\n\n\n\n\n")
if not args.socket:
p = Popen(cmd, stdout=None, stderr=None)
elif args.socket:
cmd.append("-y")
p = Popen(cmd, stdout=None, stderr=None, stdin=PIPE)
s = server.server()
if s:
p.communicate(input=b"q")
else:
pass
exit = p.wait()
print("FFMPEG exit code " + str(exit))
if __name__ == "__main__":
if args.start:
input("\n\n\n #### Start? ####\n\n\n")
main()
if args.shutdown:
shutdown()