Results 1 to 12 of 12

Thread: Save Video to SQLite DB and play it directly...

  1. #1

    Thread Starter
    Lively Member IndicSoftware's Avatar
    Join Date
    Aug 2017
    Location
    India
    Posts
    85

    Save Video to SQLite DB and play it directly...

    Hello Everyone,

    I am using VBRichClient and trying to save video files located in a folder to SQLite DB. Average size of a video file is 450 MB. The files are in following formats:
    • .mpg
    • .avi
    • .asf
    • .mp4


    But once the files are stored in DB if I want to view the video I have to first extract the file to hard disk and then play it. This is taking up a lot of tile especially whenthe file is large.

    Instead of this I want to be able to play the video directly from DB without having to extract it and save it to hard disk.

    For this how should I store the video in SQLite DB?

    Are there any possibilities of being able to stream the video from SQLite DB directly to MCI control.

    Regards,
    --
    From,
    Indic Software


    Revolutionary Visual Programming IDE.

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: Save Video to SQLite DB and play it directly...

    Can you first explain why you want to store files with a size of 450MB in a database file?

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Save Video to SQLite DB and play it directly...

    Quote Originally Posted by Arnoutdv View Post
    Can you first explain why you want to store files with a size of 450MB in a database file?
    Since SQLite is a filebased DB, he could then put it on a USB stick and move it around
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4
    gibra
    Guest

    Re: Save Video to SQLite DB and play it directly...

    Quote Originally Posted by Arnoutdv View Post
    Can you first explain why you want to store files with a size of 450MB in a database file?
    I agree 100%...
    Moreover, to be played, the video must be first saved again on disk.
    Because you don't play directly a video stored in database.

  5. #5
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: Save Video to SQLite DB and play it directly...

    Quote Originally Posted by Zvoni View Post
    Since SQLite is a filebased DB, he could then put it on a USB stick and move it around
    But why storing such huge files in a new file?

  6. #6
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Save Video to SQLite DB and play it directly...

    Quote Originally Posted by Arnoutdv View Post
    But why storing such huge files in a new file?
    Beats me *shrug*
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  7. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Save Video to SQLite DB and play it directly...

    Quote Originally Posted by gibra View Post
    Moreover, to be played, the video must be first saved again on disk.
    What i've found it's supposed to work with File-/MemoryStream with this Silverlight-Player-Thingy
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  8. #8
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Save Video to SQLite DB and play it directly...

    Quote Originally Posted by IndicSoftware View Post
    I am using VBRichClient and trying to save video files located in a folder to SQLite DB. Average size of a video file is 450 MB. The files are in following formats:
    • .mpg
    • .avi
    • .asf
    • .mp4


    But once the files are stored in DB if I want to view the video I have to first extract the file to hard disk and then play it. This is taking up a lot of tile especially whenthe file is large.

    Instead of this I want to be able to play the video directly from DB without having to extract it and save it to hard disk.

    For this how should I store the video in SQLite DB?

    Are there any possibilities of being able to stream the video from SQLite DB directly to MCI control.
    Below is a solution, which should be suitable to show (smaller) Videos (e.g. in the context of ones own HTML-Help-Viewer or something),
    by firing-up a small RC5-cWebServer instance (Process-locally) - and then stream the ByteBuffer-based Video-content
    to an appropriate Receiver(Client), which can handle Video-Streams...(accepting URL-parameters)...

    AFAIK, the MCI-Control is not capable to render URL-based Streams, but e.g.
    - the Windows-MediaPlayer
    - or alternatively the quartz.dll
    can do that for example.

    Here is a small Class, which depends on a Project-Reference to quartz.dll (as found in your \system32\ Folder).
    For the example to work, include the appropriate Reference (Active Movie Control type-library) -
    then create a new Class in your Project and name it cMediaPlay:
    Code:
    Option Explicit 'needs a Project-Reference to quartz.dll (as found in \System32)
    
    Private MC As IMediaControl, VW As IVideoWindow
    
    Public Sub InitWithResource(FileNameOrUrl As String, ByVal hWnd As Long, dx, dy)
      Set MC = New FilgraphManager
      Set VW = MC
      
      MC.RenderFile FileNameOrUrl
      
      VW.WindowStyle = &H6000000 'WS_CHILD or WS_CLIPCHILDREN
      VW.Owner = hWnd
      VW.MessageDrain = hWnd
      VW.SetWindowPosition 0, 0, dx, dy
    End Sub
    
    Public Sub Play()
      MC.Run
    End Sub
    Public Sub Pause()
      MC.Pause
    End Sub
    Then include a vbRichClient5-reference into your Project and paste the following Code into Form1:
    Code:
    Option Explicit
     
    Private WithEvents WebServer As cWebServer, BaseUrl As String
    Private Cnn As cConnection, Rs As cRecordset, MP As New cMediaPlay
     
    Private Sub Form_Load()
      Set Cnn = New_c.Connection(, DBCreateInMemory)
          Cnn.Execute "Create Table Vids(ID Integer Primary Key, VidBytes Blob)"
    
      Set Rs = Cnn.OpenRecordset("Select * From Vids Where 1=0")
          Rs.AddNew: Rs!VidBytes = New_c.FSO.ReadByteContent("C:\temp\Join.avi")
          Rs.AddNew: Rs!VidBytes = New_c.FSO.ReadByteContent("C:\temp\Sample.mpg")
      Rs.UpdateBatch
      
      Const Port& = 8282
      Set WebServer = New_c.WebServer 'we use an App-internal WebServer-instance on the ...
          WebServer.Listen App.Path, "127.0.0.1", Port 'firewall-friendly loopback-interface
      BaseUrl = "http://127.0.0.1:" & Port & "/GetVideo?"
    End Sub
    
    Private Sub Form_Click()
      Static VidID As Long: VidID = (VidID Mod 2) + 1 'switch between ID 1 and 2
      DoVideoRequest VidID
    End Sub
    
    Private Sub DoVideoRequest(ByVal VidID As Long)
      MP.InitWithResource BaseUrl & VidID, hWnd, 640, 480
      MP.Play
    End Sub
    
    Private Sub WebServer_ProcessRequest(Request As vbRichClient5.cWebRequest)
      Dim CmdSpl() As String
      With Request
       If .Method = HTTP_GET And InStr(.URL, "?") > 0 Then
         CmdSpl = Split(Request.URL, "?")
      
         Select Case UCase$(CmdSpl(0))
           Case "GETVIDEO"
            .Response.ContentType = "video/x-msvideo" '"video/mpeg"
            .Response.SetResponseDataBytes GetVideoBytesForID(CmdSpl(1))
         End Select
       End If
      End With
    End Sub
    
    Private Function GetVideoBytesForID(ByVal VidID As Long) As Byte() 'read the Vid-ByteContent for a given ID from the Mem-DB
      With Cnn.CreateSelectCommand("Select VidBytes From Vids Where ID=?")
        .SetInt32 1, VidID
        GetVideoBytesForID = .Execute!VidBytes
      End With
    End Function
    The two small Video-Files for the demo above, were copied to C:\temp ...
    - the first one (C:\temp\Join.avi) should be locatable below C:\Windows (it comes with modern Systems, but any other small *.avi should do)
    - the second one (C:\temp\Sample.mpg) I've downloaded from here: http://techslides.com/sample-files-for-development (from the Video-Files-section).

    Be advised, that Video-Files larger than - say - 100-200MB will be problematic to handle with that approach,
    since neither the SQLite-Wrapper-Objects - nor the little WebServer can handle Blobs or Response.WriteBack-content in chunks
    (meaning, each Video has to fit into normal, consecutively allocated VB6-ByteArray - and that will become problematic with larger Videos).

    HTH

    Olaf

  9. #9

    Thread Starter
    Lively Member IndicSoftware's Avatar
    Join Date
    Aug 2017
    Location
    India
    Posts
    85

    Re: Save Video to SQLite DB and play it directly...

    Hello Everyone,

    Thanks all for your inputs.

    Olaf, a special thanks for the code snippets!!

    I will check the code out next week and get back if I run into any problems.

    Olaf, as you have stated that this will work with small video files only so I will have to experiment with large files and if possible decide on the largest file size that your suggested solution can handle. After that I can suggest the client to split the videos into smaller pieces...

    BTW would it be advise able to use VLC Media Player embedded in my software?

    I think VLC can handle playing videos from stream directly.

    Of course I have still researching as to how to do this though.

    Regards,
    --
    From,
    Indic Software


    Revolutionary Visual Programming IDE.

  10. #10

    Thread Starter
    Lively Member IndicSoftware's Avatar
    Join Date
    Aug 2017
    Location
    India
    Posts
    85

    Re: Save Video to SQLite DB and play it directly...

    Hello Everyone,

    Thanks all for your inputs.

    Olaf, a special thanks for the code snippets!!

    I will check the code out next week and get back if I run into any problems.

    Olaf, as you have stated that this will work with small video files only so I will have to experiment with large files and if possible decide on the largest file size that your suggested solution can handle. After that I can suggest the client to split the videos into smaller pieces...

    BTW would it be advise able to use VLC Media Player embedded in my software?

    I think VLC can handle playing videos from stream directly.

    Of course I have still researching as to how to do this though.

    Regards,
    --
    From,
    Indic Software


    Revolutionary Visual Programming IDE.

  11. #11

    Thread Starter
    Lively Member IndicSoftware's Avatar
    Join Date
    Aug 2017
    Location
    India
    Posts
    85

    Re: Save Video to SQLite DB and play it directly...

    Quote Originally Posted by Arnoutdv View Post
    Can you first explain why you want to store files with a size of 450MB in a database file?
    It is one of the many requirements put forward by my client.
    --
    From,
    Indic Software


    Revolutionary Visual Programming IDE.

  12. #12

    Thread Starter
    Lively Member IndicSoftware's Avatar
    Join Date
    Aug 2017
    Location
    India
    Posts
    85

    Re: Save Video to SQLite DB and play it directly...

    Quote Originally Posted by Arnoutdv View Post
    Can you first explain why you want to store files with a size of 450MB in a database file?
    It is one of the many requirements put forward by my client.
    --
    From,
    Indic Software


    Revolutionary Visual Programming IDE.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width