Is it possible to encode AVI video to MP4 using Java Azure function?

Sandeep Kumar Thakurala 0 Reputation points

Since Azure Media Service is being retired next year, I was thinking to try different approach to encode a video to MP4 and this approach includes Java Azure Function. The flow would be like this

  1. Get BlobInputStream by calling blobClient.openInputStream() on BlobClient.
  2. Get byte[] from BlobInputStream.
  3. Use some library to perform encoding like JAVE2 or FFMPEG.(This step is where I am confused).
  4. Hopig above would result in byte[], create InputStream from byte[].
  5. Write encoded video to storage account container by calling upload(InputStream data) on BlobClinet. OR
    • Somehow mount storage account as files system to function
    • Get the video as File object and pass this object to JAVE2.
    • Write encode output File object to mounted file system.
    • Move the encoded file from file system to storage account. NOTE: Max file size of input file is 100MB. In theory both options sounds simple but the problem I am running into with option one is JAVE2 and other similar libraries accepts object for input and output but azure-storage-blob library does not exposes any api to get File object. Now option left is to open inputstream to get byte[] but then how to encode a byte array. For option two, I am not sure if mounting storage account as file system possible.
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,628 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 69,981 Reputation points

    @Anonymous Thanks for reaching out.

    I am not an expert with the JAVE2 or FFMPEG library but from storage and function perspective I can answer your question.

    Regarding your first option, you are correct that the azure-storage-blob library does not expose any API to get a File object. However, you can still use JAVE2 or FFMPEG libraries to encode the video by passing the byte[] obtained from the BlobInputStream to these libraries. Both JAVE2 and FFMPEG libraries have APIs that accept byte[] as input and output byte[] as well. Once you have the encoded byte[], you can create an InputStream from it and write it to the storage account container by calling upload(InputStream data) on BlobClient.

    Regarding your second option, it is not possible to mount a storage account as a file system in Azure Functions. However, you can still use the first option to encode the video and write the encoded file to the storage account container.

    0 comments No comments