Still image capture from a video file. (1 Viewer)

Sac

Member
Local time
Today, 17:52
Joined
Feb 28, 2020
Messages
48
Hi All,

I was reading in the forum and came a cross how to take a picture from a webcam and store the pic path in the db. I would like to take pics from a video file and store the path in the db. Currently, I take the picture from the video file using VLC video player and store it in a folder. I can display the video file in a form but I need help on writing a code to have a buttom to take a picture.
If anybody can lead me into the right direction in how to capture images from video would be great,

Sincerely,

Sac
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:52
Joined
May 7, 2009
Messages
19,237
add reference to your vlc object in code

Dim player As Object
Set player = VLCPlugin20.Object

on click event of Snapshot button:

player.video.takeSnapshot()

this will save the snapshot to desktop. you need to Move /Copy
the image elsewhere you want.
 

Sac

Member
Local time
Today, 17:52
Joined
Feb 28, 2020
Messages
48
Arnelgp,

Thank you So much!! I wil give it a try and post my results.

Sincerely,

Sac.
 

Sac

Member
Local time
Today, 17:52
Joined
Feb 28, 2020
Messages
48
I came up with the following code that will play the video where its path is passes in the Form_Load() event. And a buttom when you click, it takes the still image and stores it in the documents folder.
I would like to know how do I rename the pic file and store the path in a table field. From there, I can read the files through a loop and display them in a form.
I like like to thank you for your help. I just started to code and I have learned quite a bit thanks to this forum!

I have the code as follows:

Code:
Private Sub Detail_Click()
Dim player As AXVLC.VLCPlugin2
Set player = Me.VLCPlugin24.Object
player.video.takeSnapshot
End Sub

Private Sub Form_Load()
Dim player As AXVLC.VLCPlugin2

    Set player = Me.VLCPlugin24.Object 
    Dim strURL As String
    strURL = "File:///C:\Users\cctvi\Desktop\report\117-SAN109.mpg"
   
    player.Playlist.Add strURL
    player.Playlist.play
End Sub
 
