1
Seekable stream off of http video resource
Problem reported by S K - 7/14/2020 at 3:00 PM
Resolved
Hello Folks!

I have a video source that's located in the web (usual https://blah.mp4 etc)

I am trying to cut a thumbnail without having to download the entire video (the video can be huge)

I tried to use the code below, but I am getting the error "Stream must be seekable"

I would appreciate any ideas on how to go about cutting thumbnails from a
url without having to d/l the entire video.

I would also appreciate a critique of my spin lock technique.


==

string fileUrl = "https:/....";
WebResponse objResponse = WebRequest.Create(fileUrl).GetResponse();
Stream stream = objResponse.GetResponseStream();
using (var videoFrameReader = new VideoFrameReader(stream))
{
    while (!videoFrameReader.Read()) //Only if frame was read successfully
    {
      /* Spin lock with sleep for 500 ms till we get at least one frame */
      System.Threading.Thread.Sleep(500);
    }

     using (var frame = videoFrameReader.GetFrame())
     {
          String thumnailDestination = "Local file path";
          frame.Save(thumbnailDestination, ImageFormat.Jpeg);
     }

}

2 Replies

Reply to Thread
1
Cem Alacayir Replied
Employee Post Marked As Resolution
VideoUltimate already supports URLs:

videoPath
Type: System.String
The path to the video file to load. URLs are also supported.
So you simply do this:

using (var videoFrameReader = new VideoFrameReader("http://vjs.zencdn.net/v/oceans.mp4"))
{
    //Process..
}
or

using (var videoThumbnailer = new VideoThumbnailer("http://vjs.zencdn.net/v/oceans.mp4"))
{
    //Process..
}
0
S K Replied
Thanks! That really helped.

Reply to Thread