Created
January 4, 2024 20:33
-
-
Save 0187773933/b0b14c373339ace8f09f2b14f1adab5d to your computer and use it in GitHub Desktop.
Keeps HDMI Capture Card Device "open" So Loopback Audio Can See It amazon.com/dp/B0CGXFB716
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"os/exec" | |
"os/signal" | |
"syscall" | |
"strconv" | |
"strings" | |
// "time" | |
"gocv.io/x/gocv" | |
"github.com/manifoldco/promptui" | |
) | |
func get_devices_mac_osx() ( result []string ) { | |
swift_code := `import AVFoundation | |
import os | |
let stderr = FileHandle.standardError | |
let null_device = FileHandle( forUpdatingAtPath: "/dev/null" )! | |
dup2( null_device.fileDescriptor , stderr.fileDescriptor ) | |
let discoverySession = AVCaptureDevice.DiscoverySession( | |
deviceTypes: [.builtInWideAngleCamera, .external], | |
mediaType: .video, | |
position: .unspecified | |
) | |
let devices = discoverySession.devices | |
for ( index , device ) in devices.enumerated() { | |
print( "\(index) === \(device.localizedName) === \(device.manufacturer)" ) | |
}` | |
cmd := exec.Command( "swift" , "-e" , swift_code ) | |
output , err := cmd.Output() | |
if err != nil { | |
fmt.Println( "Failed to execute Swift code:", err ) | |
return nil | |
} | |
result = strings.Split( strings.TrimSpace( string( output ) ) , "\n" ) | |
return | |
} | |
func main() { | |
device_id := 0 | |
if len( os.Args ) > 1 { | |
device_id , _ = strconv.Atoi( os.Args[1] ) | |
} else { | |
devices := get_devices_mac_osx() | |
prompt := promptui.Select{ | |
Label: "Select Device" , | |
Items: devices , | |
} | |
device_id , _ , _ = prompt.Run() | |
} | |
webcam , err := gocv.OpenVideoCapture( device_id ) | |
if err != nil { | |
fmt.Println( err ) | |
return | |
} | |
defer webcam.Close() | |
fmt.Println( webcam ) | |
x_image := gocv.NewMat() | |
defer x_image.Close() | |
// go func() { | |
// for { | |
// webcam.Read( &x_image ) | |
// } | |
// }() | |
webcam.Read( &x_image ) | |
c := make( chan os.Signal ) | |
signal.Notify( c , os.Interrupt , syscall.SIGTERM ) | |
<-c | |
fmt.Println( "Shutting Down..." ) | |
// gocv.IMWrite( "test.png" , x_image ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment