8 Replies - 13219 Views - Last Post: 29 March 2010 - 08:49 AM Rate Topic: -----

#1 Guest_Schmit38*


Reputation:

How can I get .AVI header info without playing file?

Posted 18 March 2010 - 08:24 AM

I have been working off and on for a year on my own media browser that I created in VB.NET. My program will play MP3 playlists as well as supporting drag and drop

Getting fileinfo of an mp3 is no problem but I have discovered that it is more complex when I try to get file duration of video files (.avi,.mpg) etc.

My code listed below uses a timer. In order for me to get a video duration value, I must actually play the file in axwindowsmediaplayer1 for one second. This seems not practical.

I have seen many examples on the internet in C# that read video metadata without need to play/load the file. Why are there no examples in vb.net of this? Is it too difficult to achieve in vb.net?


Imports System.IO

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ofd1.InitialDirectory = "D:\Howard Stern\Video\HTVOD - 50 Cent & G-Unit - 2003 [WDM]"
        ofd1.ShowDialog()

        Dim filepath As String = ofd1.FileName
        '  MsgBox(filepath)
        AxWindowsMediaPlayer1.URL = filepath
        AxWindowsMediaPlayer1.Ctlcontrols.play()

        ' AxWindowsMediaPlayer1.Ctlcontrols.stop()
        'getinfo()
       
        Timer1.Enabled = True
    End Sub
    Function ConvertTime(ByVal TheTime As Integer)
        ' Converts Windows Media Player (AxWMP Component)  
        ' Default Play Time in Milliseconds to either: (00:00) MM:SS (Minutes:Seconds) 
        ' or HH:MM:SS (00:00:00) (Hours:Minutes:Seconds) 

        On Error Resume Next

        Dim NewTime As String
        Dim Sec As Single
        Dim min As Single
        Dim h As Single
        Dim a As String = ""
        If TheTime = 60 Then
            ConvertTime = "1:00"
            Exit Function
        End If
        If TheTime > 60 Then
            Sec = TheTime
            min = Sec / 60
            min = Int(min)
            Sec = Sec - min * 60
            h = min / 60
            h = Int(h)
            min = min - h * 60
            'If your current time in Seconds is less than 10 then designate a 0 prior to the single digit second - Prevents you from showing 0:1 as opposed to 0:01. 
            If Sec < 10 Then
                a = "0"
            End If
            'edit this line to add Hours(HH:MM:SS) if you would like 
            ConvertTime = String.Format("{0}:{1}{2}", min, a, Sec)
        End If

        If TheTime < 60 Then
            Sec = TheTime
            min = Sec / 60
            min = Int(min)
            Sec = Sec - min * 60
            h = min / 60
            h = Int(h)
            min = min - h * 60
            If Sec < 10 Then
                a = "0"
            End If
            ConvertTime = String.Format("{0}:{1}{2}", min, a, Sec)
        End If
    End Function
    Sub getinfo()
        lblTotalTime.Text = ConvertTime(AxWindowsMediaPlayer1.Ctlcontrols.currentItem.duration)
    End Sub
    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'Get the duration of the avi file here while it is playing
        lblTotalTime.Text = ConvertTime(AxWindowsMediaPlayer1.Ctlcontrols.currentItem.duration)
        lblCurrentTime.Text = ConvertTime(AxWindowsMediaPlayer1.Ctlcontrols.currentPosition)
        AxWindowsMediaPlayer1.Ctlcontrols.stop()
    End Sub
End Class


Is This A Good Question/Topic? 0

Replies To: How can I get .AVI header info without playing file?

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How can I get .AVI header info without playing file?

Posted 18 March 2010 - 09:34 AM

The VB.NET Programmers forum isnt for asking for programming help, it's for discussion of more advanced topics. For that reason I'm moving this to the VB.NET forum :)
Was This Post Helpful? 0
  • +
  • -

#3 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: How can I get .AVI header info without playing file?

Posted 18 March 2010 - 09:47 AM

You could always just wrap FFMPEG.
Was This Post Helpful? 0
  • +
  • -

#4 Guest_Schmit38*


Reputation:

Re: How can I get .AVI header info without playing file?

Posted 19 March 2010 - 09:52 AM

I looked at the documentation for FFMPEG. It is in the "C" language. Maybe its time to learn C# because I am finding out that most programs that do anything meaningful seem to be in C or C#. I can't believe there is nothing I can google that will show me an example of this problem in vb.net. Any more hints anyone?

How can I use C programs in tandem with vb.net?
Was This Post Helpful? 0

#5 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: How can I get .AVI header info without playing file?

Posted 19 March 2010 - 12:41 PM

Yes you should learn C#, almost all C# can be directly converted to VB.Net and its nice to be able to switch between the two should the situation call for it.

Any console program (not just those written in C) can be wrapped in a Process object and the output can be read using a streamreader.

I've written several small apps that wrap FFMPEG for one purpose or the other. Heres an example of how to get video information