Last edited by a moderator:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:52
Joined
May 7, 2009
Messages
19,237
you can pause for a moment and ask for the filename.
take the snapshot and rename it
save (insert the filepath+filename) to table.
Code:
Private Sub Detail_Click()
Dim player As AXVLC.VLCPlugin2
Dim sNewFile As String, sSnapFile
Set player = Me.VLCPlugin24.Object
With player
    .playlist.pause
    sNewFile = InputBox("Type the new Name of the snapshot." & vbcrlf & _
        "(do not add Extension. Bmp is the default)","New snapshot"))
    If sNewFile <> "" Then
        player.video.takeSnapshot
        sSnapFile = Dir("C:\Users\cctvi\Desktop\report\*.bmp")
        While sSnapFile = ""
            sSnapFile = Dir("C:\Users\cctvi\Desktop\report\*.bmp")
        Wend
        Name ("C:\Users\cctvi\Desktop\report\" & sSnapFile) As ("C:\Users\cctvi\Desktop\report\" & sNewFile & ".bmp")
        ' save to table
        Currentdb.Execute "Insert Into yourTableHere (theFieldNameHere) " & _
            "Select '" & "C:\Users\cctvi\Desktop\report\" & sNewFile & ".bmp" & "'"
    End If
    .playlist.togglePause
End With
End Sub
 

Sac

Member
Local time
Today, 17:52
Joined
Feb 28, 2020
Messages
48
arnelgp,

Thanks again for taking the time to help me!! I will post my result once I finish.

Cheers,

Sac
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:52
Joined
May 7, 2009
Messages
19,237
without seeing your db, its very hard to guess what is going on inside.
if you can upload a strip-down version of your db (maybe with 2 records).
 

Sac

Member
Local time
Today, 17:52
Joined
Feb 28, 2020
Messages
48
arnelgp,

Attached is the db I am working on. Lots of mistakes there. Hopefully with time, I will do better.
There are 5 tables: Asset, Inspection, Code, Project And observations. The tables relationships are one to many.
Every form has a subform that display the record that you enter through the form and be able to see the record if I make a mistake. If you do, you do, click on the subform record and click edit to edit the form. The form populates the record data so that you can make the change in the form.
From the AddInspection form, I fill the inspection details and select the project and asset that I am going to inspect. From there, I pass the inspectionID, Asst ID , Project ID and Project Name. To the AddObservation form. In the observation form, I code the pipe. Once I code the pipe, I create the report and picture report template. And then send them to print to pdf files.
The problem I have is that when I create the first observation and refresh the subform, the observation I just created appears. I then take the picture from the video and the table field picpath updates with the picture path. When I do the second observation. The picture does not update the picpath. I have to close the AddObservation form upload it again. And go back to where I was in the inspection. Ideally, I would like to take the picture without renaming, just click and insert so that I can focus in the inspection.
I hope you understand what I am trying to explain and do.

arnelgp, thank you for taking the time to help me!

Sac
 

Attachments

  • DB-PipeCodingTool.zip
    2.6 MB · Views: 417
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:52
Joined
May 7, 2009
Messages
19,237
update your code on "take snapshot"
Code:
Private Sub cmdSnapShot_Click()

Const pic_path As String = "C:\Users\cctvi\OneDrive\Documents\"

Dim player As AXVLC.VLCPlugin2
Dim sNewFile As String, sSnapFile
Set player = Me.VLCPlugin27.Object

 With player
 .Playlist.pause
  Debug.Print Me.frmObservationSub.Form.Recordset.Fields("OBSERVATIONID")
  sNewFile = InputBox("Type the new Name of the snapshot." & vbCrLf & _
                "(do not add Extension. Bmp is the default)", "New snapshot")
            If sNewFile <> "" Then
               player.video.takeSnapshot
                    sSnapFile = Dir(pic_path & "*.bmp")
                    While sSnapFile = ""
                        sSnapFile = Dir(picpath & "*.bmp")
                    Wend
                    Name (pic_path & sSnapFile) As (pic_path & sNewFile & ".bmp")
                    ' save to table
                  
                   '  CurrentDb.Execute "UPDATE OBSERVATION " & _
                   ' " SET PICTUREPATH='" & "C:\Users\cctvi\OneDrive\Documents\" & sNewFile & ".bmp" & "'" & _
                   '  " WHERE OBSERVATIONID=" & Me.frmObservationSub.Form.Recordset.Fields("OBSERVATIONID") & " AND DESCRIPTION IS NOT NULL"
              
                    ' dont save yet, just assign it to Me.txtPicturePath
                    Me.txtPicturePath = pic_path & sNewFile & ".bmp"
       End If
      
    .Playlist.togglePause
    End With
      
 
    
End Sub
 

Sac

Member
Local time
Today, 17:52
Joined
Feb 28, 2020
Messages
48
Good Morning Arnelgp,
I wanted to insert the pic into the db without renaming it as it takes more time when doing a lot of inspections. Also, when I name the file as the previous by mistake using the Inbox, all files get renamed and the picture assigned to the record changes. So I changed the code a little bit. I used the Now and Format functions to pass a unique string to the string variable sNewFile. ---> sNewFile = Format(Now(), "ddmmyyhhmmss") . It generates a different name every time I insert it to the database via the form. However, when I compare the file names inserted in the DB to the bmp files created by the VLC ActiveX control in the documents folder, only the first name matches.

What Am I doing wrong? Below is the code.
Thank you! SAC.

Code:
Private Sub cmdSnapShot_Click()

Const pic_path As String = "C:\Users\sac\OneDrive\Documents\"

Dim player As AXVLC.VLCPlugin2
Dim sNewFile As String, sSnapFile
Set player = Me.VLCPlugin27.Object

With player
.Playlist.pause

' sNewFile = InputBox("Type the new Name of the snapshot." & vbCrLf & _
  '              "(do not add Extension. Bmp is the default)", "New snapshot")
   
        sNewFile = Format(Now(), "ddmmyyhhmmss")
        If sNewFile <> "" Then
             player.video.takeSnapshot
            sSnapFile = Dir(pic_path & "*.bmp")
             While sSnapFile = ""
                 sSnapFile = Dir(pic_path & "*.bmp")
             Wend
             Name (pic_path & sSnapFile) As (pic_path & sNewFile & ".bmp")
                     ' save to table
                 
                    '  CurrentDb.Execute "UPDATE OBSERVATION " & _
                    ' " SET PICTUREPATH='" & "C:\Users\cctvi\OneDrive\Documents\" & sNewFile & ".bmp" & "'" & _
                    '  " WHERE OBSERVATIONID=" & Me.frmObservationSub.Form.Recordset.Fields("OBSERVATIONID") & " AND DESCRIPTION IS NOT NULL"
             
                     ' dont save yet, just assign it to Me.txtPicturePath
             Me.txtPicturePath = pic_path & sNewFile & ".bmp"
      
        End If
      .Playlist.togglePause
   
    End With
 
End Sub
 
Last edited by a moderator:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:52
Joined
May 7, 2009
Messages
19,237
on sNewFile, the Format character for "minute" is "nn" not "mm".
 

Sac

Member
Local time
Today, 17:52
Joined
Feb 28, 2020
Messages
48
Arnelgp,

Thank you! I made the change and I still get the first pic in Docs folder with the same name as the one inserted in the table. After that, the name inserted in the table is different than the file name.
Thank,
Sac
 

Sac

Member
Local time
Today, 17:52
Joined
Feb 28, 2020
Messages
48
Arnelgp,

After playing with the code and following your example code, It appears that this did the trick! The Picture file saved in the docs folder is the same name as the db! So now I just simply take the pic without renaming.
A month ago, I was green with access VBA. But with your help, I came out of the green zone!!
Below is the change:

sNewFile1 As String

sNewFile1 = Format(Now(), "ddmmyyhhnnss")
sNewFile = "pic" & sNewFile1


Thanks for all your responses and help!!!
 

Users who are viewing this thread

Top Bottom