Jump to content

Recommended Posts

Ok so im trying to use ffmpeg to get the Dshow devices available 

Here is what i have so far

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Global $sFolder = @ScriptDir & "\www\videos"
Global $FFmpegDir =  @ScriptDir & "\www\bin\"

$sCommands = "FFmpeg -list_devices true -f dshow -i dummy"
$iPID = Run("cmd /c " & $sCommands, $FFmpegDir , @SW_Hide , $stderr_child + $stdout_child)

$sOutput = ""
 While 1
        $sOutput &= StderrRead($iPID)

        If @error Then ; Exit the loop if the process closes or StderrRead returns an error.
            ExitLoop
        EndIf
     WEnd

;ConsoleWrite($sOutput  & @CRLF)

Local $iPosition = StringInStr($sOutput, "[dshow")
Local $sString = StringTrimLeft($sOutput, $iPosition -1)
Local $iPosition2 = StringInStr($sString, "dummy: Immediate exit requested")
Local $iLength = StringLen($sString)
Local $CutRight = $iLength - $iPosition2
Local $dStrings = StringTrimRight($sString, $CutRight + 1)
ConsoleWrite($dStrings  & @CRLF)


this is what i get back:

[dshow @ 02b85e40] DirectShow video devices
[dshow @ 02b85e40]  "CyberLink Webcam Splitter"
[dshow @ 02b85e40]  "USB Video Device"
[dshow @ 02b85e40]  "IP Camera [JPEG/MJPEG]"
[dshow @ 02b85e40]  "DroidCam"
[dshow @ 02b85e40] DirectShow audio devices
[dshow @ 02b85e40]  "USB Audio Device"
[dshow @ 02b85e40]  "Realtek HD Audio Input"


all i really want is the devices split up can come back as an array so i can put into a combo box for each of the below

1.) DirectShow video devices
2.)  DirectShow audio devices

each machine i am assuming will have different  than this "[dshow @ 02b85e40]"  so not a 100 % sure i could/should just do another "StringTrimLeft" just in case its more letters/numbers.

heck i prob didn't need what i had done as it is... sure there is an easier way

Thank you for your help

Share this post


Link to post
Share on other sites

This ?

#Include <Array.au3>

$dStrings = '[dshow @ 02b85e40] DirectShow video devices' & @CRLF & _
           '[dshow @ 02b85e40]  "CyberLink Webcam Splitter"' & @CRLF & _
           '[dshow @ 02b85e40]  "USB Video Device"' & @CRLF & _
           '[dshow @ 02b85e40]  "IP Camera [JPEG/MJPEG]"' & @CRLF & _
           '[dshow @ 02b85e40]  "DroidCam"' & @CRLF & _
           '[dshow @ 02b85e40] DirectShow audio devices' & @CRLF & _
           '[dshow @ 02b85e40]  "USB Audio Device"' & @CRLF & _
           '[dshow @ 02b85e40]  "Realtek HD Audio Input"'

$sVideo = StringRegExpReplace($dStrings, '(?s).*\[[^\]]+\]\h+DirectShow video devices\R((?:\[[^\]]+\]\h+"[^"]+"(?:\R|$))+).*', "$1")
$aVideoDevices = StringRegExp($sVideo, '"([^"]+)"', 3)
_ArrayDisplay($aVideoDevices, "Video devices")


$sAudio = StringRegExpReplace($dStrings, '(?s).*\[[^\]]+\]\h+DirectShow audio devices\R((?:\[[^\]]+\]\h+"[^"]+"(?:\R|$))+).*', "$1")
$aAudioDevices = StringRegExp($sAudio, '"([^"]+)"', 3)
_ArrayDisplay($aAudioDevices, "Audio devices")

 

Share this post


Link to post
Share on other sites

'nother one ...  :)

#Include <Array.au3>

