-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathffmpeg_wrapper.nim
48 lines (42 loc) · 1.12 KB
/
ffmpeg_wrapper.nim
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
import os
import osproc
import wNim
import winim
var running_process = false
var the_proc: Process
const procOpts = {
poUsePath,
poEvalCommand,
poEchoCmd,
poInteractive,
poStdErrToStdOut,
poParentStreams
}
let app = App()
let frame = Frame(title="ffmpeg_wrap", size=(400, 300))
frame.connect(WM_MOVE) do (event: wEvent):
if running_process == false:
running_process = true
var command_str: string = paramStr(1)
for i in 2..paramCount():
var param: string = paramStr(i)
if param.contains(' '):
param = "\"" & paramStr(i) & "\""
else:
param = paramStr(i)
command_str = command_str & " " & param
the_proc = startProcess(command_str, "", [], nil, procOpts)
frame.connect(WM_CLOSE) do (event: wEvent):
# Use windows API to send the Ctrl+C
let ev: DWORD = 0
let pid: DWORD = the_proc.processID()
GenerateConsoleCtrlEvent(ev, pid)
echo "Waiting for ffmpeg to finish..."
discard the_proc.waitForExit(120000)
echo "Ffmpeg finished!"
if the_proc.running():
echo "Terminating ffmpeg"
the_proc.terminate()
quit(QuitSuccess)
frame.center()
app.mainLoop()