P
P
prilichny2019-12-31 17:43:00
Swift
prilichny, 2019-12-31 17:43:00

How to start and then terminate vlc in Swift 4?

I'm trying to create an application that would allow you to record what is happening on the screen using vlc.
I found a handy line
/Applications/VLC.app/Contents/MacOS/VLC -I dummy screen:// --screen-fps=25 --quiet --sout "#transcode{vcodec=h264,vb072}:standard{access= file,mux=mp4,dst="Desktop/vlc-output-terminal.mp4"}"
which allows you to instantly start recording. Stop recording - ctrl+c.
All this works fine in the terminal. Now I want to pack into an application.
Found this:
https://iswift.org/cookbook/execute-a-shell-command
When I start I get
Couldn't posix_spawn: error 1

Here is the full text of the error

2018-12-31 18:12:28.583388+0300 CenLock[1857:91753] [General] An uncaught exception was raised
2018-12-31 18:12:28.583464+0300 CenLock[1857:91753] [General] Couldn't posix_spawn: error 1
2018-12-31 18:12:28.587944+0300 CenLock[1857:91753] [General] (
0 CoreFoundation 0x00007fff29d8d59b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fff510c0942 objc_exception_throw + 48
2 CoreFoundation 0x00007fff29e1d935 +[NSException raise:format:] + 197
3 Foundation 0x00007fff2c00c5c0 -[NSConcreteTask launchWithDictionary:error:] + 4486
4 CenLock 0x00000001000042b5 $S7CenLock11AppDelegateC14startRecordingyyypSgF + 293
5 CenLock 0x000000010000477c $S7CenLock11AppDelegateC14startRecordingyyypSgFTo + 188
6 AppKit 0x00007fff27a30a43 -[NSApplication(NSResponder) sendAction:to:from:] + 312
7 AppKit 0x00007fff274c5213 -[NSMenuItem _corePerformAction] + 323
8 AppKit 0x00007fff274c4f9b -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 114
9 AppKit 0x00007fff2754ac7a -[NSMenu performActionForItemAtIndex:] + 133
10 AppKit 0x00007fff2754abe5 -[NSMenu _internalPerformActionForItemAtIndex:] + 94
11 AppKit 0x00007fff2754aa15 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 106
12 AppKit 0x00007fff274112a2 NSSLMMenuEventHandler + 882
13 HIToolbox 0x00007fff28fc1904 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1541
14 HIToolbox 0x00007fff28fc0c4d _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 374
15 HIToolbox 0x00007fff28fd5f21 SendEventToEventTarget + 39
16 HIToolbox 0x00007fff2901f3f9 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 411
17 HIToolbox 0x00007fff290482ee SendMenuCommandWithContextAndModifiers + 49
18 HIToolbox 0x00007fff290482aa SendMenuItemSelectedEvent + 188
19 HIToolbox 0x00007fff29048184 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 96
20 HIToolbox 0x00007fff2916087c _ZL19PopUpMenuSelectCoreP8MenuData5PointdS1_tjjPK4RecttjS4_S4_PK14__CFDictionaryPK10__CFStringPP13OpaqueMenuRefPt + 1662
21 HIToolbox 0x00007fff2915fcf7 _ZL26_HandlePopUpMenuSelection8P13OpaqueMenuRefP14OpaqueEventRefj5PointtjjPK4RecttS6_S6_PK14__CFDictionaryPK10__CFStringPS0_Pt + 409
22 HIToolbox 0x00007fff2902840c _HandlePopUpMenuSelectionWithDictionary + 268
23 AppKit 0x00007fff2754179a _NSSLMPopUpCarbonMenu3 + 5632
24 AppKit 0x00007fff275400f4 -[NSCarbonMenuImpl popUpMenu:atLocation:width:forView:withSelectedItem:withFont:withFlags:withOptions:] + 439
25 AppKit 0x00007fff27a1bc6b +[NSStatusBarButtonCell popupStatusBarMenu:inRect:ofView:withEvent:] + 1003
26 AppKit 0x00007fff27a1ad3a -[NSStatusBarButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 159
27 AppKit 0x00007fff274d3670 -[NSControl mouseDown:] + 965
28 AppKit 0x00007fff27bcfd6d -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 5891
29 AppKit 0x00007fff27bcc9c4 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2359
30 AppKit 0x00007fff27bcbc70 -[NSWindow(NSEventRouting) sendEvent:] + 497
31 AppKit 0x00007fff27a1e885 -[NSStatusBarWindow sendEvent:] + 348
32 AppKit 0x00007fff27a2d236 -[NSApplication(NSEvent) sendEvent:] + 2462
33 AppKit 0x00007fff2728d8b5 -[NSApplication run] + 812
34 AppKit 0x00007fff2725ca72 NSApplicationMain + 804
35 CenLock 0x000000010000a07d main + 13
36 libdyld.dylib 0x00007fff51cd7015 start + 1
)

I googled, but I couldn’t find any sensible explanation for macOS, or how to get around this business.
What is the difference between their example /usr/bin/env and /Applications/VLC.app/Contents/MacOS/VLC ?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question