I need to be able to get images of QuickLook previews of video files.
Getting the QuickLook image is simple enough using the MBS plugins. However, I need to do additional processing to the various files BEFORE I get the QuickLook preview and would like to like to save this processing time if the file is not actually a viewable video file.
I used to be able to use FolderItem.IsMovieFileMBS back when QuickTime was still supported, but that is obviously no longer an option.
I’m looking to see if anyone has a reliable and inexpensive (in terms of processing cycles) method for determining if a file is viewable video file. The only method of doing this that I can think of at the moment is:
[code]Dim m as Movie
// Assume f is already a non-Nil FolderItem that exists
m = f.OpenAsMovie
if not( m = Nil ) then
// f is a Video file
// f is not a Video file
This method is not only expensive in terms of processing time, it is also not reliable. I will end up with files that f.OpenAsMovie will return a not-Nil Movie, but I cannot get a QuickLook preview of them and they won’t play. These usually tend to be older QuickTime movies that might play in QuickTime Player (after QuickTime Player converts them), but frequently even QuickTime Player can’t handle them.
I hope this makes sense. This is one of those things that makes a ton of sense in my head, but I’m having trouble describing what I need when I write it out.
Thank you in advance for any assistance anyone might be able to provide.
[code]dim f as FolderItem
dim extension as string
if f <> nil and f.Exists then
extension = NthField(f.name, “.”,CountFields(f.name,"."))
if extension = “mp4” or extension = “mov” then
m = f.OpenAsMovie
or extension = “xxx”
Thank you Axel!
Unfortunately, there could be a great number of video files that Mac OS X can show and not as much consistency in the file extension as one might expect. I was hoping for something a bit more generic. I have no idea what files a user may throw at my application that may be a valid video file, but not have a known extension.
I can’t imagine that the system is only looking at the extension here.
On OSX, try the
file command. It does not rely on extensions.
I use a slight variation of your expensive method: a function more or less like,
return m <> nil and m.movieHeight > 2 and m.movieWidth > 2
I am not sure what you are trying to describe here. Could you clarify?
[quote=241727:@Carlo Rubini]I use a slight variation of your expensive method: a function more or less like,
return m <> nil and m.movieHeight > 2 and m.movieWidth > 2[/quote]
The problem that I’m seeing with this is that I still get files that pass these tests, but still aren’t viewable videos (usually older QuickTime movies that Mac OS X can no longer open).
Why not load the file in an off-window MoviePlayer, set volume to zero, Play and check for Duration. Then Stop.
If Duration = zero, then the file is not playable.
file is a command line tool (OSX & Linux)
dim sh as new shell
sh.Execute "file " + f.ShellPath
I ended up processing everything (that has to do with videos) with ffmpeg using async Shells. Initially, I tried to avoid it because I thought it was too expensive but the processing happens on multiple cores and, to my surprise, it works pretty well.
Before processing, I read/check video properties with ffprobe.
During this ffprobe check, I also make a unique hash of the video file (first and last 64KB) and start a thread that fetches the Metadata. Benchmarking showed me that this whole process of shelling out and processing the result takes ~200ms but I run 32 concurrently so it flies through the list pretty fast.
Maybe an idea.
FFMPEG: be careful: https://www.cvedetails.com/cve/CVE-2016-1897/
The original question is nearly unsolvable, because there is no such thing as a “video file” - modern video file formats such as MP4 and MOV are container files that can contain any number of different video (and audio) codecs.
There are plenty of MOV files for example that used to play fine under 10.6, and won’t play at all under 10.11. I also have some that will play under QuickTime Player 7, but not QuickTime Player X.
You could check the UTType via declares and see if it conforms to “public.movie”.
[code]Function isMovie(f as folderitem) As boolean
#if TargetCocoa then
declare function NSClassFromString lib “Foundation” ( aClassName as CFStringRef ) as Ptr
declare function sharedWorkspace lib “AppKit” selector “sharedWorkspace” ( NSWorkspaceClass as Ptr ) as Ptr
declare function typeOfFile lib “AppKit” selector “typeOfFile:error:” ( NSWorkspace as Ptr, absoluteFilePath as CFStringRef, error as Ptr ) as CFStringRef
declare function typeconformsToType lib “AppKit” selector “type:conformsToType:” ( NSWorkspace as Ptr, firstTypeName as CFStringRef, secondTypeName as CFStringRef) as boolean
Dim error as Ptr
Dim fileUTType as string = typeOFFile( sharedWorkspace( NSClassFromString( "NSWorkspace" ) ), f.nativePath, error )
if error <> nil then
// --- There was an error, so we log it.
Declare function description lib "Foundation" selector "description" ( ID as Ptr ) as CFStringRef
System.DebugLog currentmethodName + " failed to get file type: " + description( error )
return typeConformsToType( sharedWorkspace( NSClassFromString( "NSWorkspace" ) ), fileUTType, "public.movie" )
Thank you Sam!
Unfortunately, the code you posted doesn’t seem to do what I need it to. For example, some of these files may be .wmv files. Yes, they are video files, but they are not video files that Mac OS X can natively handle. Therefore, I need them to be ignored.
[quote=241736:@Michael Diehr]The original question is nearly unsolvable, because there is no such thing as a “video file” - modern video file formats such as MP4 and MOV are container files that can contain any number of different video (and audio) codecs.
There are plenty of MOV files for example that used to play fine under 10.6, and won’t play at all under 10.11. I also have some that will play under QuickTime Player 7, but not QuickTime Player X.[/quote]
I understand what you are saying Michael. But, how does Mac OS X decide if a file can be shown?
I think I may just have to resort to getting the QuickLook preview before processing the file. That will be more expensive, but hopefully more reliable than what I am doing now.
The one & only true way to know
I’d bet it tries to open it and play it as a movie type and finds theres no video tracks or none that it can access (think wmv’s here) and so doesn’t show it
Just tested the
file command on a sample WMV…
[quote]MacPro-2009:Downloads$ file DLP_PART_2_768k.wmv
DLP_PART_2_768k.wmv: Microsoft ASF[/quote]
I don’t know if the return value “Microsoft ASF” is of any value to you. And it works with/without a
Just like shoes, by trying them on. Exactly the method I suggested above
With MBS Plugins just two lines:
[code] dim f as FolderItem = SpecialFolder.Desktop.Child(“Import.avi”)
dim u as string = UTTypeMBS.UTI(f)
if UTTypeMBS.ConformsTo(u, “public.movie”) then
MsgBox u+" is movie"
MsgBox u+" is not movie."
end if [/code]
Sorry I am just getting back to this. I was unexpectedly traveling for business and have not had time to work on this for the past week or so.
Christian - Your code shows the same problem as Sam’s code above. It shows some filetypes as movies that cannot be opened by Mac OS X. I need a solution that will only allow what Mac OS X can actually open.
For example: Mac OS X can natively open most .mp4 files. No problem there. Mac OS X cannot natively open a .wmv file, so that file should be ignored. However, if the user has installed software that allows Mac OS X to “natively” open a .wmv file, then it should not ignore .wmv files.
So far, the best solution I’ve found (although not perfect) is to look to see if I can get a valid QuickLook preview from the file.
If quicklook returns something useful, then I wouls suggest using it as a second step (especially as it can return something useful for a spreadsheet). Start by using the UTI to see if the OS thinks it’s a movie, then use Quicklook to see if it’s a movie that the OS can play.
For example: Mac OS X can natively open most .mp4 files. No problem there. Mac OS X cannot natively open a .wmv file, so that file should be ignored. However, if the user has installed software that allows Mac OS X to “natively” open a .wmv file, then it should not ignore .wmv files.[/quote]
Duration will tell you immediately.