$dStrings = '[dshow @ 02b85e40] DirectShow video devices' & @CRLF & _
           '[dshow @ 02b85e40]  "CyberLink Webcam Splitter"' & @CRLF & _
           '[dshow @ 02b85e40]  "USB Video Device"' & @CRLF & _
           '[dshow @ 02b85e40]  "IP Camera [JPEG/MJPEG]"' & @CRLF & _
           '[dshow @ 02b85e40]  "DroidCam"' & @CRLF & _
           '[dshow @ 02b85e40] DirectShow audio devices' & @CRLF & _
           '[dshow @ 02b85e40]  "USB Audio Device"' & @CRLF & _
           '[dshow @ 02b85e40]  "Realtek HD Audio Input"'

$nV = "DirectShow video devices"
$nA = "DirectShow audio devices"
$dev = StringRegExp($dStrings, '(?s)(' & $nV & '.*)(' & $nA & '.*)', 3)

$video = StringRegExp($dev[0], '"([^"]+)"' , 3)
_ArrayDisplay($video, $nV)

$audio = StringRegExp($dev[1], '"([^"]+)"' , 3)
_ArrayDisplay($audio, $nA)

 

Edited by mikell

Share this post


Link to post
Share on other sites

this is what i did, is there a way to make the for loops into one? to clean it up?
 

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#Include <Array.au3>

Global $FFmpegDir =  @ScriptDir & "\www\bin\"

$sCommands = "FFmpeg -list_devices true -f dshow -i dummy"
$iPID = Run("cmd /c " & $sCommands, $FFmpegDir , @SW_Hide , $stderr_child + $stdout_child)

$sOutput = ""
 While 1
        $sOutput &= StderrRead($iPID)

        If @error Then ; Exit the loop if the process closes or StderrRead returns an error.
            ExitLoop
        EndIf
     WEnd


$sVideo = StringRegExpReplace($sOutput, '(?s).*\[[^\]]+\]\h+DirectShow video devices\R((?:\[[^\]]+\]\h+"[^"]+"(?:\R|$))+).*', "$1")
$aVideoDevices = StringRegExp($sVideo, '"([^"]+)"', 3)

$sAudio = StringRegExpReplace($sOutput, '(?s).*\[[^\]]+\]\h+DirectShow audio devices\R((?:\[[^\]]+\]\h+"[^"]+"(?:\R|$))+).*', "$1")
$aAudioDevices = StringRegExp($sAudio, '"([^"]+)"', 3)


Local $vDshow = ""
For $vid In $aVideoDevices
    $vDshow = $vDshow & $vid & @CRLF
 Next
MsgBox(0, "DirectShow video devices", $vDshow)


Local $aDshow = ""
For $aud In $aAudioDevices
    $aDshow = $aDshow & $aud & @CRLF
 Next
MsgBox(0, "DirectShow audio devices", $aDshow)

 

Share this post


Link to post
Share on other sites

Try with this code :

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Global $FFmpegDir = @ScriptDir & "\www\bin\"

$sCommands = "FFmpeg -list_devices true -f dshow -i dummy"
$iPID = Run("cmd /c " & $sCommands, $FFmpegDir , @SW_Hide , $stderr_child + $stdout_child)

$sOutput = ""
While 1
    $sOutput &= StderrRead($iPID)
    If @error Then ExitLoop
WEnd
Local $sVideoDevices, $sAudioDevices
Local $iVideoLine = 0, $iAudioLine = 0

$aLines = StringRegExp($sOutput, '\[[^\]]+\]\h+(?|(DirectShow (?:audio|video) devices)|"([^"]+)"|(Could not enumerate\N+))', 3)
For $i = 0 To UBound($aLines) - 1
    If StringInStr($aLines[$i], "DirectShow video devices") Then
        $iVideoLine = 1
        $iAudioLine = 0
        ContinueLoop
    ElseIf StringInStr($aLines[$i], "DirectShow audio devices") Then
        $iAudioLine = 1
        $iVideoLine = 0
        ContinueLoop
    EndIf
    
    If $iVideoLine Then $sVideoDevices &= $aLines[$i] & @CRLF
    If $iAudioLine Then $sAudioDevices &= $aLines[$i] & @CRLF
Next

