0

I'm implementing an API that allows the user to send a video stream and generate thumbnails. I'm using asp.net core and Azure Blob Storage. The interface of API is this:

    [HttpPost]
    [Route("test_upload")]
    public IActionResult TestUpload( IFormFile mediaFile ) {
        //->store mediaFile
        //->generate thumbnail
        //->save thumbnail
        return Ok();
    }

I need to do two main things:

  1. Generate a thumbnail
  2. Get video information such as the duration

I tried to use libraries from Nuget, but all of this needs the file path and I don't have the file path, just the video Stream or the Blob from the Blob Storage after saving. So, my question is, how can I manage video directly from the stream using FFmpeg or another tool?

I know Azure Media Services provide a lot of tools to manage media files such as videos and audio, but it's too slow for videos that are just 2Mb and 30 seconds long. And I don't need to encode the video, create streams or other things like that. I just need to take video information from a Stream and store the video on the Storage.

Any idea? Thanks!

Update 1: I wrote a workaround by creating a folder for temporary videos, I just save the video in this folder, create the thumbnail and delete the temp file. But I don't know if this practice has some bad side effects.

Gaetano Lenoci
  • 179
  • 1
  • 10
  • 1
    I don't think it is possible directly from the stream or blob storage. But you could store the stream first on a 'normal' (temp) storage and do the processing there. See also this answer: https://stackoverflow.com/questions/43681552/verify-duration-of-video-which-has-been-uploaded-into-azure-blob – Poiter Oct 08 '21 at 10:29
  • Ok thanks, with this method it works. But, it's a good pratice allow the server to save temp files in a folder? Can there be any side effects? – Gaetano Lenoci Oct 08 '21 at 12:23

1 Answers1

0

Thank you Poiter, Posting your comment as an answer, which will be helpful to other community members.

Upload to %TEMP% (which expands to d:\local\temp). That's local storage in App Service. All those libs should then work against the local filesystem, including MediaInfo

Cleanup your %TEMP% with a nightly WebJob to account for stale/incomplete uploads (i.e. remove files older than 6 hours), just in case your delete calls to the filesystem fail from time to time due to unforeseen reasons.

Can there be any side effects?

Cache the input stream to temporary file. It brings seeking capability to live streams.
Please refer FFmpeg Cache