Grabbing a thumbnail from a video when uploading.

2019-05-31 23:21发布

I currently has a system that uploads videos to Azure blob storage and works fine. I would like to implement a feature that grabs a thumbnail from the video while uploading and pushes it to Azure as well.

I tried using this as suggested:

new FFMpegConverter().GetVideoThumbnail(file, outputJPEG);

The problem is that I am not sure what to use as outputJPEG as I don't have a file I am writing to, but rather want to write that file to Azure's blob storage.

Can anyone help me figure out this issue, or perhaps suggest an alternative method?

I have tried:

  • Creating a new, empty HttpPostedFileBase as the outputJPEG file but this is impossible as it only accepts user uploaded files.

  • Using filestream but this does not seem to work as it requires a location of a file it's writing to, rather than letting me just push to the blob storage. (via: blob.UploadFromStream(file.InputStream);)

Thanks in advance for any help!

2条回答
一纸荒年 Trace。
2楼-- · 2019-06-01 00:08

Note that GetVideoThumbnail method always creates temporary file for output jpeg file even when overload that accepts Stream is used.

If you goal is to avoid creation of temporary file you can use FFMpegConverter.ConvertLiveMedia overload that accepts inputSource from file and writes result to output stream (extracting video thumbnail is equivalent to conversion to MJPEG stream with only 1 frame).

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-06-01 00:16

It looks like there is an override that takes a stream, so you could write it to a memory stream and then take the memory stream and create a new file in the blob store:

MemoryStream ms = new MemoryStream();
var converter = new FFMpegConverter();

converter.GetVideoThumbnail(file, ms);

ms.Position = 0;

// Write ms to a blob object here
blockblob.UploadFromStream(ms);
查看更多
登录 后发表回答