MsgBox(0, "DirectShow video devices", $sVideoDevices)
MsgBox(0, "DirectShow audio devices", $sAudioDevices)

Edit : I edited my code because when I tried the code on my computer an I saw this error :

[dshow @ 02c09800] DirectShow video devices (some may be both video and audio devices)
[dshow @ 02c09800] Could not enumerate video devices (or none found).
[dshow @ 02c09800] DirectShow audio devices
[dshow @ 02c09800]  "Realtek Digital Input (Realtek "
[dshow @ 02c09800]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\Realtek Digital Input (Realtek "
dummy: Immediate exit requested

Edited by jguinch

Share this post


Link to post
Share on other sites

or this one  :D

$dStrings = '[dshow @ 02b85e40] DirectShow video devices' & @CRLF & _
           '[dshow @ 02b85e40]  "CyberLink Webcam Splitter"' & @CRLF & _
           '[dshow @ 02b85e40]  "USB Video Device"' & @CRLF & _
           '[dshow @ 02b85e40]  "IP Camera [JPEG/MJPEG]"' & @CRLF & _
           '[dshow @ 02b85e40]  "DroidCam"' & @CRLF & _
           '[dshow @ 02b85e40] DirectShow audio devices' & @CRLF & _
           '[dshow @ 02b85e40]  "USB Audio Device"' & @CRLF & _
           '[dshow @ 02b85e40]  "Realtek HD Audio Input"'

$nV = "DirectShow video devices"
$nA = "DirectShow audio devices"
$dev = StringRegExp($dStrings, '(?s)(' & $nV & '.*)(' & $nA & '.*)', 3)

$pattern = '(?m)(^[^"]+"?)|("(?=\R?))'
msgbox(0, $nV, $nV &@crlf&@crlf& StringRegExpReplace($dev[0], $pattern , ""))
msgbox(0, $nA, $nA &@crlf&@crlf& StringRegExpReplace($dev[1], $pattern , ""))

 

Edited by mikell

Share this post


Link to post
Share on other sites

 

​heck yeah that was a lot cleaner code than mine...

i think the issue is the $dstrings wouldb ebe different on every pc so i went with just getting the $sOutput from the  StderrRead​

seems to work without the need for the $dDtrings

Share this post


Link to post
Share on other sites

#Include <Array.au3>

$dStrings = '[dshow @ 02b85e40] DirectShow video devices' & @CRLF & _
           '[dshow @ 02b85e40]  "CyberLink Webcam Splitter"' & @CRLF & _
           '[dshow @ 02b85e40]  "USB Video Device"' & @CRLF & _
           '[dshow @ 02b85e40]  "IP Camera [JPEG/MJPEG]"' & @CRLF & _
           '[dshow @ 02b85e40]  "DroidCam"' & @CRLF & _
           '[dshow @ 02b85e40] DirectShow audio devices' & @CRLF & _
           '[dshow @ 02b85e40]  "USB Audio Device"' & @CRLF & _
           '[dshow @ 02b85e40]  "Realtek HD Audio Input"'

$aSplit = stringsplit($dStrings , "DirectShow audio devices" & @CRLF , 3)

$aVideo = stringsplit($aSplit[0] , @CRLF , 3)
_ArrayDelete($aVideo , ubound($aVideo) - 1)
_ArrayDelete($aVideo , 0)

$aAudio = stringsplit($aSplit[1] , @CRLF , 3)


_ArrayDisplay($aVideo , "Video")
_ArrayDisplay($aAudio , "Audio")

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By BlueBandana
      Is there a way to output the regex matches into a file?
      I have a script to compare two files and check for regex matches.
      I want to output the matching regex of 'testexample.txt' to another file.
      #include <MsgBoxConstants.au3> #include <Array.au3> $Read = FileReadToArray("C:\Users\admin\Documents\testexample.txt") $Dictionary = FileReadToArray("C:\Users\admin\Documents\example.txt") For $p = 0 To UBound($Dictionary) - 1 Step 1 $pattern = $Dictionary[$p] For $i = 0 To UBound($Read) - 1 Step 1 $regex = $Read[$i] If StringRegExp($regex, $pattern, 0) Then MsgBox(0, "ResultsPass", "The string is in the file, highlighted strings: " ) Else MsgBox(0, "ResultsFail", "The string isn't in the file.") EndIf Next Next  
    • By therks
      So I have this pattern: 
      ^(?:(\d+)|(\d+):(\d+)|(\d+):(\d+):(\d+))$ And I'm expecting (depending on input) to get a 1, 2 or 3 index array (or @error for invalid input).
      But instead I get this:
      #include <Debug.au3> Func Test($String) _DebugArrayDisplay(StringRegExp($String, '^(?:(\d+)|(\d+):(\d+)|(\d+):(\d+):(\d+))$', 1)) EndFunc Test('10') ; Results (normal, expected): ; Row 0|10 Test('10:20') ; Results (extra blank index): ; Row 0| ; Row 1|10 ; Row 2|20 Test('10:20:30') ; Results (three blank indices): ; Row 0| ; Row 1| ; Row 2| ; Row 3|10 ; Row 4|20 ; Row 5|30 Is this normal? Should I just code around it, or is there a better way to do what I'm looking for?
      I also tried reversing my regex, but it was even uglier results:
      #include <Debug.au3> Func Test($String) _DebugArrayDisplay(StringRegExp($String, '^(?:(\d+):(\d+):(\d+))|(\d+):(\d+)|(\d+)$', 1)) EndFunc Test('10') ; Results (yuck): ; Row 0| ; Row 1| ; Row 2| ; Row 3| ; Row 4| ; Row 5|10 Test('10:20') ; Results (slightly better): ; Row 0| ; Row 1| ; Row 2| ; Row 3|10 ; Row 4|20 Test('10:20:30') ; Results (nice): ; Row 0|10 ; Row 1|20 ; Row 2|30  
    • By Deye
      Hi,
      I want to add any needed conditions to the StringRegExp command so it can pull out only  "File.au3", "WinAPIFiles.au3", "Test.bmp" into the array
      #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include 'WinAPIFiles.au3' #include "File.au3" ; Script Start - Add your code below here Local $bFileInstall = False ; Change to True and ammend the file paths accordingly. ; This will install the file C:\Test.bmp to the script location. If $bFileInstall Then FileInstall("C:\Test.bmp", @ScriptDir & "\Test.bmp") $sFile = FileRead(@ScriptFullPath) $aResults = StringRegExp($sFile, "(?i)(FileInstall\s*|include\s*)(.*)", 3) _ArrayDisplay($aResults) Thanks In Advance
      Deye
    • By FroVN
      i have a text : <Name>Jonh</Name>.<Age>15</Age>
      how i can get Jonh and 15 in one stringregexp? pls give me example
    • By therks
      I'm looking for a regex genius, cus I'm stumped when it comes to assertions.
      So what I have now, is this regular expression: ([^|=]+)=([^|]+)
      It takes a string (user input) of keys=values separated by pipes (ie: "param=value|param=value") and splits them into an array.
      Example:
      $vParamData = 'example=value|fruit=apple|phrase=Hello world' $aRegEx = StringRegExp($vParamData, '([^|=]+)=([^|]+)', 3) ; Result ; [0] => example ; [1] => value ; [2] => fruit ; [3] => apple ; [4] => phrase ; [5] => Hello world So that's working fine, but I'm wondering if there's also a way I could have this capture escaped pipes instead of splitting by them.
      ie:
      $vParamData = 'pipe test=this \| is a pipe|example=value' $aRegEx = StringRegExp($vParamData, '([^|=]+)=([^|]+)', 3) ; I'm getting this: ; [0] => pipe test ; [1] => this \ ; [2] => example ; [3] => value ; But I'd like a result like this: ; [0] => pipe test ; [1] => this \| is a pipe ; [2] => example ; [3] => value Is there some pattern that would accomplish this, or am I better off parsing it some other way?
×
×
  • Create New...