Jump to content

stringregexp question/help


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

Link to comment
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")

 

Link to comment
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
Link to comment
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)

 

Link to comment
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
Link to comment
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
Link to comment
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")

 

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

Link to comment
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
 Share

×
×
  • Create New...