Working with client.bitstream_bytes(bitstream)

86 views
Skip to first unread message

Jujube Menon

unread,
Jan 8, 2024, 10:41:10 AMJan 8
to pyPreservica

I’m now working with pyPreservica and video .mp4 files using GStreamer which is a multimedia library written in C but with Python bindings. I’m using client.bitstream_bytes(bitstream)  and able to feed the chunks to the GStreamer pipeline and do HLS conversion which is great. However, I can do this only after all the chunks are downloaded.

I’m now attempting to feed the chunks to the GStreamer pipeline as they are downloaded using asyncio. At the moment, it appears to be that client.bitstream_bytes(bitstream) will block until the entire download is complete. Do you think it should be technically feasible to feed chunks as they are downloaded or am I just wasting my time?

Regards, Vinod

James Carr

unread,
Jan 11, 2024, 11:26:41 AMJan 11
to pyPreservica
Here is an example script which lets you process the chunks of a Bitestream as they arrive using a Generator function. In this case its 16K chunks. I'm not sure if it would be more efficient or not.

from pyPreservica import *

client = EntityAPI()


def chunks(bitstream: Bitstream):
with client.session.get(bitstream.content_url, headers={"Preservica-Access-Token": client.token}, stream=True) as request:
if request.status_code == requests.codes.ok:
for chunk in request.iter_content(chunk_size=1024*16):
yield chunk


if __name__ == '__main__':

asset = client.asset("c94b5b96-a151-4503-a05d-9b2e3dcee85c")

for bitstream in client.bitstreams_for_asset(asset):
for chunk in chunks(bitstream):
print(chunk)

Jujube Menon

unread,
Jan 24, 2024, 7:31:20 AMJan 24
to pyPreservica
Thanks, James. I will do some testing with this.

Jujube Menon

unread,
Feb 17, 2024, 8:32:59 AMFeb 17
to pyPreservica
Hi James,
I finally got around to testing the code you provided and it works brilliantly. The chunks are fed directly to my GStreamer pipeline with no lag and the HLS conversion takes place instantaneously. I'm thinking that even multi-part asset would work as we loop through a folder containing them. That will be the next thing to test.

Thanks again.
Regards, Vinod

James Carr

unread,
Feb 20, 2024, 5:02:26 AMFeb 20
to pyPreservica
I have added this function into the main library, the next time i do a release it should become available.
Message has been deleted

V. Chettur

unread,
Feb 23, 2024, 6:16:33 AMFeb 23
to pyPreservica
Thank you, James. It works very well with Gstreamer as well as ffmpeg.

V. Chettur

unread,
Mar 8, 2024, 5:02:52 PMMar 8
to pyPreservica
Hi James,
Did you add this to the latest release? I would like to read the documentation about it.
Thanks, V

On Tuesday, February 20, 2024 at 5:02:26 AM UTC-5 drjam...@gmail.com wrote:

V. Chettur

unread,
Mar 8, 2024, 5:07:18 PMMar 8
to pyPreservica

Also, able to smoothly stream a 40 part audiobook from mp3 to hls segments with no issues.
Reply all
Reply to author
Forward
0 new messages