locked
Get frames from video RRS feed

  • Question

  • How can i get frame from a video file in vb.net
    Wednesday, October 23, 2013 3:14 PM

Answers

All replies

  • Hi,

     You can check out this LINK. I have not tried it out so i can`t tell you if it will do what you want or not. If not you could also use FFMPEG to save frames of a video as pictures. If you want to try it you can download FFMPEG HERE. Then you can try this example by creating a new Form project and adding 1 AxWindowsMediaPlayer control and 2 Buttons. Name 1 Button "Button_SaveFrame" and the other as "Button_Open". Then use the code below.

     You will need to look in the unzipped FFMPEG folder that you downloaded and find the "ffmpeg.exe" file. Copy it to the folder you want to use for it. I copied it to the Debug folder in my vb project folder, so if you copy it elsewhere then you will need to change the ffmpegPath variable at the top of the code to the path you put it in.

    Public Class Form1
        Dim ffmpegPath As String = IO.Path.Combine(Application.StartupPath, "ffmpeg.exe")
        Dim OpenedVideo As String = ""
        Dim WithEvents proc As New Process
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            proc.StartInfo.UseShellExecute = False
            proc.StartInfo.CreateNoWindow = True
            proc.StartInfo.FileName = ffmpegPath
        End Sub
    
        Private Sub Button_Open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Open.Click
            Dim ofd As New OpenFileDialog
            ofd.Title = "Open A Video..."
            ofd.Filter = "Video Files|*.avi;*.flv;*.mp4"
            ofd.Multiselect = False
            If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                OpenedVideo = ofd.FileName
                AxWindowsMediaPlayer1.URL = OpenedVideo
            End If
        End Sub
    
        Private Sub Button_SaveFrame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_SaveFrame.Click
            Dim FrameTime As Double = AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
            Dim SaveAs As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "Picture_" & FrameTime.ToString.Replace(".", "-") & ".jpg")
            proc.StartInfo.Arguments = "-ss " & FrameTime.ToString & " -i " & Chr(34) & OpenedVideo & Chr(34) & " -vframes 1 -f image2 " & Chr(34) & SaveAs & Chr(34)
            proc.Start()
        End Sub
    End Class

     FFMPEG comes with help documents that will explain the different arguments you can use and the net has a bunch of examples for using it. You may want to look threw the help documents because, you can do other things such as changing the size of the image when saving it or saving several frames in a row.


    • Edited by IronRazerz Wednesday, October 23, 2013 7:15 PM
    • Proposed as answer by Frank L. Smith Wednesday, October 23, 2013 7:42 PM
    Wednesday, October 23, 2013 6:36 PM
  • How can i get frame from a video file in vb.net

    What do you want just an image of the frame or do you want all of the information such as audio with it?

    I'm creating a program that will allow you to get an image from Windows Media Player that I will provide here tomorrow sometime. But it's just an image with no other info. Like the one below from an old Apollo 16 video. You can select what area of the image you desire to get also.


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.



    • Edited by Mr. Monkeyboy Thursday, October 24, 2013 4:13 AM 5555
    Thursday, October 24, 2013 4:00 AM
  • Thanks for your help .

    But I want to make a video player without using any components !

    • Proposed as answer by jier Monday, July 8, 2019 2:17 AM
    Thursday, October 24, 2013 9:53 AM
  • Thanks for your help .

    But I want to make a video player without using any components !


     I am confused on what you mean. Are we on the rite track that you want to try to capture frames from a video and save them as images on the hard drive? If not then could you explain a little more about what your trying to do. I am not positive but, if you want to save frames as images then your probably going to need to use some kind of component such as the C# wrapper from CodeProject, FFMPEG, or even MPlayer from this LINK. However, maybe someone has another way to do it that i have not figured out yet.   :)
    Thursday, October 24, 2013 11:26 AM

  • But I want to make a video player without using any components !


    How many month or years do you want to spend on it? Note that even if you are capable of doing it, you will probably hunt for good documentation in this area.

    Armin

    • Proposed as answer by Mr. Monkeyboy Thursday, October 24, 2013 12:46 PM
    Thursday, October 24, 2013 12:19 PM
  • Thanks for your help .

    But I want to make a video player without using any components !


    I wish you had mentioned that in your original question. Grabbing a frame from a video will not accomplish that task.

    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Thursday, October 24, 2013 12:36 PM
  • Maybe these links will help although the media player is not pure code as you're using the MCI API (I believe) to accomplish the task.

    Media Control Interface

    About MCI

    Using MCI Command Strings

    Using MCI Command Messages

    MCI Reference

    A thread on "Win32 MCI Api for playing media"


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Thursday, October 24, 2013 12:46 PM
  • Maybe this is also a starting point:

    DirectShow Samples

    "DShowplayer" example looks promising.


    Armin

    Thursday, October 24, 2013 1:43 PM
  • sir, I'm a newbie, and I try your code above.. but it's doesn't work.. can you help me to fix it?
    Sunday, April 19, 2015 7:11 PM
  • sir, I'm a newbie, and I try your code above.. but it's doesn't work.. can you help me to fix it?

     Please start your own new question and post your code. You will also need to explain what is not working and show any error messages that you are getting.

    If you say it can`t be done then i`ll try it

    Sunday, April 19, 2015 7:41 PM