-
Apr 20th, 2024, 05:05 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Reliably identify video files. Was: Video file GUIDs?
Hi everyone!
I use several of these in one of my projects in order to identify image files:
Code:
Const ImageFormatBMP As String = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}"
Const ImageFormatEMF As String = "{B96B3CAC-0728-11D3-9D7B-0000F81EF32E}"
But I need same for mp4, mov, avi, wmv.
Not sure if exists or where to find? Thanks as always .
EDIT: What I really need is a reliable way to identify video files without using FSO etc.....I'm thinking open the file in binary mode & read applicable header bytes. Thoughts appreciated!
Last edited by SomeYguy; Apr 20th, 2024 at 06:45 PM.
-
Apr 20th, 2024, 10:35 PM
#2
Thread Starter
Addicted Member
Re: [RESOLVED] Reliably identify video files. Was: Video file GUIDs?
Well, I decided to go simple and just read the file header. Here's what I came up with:
Code:
Dim d As Byte, s As Long, fI as long, st as string
fI = FreeFile
Open "C:\vids\ShakeItUp.mp4" For Binary As fI
For s = 5 To 8
Get fI, s, d
st = st & CStr(Hex(d))
Next s
Close fI
End Sub
'- mp4 = 5 to 8, 66747970
'- avi = 9 to 12, 41564920
This was just a quick throw together so not production code. Seems to work well!
Last edited by SomeYguy; Apr 20th, 2024 at 10:53 PM.
-
Apr 20th, 2024, 10:44 PM
#3
Re: [RESOLVED] Reliably identify video files. Was: Video file GUIDs?
GPT-4 gave me this:-
Code:
Private Sub IdentifyFileType(ByVal fileName As String)
Dim fileNumber As Integer
Dim header As String
Dim buffer As String
fileNumber = FreeFile ' Get a free file number
On Error GoTo ErrorHandler ' Error handling if file can't be opened
Open fileName For Binary As #fileNumber ' Open the file in binary mode
' Read the first 12 bytes from the file
header = Space$(12)
Get #fileNumber, , header
Close #fileNumber ' Close the file
' Check for PNG
If Left$(header, 8) = Chr$(137) & "PNG" & Chr$(13) & Chr$(10) & Chr$(26) & Chr$(10) Then
MsgBox fileName & " is a PNG file."
' Check for JPEG
ElseIf Left$(header, 3) = Chr$(255) & Chr$(216) & Chr$(255) Then
MsgBox fileName & " is a JPEG file."
' Check for GIF
ElseIf Left$(header, 3) = "GIF" Then
MsgBox fileName & " is a GIF file."
' Check for BMP
ElseIf Left$(header, 2) = "BM" Then
MsgBox fileName & " is a BMP file."
' Check for AVI
ElseIf Left$(header, 4) = "RIFF" And Mid$(header, 9, 4) = "AVI " Then
MsgBox fileName & " is an AVI file."
' Check for MP4
ElseIf Left$(header, 4) = Chr$(0) & Chr$(0) & Chr$(0) And _
(Mid$(header, 5, 8) = "ftypisom" Or Mid$(header, 5, 8) = "ftypmp42") Then
MsgBox fileName & " is an MP4 file."
Else
MsgBox "File type of " & fileName & " is unknown."
End If
Exit Sub
ErrorHandler:
MsgBox "Error opening file. Please check if the file exists and is accessible."
Close #fileNumber
End Sub
I'd recommend double checking that those header signatures as AIs tend to hallucinate. GPT-4 rarely screws up simple things like this but I'd double check it anyway.
I'd also recommend using ChrW instead of Chr. We live in a Unicode world now.
-
Apr 20th, 2024, 10:57 PM
#4
Thread Starter
Addicted Member
Re: [RESOLVED] Reliably identify video files. Was: Video file GUIDs?
Looks better than what I came up with as far as reading the needed bytes. I'll try it along with your recommendations, thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|