Um das zu...
26.06.2025 12:17:26
Case
Moin Christian, :-)
... präzisieren: ;-)
Die Gesamtzeit wird ausgelesen. Dann möchten wir es aber in einem bestimmten Aussehen haben. Also nutzen wir z. B. "INT()" (das nimmt wohl auch der Explorer - hier wird auf die nächste kleinere Zahl abgerundet). ;-)
https://support.microsoft.com/de-de/office/ganzzahl-funktion-a6c4af9e-356d-4369-ab6a-cb1fd9d343ef
Hier ein paar Möglichkeiten: ;-)
Option Explicit
Public Sub Main_1()
Dim dblDuration As Double
Dim strPath As String
strPath = "C:\Temp\Filme\Benni_4.mp4"
dblDuration = fncVidDuration(strPath)
Debug.Print "Dauer in Sekunden: " & dblDuration
Debug.Print "Dauer mit Millisekunden: " & fncMilli(dblDuration)
End Sub
Private Function fncVidDuration(strFilePath As String) As Double
Dim strCommand As String
Dim objExec As Object
Dim strPath As String
Dim objWSH As Object
Dim strOut As String
strPath = "C:\Temp\ffprobe.exe"
strCommand = """" & strPath & """ -v error -hide_banner -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 """ & strFilePath & """"
Set objWSH = CreateObject("WScript.Shell")
Set objExec = objWSH.exec(strCommand)
Do While objExec.Status = 0
DoEvents
Loop
strOut = objExec.StdOut.ReadAll
If Trim(strOut) > "" Then
fncVidDuration = Val(strOut)
Else
fncVidDuration = 0
End If
End Function
Private Function fncMilli(dblSec As Double) As String
Dim dblRest As Double
dblRest = dblSec - Int(dblSec)
fncMilli = Format(Int(dblSec) \ 3600, "00") & ":" & Format((Int(dblSec) Mod 3600) \ 60, "00") & ":" & Format(Int(dblSec) Mod 60, "00") & "," & Format(Round(dblRest * 1000, 0), "000")
End Function
Public Sub Main_2()
Dim strCommand As String
Dim strFFProbe As String
Dim objExec As Object
Dim strPath As String
Dim objWSH As Object
Dim strOut As String
strFFProbe = "C:\Temp\ffprobe.exe"
strPath = "C:\Temp\Filme\Benni_4.mp4"
strCommand = """" & strFFProbe & """ -v quiet -print_format json -show_format -show_streams """ & strPath & """"
Set objWSH = CreateObject("WScript.Shell")
Set objExec = objWSH.exec(strCommand)
strOut = objExec.StdOut.ReadAll
Debug.Print strOut
End Sub
Public Sub Main_3()
Dim strDuaration As String
Dim strCommand As String
Dim strFFProbe As String
Dim varLines As Variant
Dim strHeight As String
Dim strCodec As String
Dim strWidth As String
Dim objExec As Object
Dim varTMP As Variant
Dim objWSH As Object
Dim strPath As String
Dim strOut As String
strFFProbe = "C:\Temp\ffprobe.exe"
strPath = "C:\Temp\Filme\Benni_4.mp4"
strCommand = """" & strFFProbe & """ -v quiet -print_format flat -show_format -show_streams """ & strPath & """"
Set objWSH = CreateObject("WScript.Shell")
Set objExec = objWSH.exec(strCommand)
strOut = objExec.StdOut.ReadAll
varLines = Split(strOut, vbLf)
For Each varTMP In varLines
If InStr(varTMP, "format.duration=") > 0 Then strDuaration = fncTrenn(varTMP)
If InStr(varTMP, "streams.stream.1.codec_name=") > 0 Then strCodec = fncTrenn(varTMP)
If InStr(varTMP, "streams.stream.1.width=") > 0 Then strWidth = fncTrenn(varTMP)
If InStr(varTMP, "streams.stream.1.height=") > 0 Then strHeight = fncTrenn(varTMP)
Next varTMP
Debug.Print "Dauer: " & strDuaration & vbLf & "Video-Codec: " & strCodec & vbLf & "Auflösung: " & strWidth & "x" & strHeight
End Sub
Private Function fncTrenn(ByVal strLine As String) As String
Dim varPart As Variant
varPart = Split(strLine, "=")
fncTrenn = Replace(varPart(1), """", "")
End Function
Ich denke du siehst, wo du anpassen musst. Habe jetzt immer nur eine Datei genommen, um es zu demonstrieren. Also du musst Dateiname , Dateipfad und den Pfad zur "ffprobe.exe" anpassen. ;-)
Ausgabe alles über Debug.Print im Direktbereich. ;-)
In Main_1 werden dir die Sekunden und mit Millisekunden ausgegeben. ;-)
In Main_2 wird der gesamte JSON-String der Videodatei ausgegeben. ;-)
Jetzt brauchst du noch einen JSON-Parser (oder du splittest es selber auf). ;-)
https://github.com/VBA-tools/VBA-JSON/blob/master/JsonConverter.bas
Es gibt aber für "ffprobe -v quiet -print_format json -show_format -show_streams "DeineVideoDatei.mp4"" noch andere Ausgabemöglichkeiten: ;-)
Als da wären JSON, XML, INI, CSV, FLAT. ;-)
Für eine schnelle Ausgabe ist FLAT vorgesehen. ;-)
Das siehst du in Main_3. ;-)
Hier wird die Dauer, der Codec und die Auflösung ausgegeben. ;-)
Servus
Case