Using Mediaplayer to get video details

Hi,

My old software for obtaining the duration of a video (below) was written in Visual Basic and is in need of replacing…

While I had Real Basic back in 2009, I have just started developing in XOJO 2015, having seen Mediaplayer in the docs…

However, on further inspection, it appears that I need to play the video in a window in order to obtain the details.

My question is, does anyone know how to avoid this? It was not necessary in VB!

My VB code is below, if anyone can help me it would be greatly appreciated.

Thanks,
Richard Gamester

'
' Get Video Details
'
'Get an object on the filter graph manager
Set MediaControl = New FilgraphManager
' Get the various controls
Set MediaPosition = MediaControl
Set BasicVideo2 = MediaControl
'
On Error Resume Next
MediaControl.RenderFile Fl.Path
rc& = Err.Number
Msg$ = Err.Description
On Error GoTo 0
'
If rc& = 0 Then
  '
  Do ' Wait for RenderFile to complete
    On Error Resume Next
    Err.Clear
    MediaControl.GetState 200, rc&
    rc& = Err.Number
    On Error GoTo 0
  Loop While rc& <> 0
  '
  If UCase(Typ$) = "MP3" Then
    ' No video content...
    Wide% = 0
    High% = 0
  Else
    '
    ' A video may render, but have problems so not be
    ' playable until edited. This causes the get width to fail,
    ' so we check this first...
    '
    On Error Resume Next
    Wide% = BasicVideo2.SourceWidth    ' Video width 720 or 704
    High% = BasicVideo2.SourceHeight
    If Typ$ <> "JPG" Then
      Frames = BasicVideo2.AvgTimePerFrame
      If Frames > 0 Then Frames = 1 / Frames
      Frames = Round(Frames, 1)
    End If
    rc& = Err.Number
    Msg$ = Err.Description
    On Error GoTo 0
  End If
End If
'

Indeed you need to play, but it can be extremely brief.

I placed that in the Play event of a MoviePlayer :

system.DebugLog str(me.Duration) me.Stop

All I need to do is to set the movie property, and go MoviePlayer1.Play to obtain the duration.

More interesting, it works with the MoviePlayer set as invisible.

I use mdls in OSX to get the movie duration (mpeg, mp4)

dim f as FolderItem = GetFolderItem ("xxxxxx", FolderItem.PathTypeNative) If f <> Nil And f.Exists Then dim sh as new shell sh.execute "mdls -name kMDItemDurationSeconds '" + f.NativePath + "' | cut -d ""="" -f 2" dim length as double = val(sh.Result) MsgBox str(floor(length)) // length in Seconds End If

I believe as the OP mentions VB, he is using Windows.

While a Mac declare is always good, the method I describe works cross platform.

Many thanks guys, really appreciated!
… and yes it’s Windoze. I have a large video library and this code is part of the index update process.

Ok, I now have a Movie Player that works, and can get the duration - Thank You!

Out of interest, does anyone know how to get the width & height of the movie?

I’ve tried Player.Movie.MoveiWidth and Player.Movie.BaseWidth and I have even installed Quicktime
as mentioned in the documentation, but I still get zeros.

I also tried AutoResize, but that appears to have no affect.

As before, this is on Windows.

Thanks.

Maybe using ffprobe is an option?

Someone has posted a method here :
http://superuser.com/questions/841235/ffmpeg-get-video-resolution

Not too sure it works out of the box for Windows, but you can also look at http://ffmpeg.org/ffprobe.html for help.

ffprobe -v quiet -select_streams v:0 -show_entries stream=width,height,avg_frame_rate,nb_frames -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 video.xyz

…gives you nicely formatted output that you can parse.

Yes, I did look at ffprobe using the command line prompt and it works well.
But I could not work out how to save the console output and there is no save option.

I assume I have to build the command line and call Shell, with the console saved somehow.
I then just wait for completion (no problem with that) and then parse the result.

Unfortunately the consol bit is beyond me at present…

[quote=224140:@Richard Gamester]Yes, I did look at ffprobe using the command line prompt and it works well.
But I could not work out how to save the console output and there is no save option.

I assume I have to build the command line and call Shell, with the console saved somehow.
I then just wait for completion (no problem with that) and then parse the result.

Unfortunately the consol bit is beyond me at present…[/quote]

Use a synchronous shell with the same kind of command line, except you need to point the whole path to ffprobe. Then you get the result in the Shell.Result string property.

See http://documentation.xojo.com/index.php/shell

Wow that was fast!

Thank you Michel, simple when you know how…

I have used ShellExecute in another project that controls TV recording software, but never looked at Shell.
Ah well you learn something new every day, even when you’re 70!

Many many thanks to everyone who has helped me.

Richard

You’re welcome. Congratulations.