Livepeer 🛠 Building the future of video with Livepeer - Suhail Kakar
Space Warp 2023 · 24 Jan 2023 · 15:16
Suhail Kakar from Livepeer shows how to add video to an app with Livepeer. The workshop explains why video streaming and transcoding are costly and how Livepeer's decentralized network and Studio dashboard reduce that cost, then builds a Next.js app step by step with the Livepeer React SDK: setting up the client with an API key, fetching an asset, uploading a video and playing it with the player, including content stored on IPFS.
Speakers
Topics
From Space Warp 2023, hosted by ETHGlobal.
Transcript
foreign [Applause] [Music] who can use live peer what problem does it solve and finally how to interview live viewer into your application approximately 80 of the entrance traffic is accounted by the video that means the large majority of the data transmitted and receive it over the internet and in the form of video content such as streaming videos online video calls and video sharing on the social medias however this process is very expensive a main factor is the amount of data and bandwidth required to transmit and receive high quality and transcoded
videos requires a specialized technology and infrastructure such as powerful servers high-speed networking equipment and furthermore video streaming and transcoding can be resource intensive process which can increase the cost of hosting and delivering the video content for example a transcoding a video from one format to another requires lots of commuting power storage which can drive up to cost of the hosting and also delivering the network and for this the solution is Life Pure Life peer is a decentralized video streaming platform that uses blockchain technology to enable anyone to easily and affordably extreme live video to a global audience it is built for the developer and it aims to increase the availability of the
live and on-demand video streaming while reducing the infrastructure cost by up to 50 times to easily interact with live peer you can use live pure residual which is an open source dashboard for interacting with live pure Network creating and managing API Keys live streams and video assets from an easy to use dashboard and yeah that's about the live view and I will be integrating life here and to a sample application so in this Workshop we will be using live pure JS which is the JavaScript key for live view at mixed building where the live video very easy if your project is not made with the react framework you can easily use a live pure API the rest API can be used on any language or framework you want
and yeah so now for live pair.js the first thing you need to set up an xgs application which we'll be doing now and then installing the Library so you can open up the terminal and then go to directory which you want to add create the application in my case I'm going to desktop and here we can create npx create a next application Live pure app and this will create the next GS application if you don't want to type script and we work with sland until the next application is completed and you'll want to also go to live peers video to create an account and get an API and yeah if you have here you should see a sign up button here you can go
ahead and sign up with your email and password at the thousand transcoding minutes is completely free so you don't need to pay for the first thousand minutes but once you come here you will see the dashboard and you can go to developers here and click on create an API key and give the API key a name and my case is going to be fvm Workshop you can also allow chords if you want but it is not necessary if you're not using it on your front end once you have it you can grab this API key save it some places because you will be need this later now coming back here at the Nexus application is installed and now we can go to the next JS directory that is a live pure app and install live pure package
here we can also open the application into vs code but you can use any other record editor that you prefer foreign package is now installed and yeah so the BC would be to follow the live peer guide and from here you have everything on how to set up in your next GS application and the first thing that you'd want to do is initial client go here and the pages and then in spite of app.js you can create cons client is
equals to better react client and finally you need to put your studio API key here you also need to import react client and Studio provider and also live peer config from App live pure flash react and at last we need to wrap our application with the live pure config we can do it like this and finally bring this component here save it and yeah that's it now the live viewer is basically integrated into our
application and now we can use live peer into our next GF application so the first thing that you would want to do is just open the terminal and run your own div in order to store the next.js application and then you can go to localhost 3000 and yeah this is a sample link JS application which we'll be using now to eye level so you'd want to clean up this code completely and just have it H1 maybe watch Pure yep that works you can also remove these imports from
here for now uh you can also remove the styling or yeah we can keep it for now but yeah we have the light viewer app here so let's go back to the styling and now in order to test whether the live player has successfully integrated or not we can just use a user set to check if everything is accessfully integrated or not now we can say use asset hook and here you need to put the asset ID once you have upload an asset whether through the API or residue or also SDK you would get the asset ID and then we can use that one to fetch the asset here in my case I want to fetch this asset this is the idea of it or even you can use this
one and here we need to put this here and finally we can just click console.log asset or we can just print it here let's do it here listen Dot ringify asset and if you come back to the application you can see it's printed here this is the idea of asset the hash the how it was uploaded when it was created and finally the playback URL so it means that we have successfully integrated live pure JS into our application so now we'll go to on how you can upload a video to the live peer and for that we
would be using use Creator which is very similar to use asset and use create assets so here you can import use create effort from what life peer react and here we can name from asset input type is going to be text and then Place folder and turn the name and here also we can create a few States in order to save the value from the input we can give it name set name
is equals to u50 make sure to import user safe from react and here we are going to also have another input and this is going to have a type file and it's going to accept the video and finally we can also put the on change here that once the person has selected the video we can get filed and set let's create one more here const video set video set and here we can see set video file we also put another on change here in
order to save the value of the input to that state once it is then it should look like this for now we are going to focus much on from The Styling here a simple styling should work margin left then and finally here we need to add a button that would be create asset that should work and here we can say on click handle upload and here we can come here and create a new function called handle upload a little bit and yeah that's it we have
declared a few States here for name and for the file a function that would be used to handle the midi upload and finally to input components and one better and for now we can console.log both the name and video to see if both of them is save it successfully and once we have that one you would be using youth create asset so here I'm going to type it something and choose a video file click on open and create after you can see we have both the name and file which means it's working fine and now we have to use the use create asset we can add it here and the cons that it was to use create effort and inside of Youth
create asset we can pass the video so we can see if there's a video we would want to pass sources it should be in the form of array and you can also upload multiple videos if you want in our case we just want to upload one video we can say name is going to be the name and finally file is equals to video and name video is not there here we can just render now and inside of here we can add create asset we can get the data from it once asset is uploaded we can also get a status we can get a progress and finally
error if there's any and finally now on the handle upload we can call the create asset function now let's refresh this page let's give it a name for example Test video click on choose file upload the video which you want and then click on create asset and now this should create an asset for f now let's come back to the live peer Studio go to asset you can see this is a test video which the video is currently processing but it means that the video is now uploaded to the live view and yeah that is how you would want to upload a video to the live peer and in the live prgs documentation you can also
go through different examples with different hooks such as use assets metrics use update asset and lots of different options and yeah that was the example of how you want to upload the video to the live peer and just have one more example on how you can play a video that's already stored into ipfs using live peer player so live pair private player provides easy to use a component to display boot video and audio it's going to be very easy so let's first remove all of the code which we have already here but yeah this is the code which you want to use for uploading the video which we have seen here anything you can see the video is also now uploaded and it can be playable the
video which I've uploaded is a very bad quality because I just wanted to upload it very faster but you can upload anything you want this was just an example video yeah now in order to use the player we can just remove this old code here and just add a Dev tag and inside of this you can add player from and this player would be imported from atlifebeard slash react and now in this foot player you can play a asset which has already stored on live peer Studio you can play ipfs hash you can play from our with transaction hash and from other places so in this example
maybe we have this video it we can play it using the playback ID so here we can just develop playback ID and then put the playback ID here we can also give it some stylings names team Etc but for now we can ignore that one so let's come back here and now you can see we have the video player and if we click on play it should now play the cat video which we see here and yeah let's play now just to make it let's make it a little bit smaller or we can say Style wet to be probably 70 percent and yeah that's fine and this is the live pure player now the asset which we are
currently playing has already stored to the live pure video but if you want you can also pass here ipff hash and that should also work for example it will be ipfs. and here you would want to put the ipfs hash it does not depend whether your video store it on the ipfs or like W3 storage or in other places it would automatically play for example if you go to the storage and here we have a few videos I've stored in both ipv5th and RV for example this is the video I can just copy the ipfs hash here and come back to our application and put the ash here save it and now if we come here
basically the video should play and yeah let's play it and you can see the video gets played and you can also play and yeah that's it thank you very much but yeah this is a pre-recorded workflow if you have any questions or anything feel free to DM me on Discord or join us the back live pure Discord and that on the CD support
