> ## Documentation Index
> Fetch the complete documentation index at: https://docs.livepeer.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Transcode with Storj

This guide will describe how to use the Livepeer
[transcode API](/api-reference/transcode/create) to transcode and store video
files in Storj using Storj’s S3 API.

There are [code examples](#code-examples) provided for reference.

<Info>
  The Transcode API can be used with any S3-compatible storage provider.
</Info>

### Storj S3 Credentials

This step assumes that you have already created an account with
[Storj](https://www.storj.io/).

Follow the
[Storj guide for generating S3 credentials](https://docs.storj.io/dcs/api-reference/s3-compatible-gateway#I7p7Q)
using either the web interface or `uplink`. Make sure that the credentials have
the proper read/write permissions for the bucket that your video files will be
read from and that transcoded videos will be written to. The access key and
secret key of the credentials will be used in the next step.

### Upload Video to Storj

Make sure you have a video file uploaded to your Storj bucket. You must upload
the video file using one of the following methods:

* Via the Storj web interface
* Via the [Storj uplink CLI](https://www.storj.io/integrations/uplink-cli)
* Via a S3 API client
  * [AWS has S3 API client implementations](https://aws.amazon.com/developer/tools/)
    in different programming languages
  * The [code examples](#code-examples) illustrate how to upload a video file to
    Storj using a S3 API client

### Transcode with Livepeer

This step assumes that you have already created a
[Livepeer Studio account](https://livepeer.studio/) and an
[API key](/api-reference/overview/authentication).

<Tabs>
  <Tab title="Node.js">
    ```javascript theme={"theme":{"light":"github-light","dark":"dark-plus"}}
    import { Livepeer } from "livepeer";

    const apiKey = "YOUR_API_KEY";

    const livepeer = new Livepeer({ apiKey });

    livepeer.transcode.create({
      input: {
        type: "s3",
        endpoint: "https://gateway.storjshare.io",
        credentials: {
          accessKeyId: "$ACCESS_KEY_ID",
          secretAccessKey: "$SECRET_ACCESS_KEY"
        },
        bucket: "mybucket",
        path: "/video/source.mp4"
      },
      storage: {
        type: "s3",
        endpoint: "https://gateway.storjshare.io",
        credentials: {
          accessKeyId: "$ACCESS_KEY_ID",
          secretAccessKey: "$SECRET_ACCESS_KEY"
        },
        bucket: "mybucket"
      },
      outputs: {
        hls: {
          path: "/samplevideo/hls"
        },
        mp4: {
          path: "/samplevideo/mp4"
        }
      },
      profiles: [
        {
          name: "480p",
          bitrate: 1000000,
          fps: 30,
          width: 854,
          height: 480
        },
        {
          name: "360p",
          bitrate: 500000,
          fps: 30,
          width: 640,
          height: 360
        }
      ]
    }).then((video) => {
      console.log(video);
    }).catch((error) => {
      console.error(error);
    });
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={"theme":{"light":"github-light","dark":"dark-plus"}}
    import livepeer
    from livepeer.models import components

    client = livepeer.Livepeer(
        api_key="<YOUR_BEARER_TOKEN_HERE>",
    )


    params = {
      "input": {
        "type": "s3",
        "endpoint": "https://gateway.storjshare.io",
        "credentials": {
          "accessKeyId": "$ACCESS_KEY_ID",
          "secretAccessKey": "$SECRET_ACCESS_KEY"
        },
        "bucket": "mybucket",
        "path": "/video/source.mp4"
      },
      "storage": {
        "type": "s3",
        "endpoint": "https://gateway.storjshare.io",
        "credentials": {
          "accessKeyId": "$ACCESS_KEY_ID",
          "secretAccessKey": "$SECRET_ACCESS_KEY"
        },
        "bucket": "mybucket"
      },
      "outputs": {
        "hls": {
          "path": "/samplevideo/hls"
        },
        "mp4": {
          "path": "/samplevideo/mp4"
        }
      },
      "profiles": [
        {
          "name": "480p",
          "bitrate": 1000000,
          "fps": 30,
          "width": 854,
          "height": 480
        },
        {
          "name": "360p",
          "bitrate": 500000,
          "fps": 30,
          "width": 640,
          "height": 360
        }
      ]
    }

    res = client.transcode.create(request=components.TranscodeRequest(**params))

    if res.task is not None:
    # handle response
    pass
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={"theme":{"light":"github-light","dark":"dark-plus"}}
      package main

    import(
      livepeergo "github.com/livepeer/livepeer-go"
      "github.com/livepeer/livepeer-go/models/components"
      "context"
      "log"
    )

    func main() {
      client := livepeergo.New(
        livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
    )

      params := map[string]interface{}{
        "input": map[string]interface{}{
          "type": "s3",
          "endpoint": "https://gateway.storjshare.io",
          "credentials": map[string]string{
            "accessKeyId": "$ACCESS_KEY_ID",
            "secretAccessKey": "$SECRET_ACCESS_KEY",
          },
          "bucket": "mybucket",
          "path": "/video/source.mp4",
        },
        "storage": map[string]interface{}{
          "type": "s3",
          "endpoint": "https://gateway.storjshare.io",
          "credentials": map[string]string{
            "accessKeyId": "$ACCESS_KEY_ID",
            "secretAccessKey": "$SECRET_ACCESS_KEY",
          },
          "bucket": "mybucket",
        },
        "outputs": map[string]interface{}{
          "hls": map[string]string{
            "path": "/samplevideo/hls",
          },
          "mp4": map[string]string{
            "path": "/samplevideo/mp4",
          },
        },
        "profiles": []map[string]interface{}{
          {
            "name": "480p",
            "bitrate": 1000000,
            "fps": 30,
            "width": 854,
            "height": 480,
          },
          {
            "name": "360p",
            "bitrate": 500000,
            "fps": 30,
            "width": 640,
            "height": 360,
          },
        },
      }

      ctx := context.Background()
      res, err := client.Transcode.Create(ctx, request)
      if err != nil {
          log.Fatal(err)
      }
      if res.Task != nil {
          // handle response
      }
    }
    ```
  </Tab>
</Tabs>

The parameters are defined as:

* `$API_KEY` is your Livepeer Studio API key
* `$ACCESS_KEY_ID` is the access key and `$SECRET_ACCESS_KEY` is the secret key
  of the S3 credentials you generated in the previous step
* `input.bucket` is the name of your Storj bucket
* `input.path` is the path that your video file can be found in the Storj bucket
* `outputs.hls.path` is the path that the HLS playlist and mpegts segments is
  found in when transcoding is complete
* `outputs.mp4.path` is the path that the MP4 video files is found in when
  transcoding is complete
* `profiles` is an optional parameter to specify the desired properties of
  transcoded video

Use the task ID in the response to query for the transcoding task status. Once
the task is complete, the HLS playlist and mpegts segments will be available at
`outputs.hls.path`, and MP4 output videos will be available at
`outputs.mp4.path`.

For more information about the transcode API refer to the
[API reference docs](/api-reference/transcode/create).

### Playback From Storj

You can create a public playback URL for the transcoded video by first creating
a shared Storj URL:

* If you are using `uplink`, follow the
  [Storj Link Sharing guide](https://docs.storj.io/dcs/api-reference/uplink-cli/share-command/#f-jKX)
  to create a URL for your bucket
* Ex.
  `uplink share sj://demo-bucket/ --url --not-after=none --base-url=https://link.storjshare.io`
* If you are using the web interface, navigate to your bucket under “Buckets”
  and click the “Share Bucket” button to create a URL for your bucket

The URL should look like this:

```bash theme={"theme":{"light":"github-light","dark":"dark-plus"}}
https://link.storjshare.io/jwjfgdxkvmfgngsgitii6pny62za/demo-bucket
```

For example, if the `outputs.hls.path` for the request in the previous step was
`/samplevideo/hls`, then the master HLS playlist used for playback will be
available at:

```bash theme={"theme":{"light":"github-light","dark":"dark-plus"}}
https://link.storjshare.io/jwjfgdxkvmfgngsgitii6pny62za/demo-bucket
```

You can play back the transcoded video from Storj using this URL with any HLS
player. For example,
`https://lvpr.tv/?url=https://storage.lp-playback.studio/raw/jwjfgdx…/demo-bucket/samplevideo/hls/index.m3u8`
will play back the video using the embeddable Livepeer player.

### Code Examples

* [Nodejs](https://github.com/livepeer/storj-livepeer-nodejs-example)
