Skip to content

feat: IPFS-based video support #16

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

feat: IPFS-based video support #16

wants to merge 5 commits into from

Conversation

stephancill
Copy link
Contributor

@stephancill stephancill commented Oct 16, 2023

Adds support for videos on IPFS via the livepeer-video and video-render Mods.

Uploading is done via the Infura IPFS API, which also pins the file.

When a video on IPFS is detected, the video-render mod tries to load the video directly via the IPFS gateway, but also makes a request to the /livepeer-video endpoint to upload and transcode the video to the livepeer servers via IPFS. This endpoint returns the livepeer asset ID which is then used to poll the /livepeer-video/<asset-id> endpoint to see if the streaming URL is ready. Once it is ready, it switches out the IPFS gateway video source for the HLS stream via Livepeer for a more performant streaming experience.

This PR introduces a few changes to mod packages to make this possible

  • Retryable HTTP requests via retryTimeout and retryCount available in the ModManifest type
  • Provide a mimeType alongside videoSrc for the video component
  • replaceInlineContext commands syntax + tests: split (splits a string) index selects an item at the specified index in an array e.g.
it("applies split and index operations to extract part of a string", () => {
    const context = { refs: { example: { url: "ipfs://exampleCID" } } };
    const template = "{{refs.example.url | split ipfs:// | index 1}}";
    expect(replaceInlineContext(template, context)).toBe("exampleCID");
  });

Todo:

  • Automatically request streaming url on load (blocking: onload is called excessively)
  • Confirm that livepeer uploads are being cached

@changeset-bot
Copy link

changeset-bot bot commented Oct 16, 2023

🦋 Changeset detected

Latest commit: 38d9420

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Oct 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2024 10:43am
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2024 10:43am
example-nextjs-shadcn ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2024 10:43am

Copy link
Contributor

@davidfurlong davidfurlong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost there

const [hasStartedPlaying, setHasStartedPlaying] =
React.useState<boolean>(false);

const pollUrl = useCallback(
Copy link
Contributor

@davidfurlong davidfurlong Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice addition

return null;
}

// TODO: Generate thumbnail if image/video
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to include this

return NextResponse.json(
{
message: "Took too long to upload. Try a smaller file",
// TODO: Cache this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think livepeer automatically caches this - if you request via an IPFS cid it doesn't re-upload if it's been uploaded to livepeer previously. Worth confirming we're doing it correctly to get this benefit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticing that their API is returning a different playbackId for each request. Can we check with them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will do

Copy link
Contributor

@davidfurlong davidfurlong Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it be this:

For IPFS HTTP gateway URLs, the API currently only supports
 “path style” URLs and does not support “subdomain style” URLs. The API will support both styles of URLs in a future update.

https://docs.livepeer.org/reference/api#upload-an-asset

I think the IPFS url uses our subdomain gateway as it stands

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I haven't asked them yet)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try upload to web3.storage instead of infura for our gateway

}
// Exchange for livepeer url
const cid = url.replace("ipfs://", "");
const gatewayUrl = `${process.env.IPFS_DEFAULT_GATEWAY}/${cid}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried it, still no caching

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will try emailing them again

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephancill can you try ipfs://{CID}?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting - it uploads fine without specifying a gateway, but still no caching (returns a different asset id each time it uploads)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants