none
[Python][Azure Storage] How can I record a live stream to a Azure Blob(or blob list thingy)? RRS feed

  • Question

  • I would like to stream from my webcam (with webrtc) to my recording server and from my recording server to a azure storage blob without saving it on the recording server (I just use the server for transcoding). My current recording server implementation accepts "file://path/to/file" and other url mappings to write the recording to a file, I would be glad if I can be told how to stream to a blob in python (with the azure storage api), but any other language is acceptable.

    Monday, March 7, 2016 4:43 PM

Answers

All replies

  • You can leverage create_blob_from_stream() in python storage sdk to upload the contents from an already opened file/stream to blob storage.

    You can refer to source code of create_blob_from_stream() at github for detailed parameter settings.

    And additionally, there is a sample list at github, which contains a code snippet how to use blob with stream, refer to https://github.com/Azure/azure-storage-python/blob/master/samples/blob/block_blob_usage.py#L315 for the sample.

    Any concern, please feel free to let me know.  

    Tuesday, March 8, 2016 3:20 AM
    Moderator
  • hey thank you for replying, can I like create a blob and have a "write url" to it? like "me.core.windows.net/recordings/new_recording" and write to that url?
    Tuesday, March 8, 2016 12:24 PM
  • Please try with the code snippet

    import requests
    import io
    from azure.storage.blob import BlockBlobService
    
    blob_service = BlockBlobService(account_name='<account_name>', account_key='<account_key>')
    container = '<container_name>'
    blob = '<blob_name>'
    imgurl='resource_url'
    r = requests.get(imgurl, stream=True)
    stream = io.BytesIO(r.content)
    blob_service.create_blob_from_stream(container,blob,stream)
    

    Wednesday, March 9, 2016 8:40 AM
    Moderator