Dim piTask As New ProcessStartInfo(My.MySettings.Default.strFFMPEGExePath) With {.UseShellExecute = False, .WindowStyle = ProcessWindowStyle.Hidden, .CreateNoWindow = True, .RedirectStandardError = True}
        piTask.Arguments = "-i " & Chr(34) & sVideoFilePath & Chr(34) ' -i flag tells FFMPEG to output file information, Chr(34) is a " '
        Dim prcTask As New Process() With {.StartInfo = piTask}
        prcTask.Start()

        prcTask.WaitForExit(-1)

        Dim sr As StreamReader = prcTask.StandardError
        Dim lsOutput As New List(Of String)
        'read the output lines into a list so we can mess about with them
        'this adds a little overhead but makes working with the FFMPEG output easier.
        Do Until sr.EndOfStream
            lsOutput.Add(sr.ReadLine())
        Loop
        sr.Close()
        prcTask.Close()
        Dim strOutput() As String = lsOutput.ToArray()
        Dim strToRead(2) As String
        '13 14 15 are the interesting lines.
        strToRead(0) = strOutput(13)
        strToRead(1) = strOutput(14)
        strToRead(2) = strOutput(15)


Was This Post Helpful? 0
  • +
  • -

#6 Guest_Schmit38*


Reputation:

Re: How can I get .AVI header info without playing file?

Posted 20 March 2010 - 10:35 AM

Thank You so much for your help!

I have one question though..

line #8: "(My.MySettings.Default.strFFMPEGExePath)" has the error code

that says: strFFMPEGExePath is not a member of FFMPEG.My.MySettings

I included system.io but am I to include something else here as well?


Imports System.IO

Public Class Form1

   'This is the file I am using as the source for FFMPEG testing

    Dim sVideoFilePath As String = "C:\test.avi"


    Private Sub btnGetInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetInfo.Click
        Dim piTask As New ProcessStartInfo(My.MySettings.Default.strFFMPEGExePath) With {.UseShellExecute = False, .WindowStyle = ProcessWindowStyle.Hidden, .CreateNoWindow = True, .RedirectStandardError = True}
        piTask.Arguments = "-i " & Chr(34) & sVideoFilePath & Chr(34) ' -i flag tells FFMPEG to output file information, Chr(34) is a " ' 
        Dim prcTask As New Process() With {.StartInfo = piTask}
        prcTask.Start()

        prcTask.WaitForExit(-1)

        Dim sr As StreamReader = prcTask.StandardError
        Dim lsOutput As New List(Of String)
        'read the output lines into a list so we can mess about with them 
        'this adds a little overhead but makes working with the FFMPEG output easier. 
        Do Until sr.EndOfStream
            lsOutput.Add(sr.ReadLine())
        Loop
        sr.Close()
        prcTask.Close()
        Dim strOutput() As String = lsOutput.ToArray()
        Dim strToRead(2) As String
        '13 14 15 are the interesting lines. 
        strToRead(0) = strOutput(13)
        strToRead(1) = strOutput(14)
        strToRead(2) = strOutput(15)
    End Sub
End Class


Was This Post Helpful? 0

#7 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: How can I get .AVI header info without playing file?

Posted 22 March 2010 - 05:49 AM

Replace My.MySettings.Default.strFFMPEGExePath with the path of the FFMPEG exe.
Was This Post Helpful? 0
  • +
  • -

#8 Guest_schmit38*


Reputation:

Re: How can I get .AVI header info without playing file?

Posted 26 March 2010 - 08:35 PM

Ok, So the past week or so I have been scratching my head trying to figure out how to run FFMPEG. My question is:

1) Do I need to be running AMP programming to use FFMPEG? You know.. like Apache, MySql, Php

2) Can I just put FFMPEG in any directory in my HDD and then point to the .exe to get an .avi file duration?

3) Why is it so difficult to find info on google about this topic. There are no snippets out there.

4) In windows explorer I am able to get length of video files without playing them. How does windows get this info?

Once again..to review... I am working on a multimedia player app.. It lists directories in list view's where you then can print out mp3 lists to a text file. I want to be able to do the same with video files.

I am so bummed out.. I would trade anything in the world to learn this more advanced stuff....Thank You...
Was This Post Helpful? 0

#9 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: How can I get .AVI header info without playing file?

Posted 29 March 2010 - 08:49 AM

View Postschmit38, on 26 March 2010 - 09:35 PM, said:

Ok, So the past week or so I have been scratching my head trying to figure out how to run FFMPEG. My question is:

1) Do I need to be running AMP programming to use FFMPEG? You know.. like Apache, MySql, Php

2) Can I just put FFMPEG in any directory in my HDD and then point to the .exe to get an .avi file duration?

3) Why is it so difficult to find info on google about this topic. There are no snippets out there.

4) In windows explorer I am able to get length of video files without playing them. How does windows get this info?

Once again..to review... I am working on a multimedia player app.. It lists directories in list view's where you then can print out mp3 lists to a text file. I want to be able to do the same with video files.

I am so bummed out.. I would trade anything in the world to learn this more advanced stuff....Thank You...


1: No, FFMPEG is a plain old console app written in C.

2: Yes.

3: No idea.

4: They probably have libraries that can read the data directly.



Wrapping FFMPEG in a process object is kind of annoying, I only suggested using it because it would give you a good excuse to become familiar with the Process class. If its too much of a struggle you may want to consider using the Windows Media Player SDK. The SDK has some neat libraries that make getting file metadata a snap.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1