livepeer / task-runner

Background service that executes tasks from the Livepeer API. Mainly used for VOD.
MIT License
3 stars 2 forks source link

task: prepare #16

Closed figintern closed 2 years ago

figintern commented 2 years ago

https://github.com/livepeer/task-runner/issues/12

First pass at Prepare task which creates new stream with { record: true } to get recording of stream for import and transcode tasks

Currently implemented as a helper but can be moved into its own task

No session is created when setting record: true so the recording streamID is used as the PlaybackRecordingID for HLS constructing HLS playback.

Testing on staging:

# IMPORT
curl --location --request POST 'https://livepeer.monster/api/asset/import' \
--header 'Authorization: Bearer a001ecb9-05d6-4878-a5af-1ffec64ade40' \
--header 'Content-Type: application/json' \
--data-raw '{
    "url":"https://file-examples.com/storage/fef8fbdce362705a7927afd/2017/04/file_example_MP4_1280_10MG.mp4",
    "name":"tonytest1"
}'

# TRANSCODE
curl --location --request POST 'https://livepeer.monster/api/asset/transcode' \
--header 'Authorization: Bearer a001ecb9-05d6-4878-a5af-1ffec64ade40' \
--header 'Content-Type: application/json' \
--data-raw '{
    "assetId":"9a6fc70f-e1b5-4e8b-837c-a6952fe1ad5e",
   "name": "tonytranscode156",
   "profile": { "name": "480p0", "fps": 30, "bitrate": 100000, "width": 480, "height": 270 }
}'

# LIST ASSETS
~/livepeer/task-runner % curl --location --request GET 'https://livepeer.monster/api/asset' \
--header 'Authorization: Bearer a001ecb9-05d6-4878-a5af-1ffec64ade40' | jq
[
  {
    "id": "9c414291-8448-458a-8d78-35af2282a394",
    "hash": [
      {
        "hash": "53c84fe23c54bb9dccf549ea495bc7c6",
        "algorithm": "md5"
      },
      {
        "hash": "9a292769693fc1f8b83d5e2f5d087daad31d7ef2ffb268024427af2c5ce6f7f8",
        "algorithm": "sha256"
      }
    ],
    "name": "tonytranscode156",
    "size": 991674,
    "status": "ready",
    "userId": "2f4daa89-4e58-4ee7-bd32-186fb05500ce",
    "createdAt": 1651595161052,
    "updatedAt": 1651595178517,
    "videoSpec": {
      "format": "mp4",
      "tracks": [
        {
          "fps": 30.033333333333335,
          "type": "video",
          "codec": "h264",
          "width": 480,
          "height": 270,
          "bitrate": 96352,
          "duration": 30.5066
        },
        {
          "type": "audio",
          "codec": "aac",
          "bitrate": 160111,
          "channels": 2,
          "duration": 30.5066,
          "sampleRate": 48000
        }
      ],
      "duration": 30.5066
    },
    "playbackId": "9c41n69k4hh3i50h",
    "sourceAssetId": "9a6fc70f-e1b5-4e8b-837c-a6952fe1ad5e",
    "playbackUrl": "https://livepeercdn.monster/recordings/b17134e8-a17b-4d80-9b47-731bb444f015/index.m3u8",
    "downloadUrl": "https://livepeercdn.monster/asset/9c41n69k4hh3i50h/video"
  },
  {
    "id": "9a6fc70f-e1b5-4e8b-837c-a6952fe1ad5e",
    "hash": [
      {
        "hash": "10c918b1d01aea85864ee65d9e0c2305",
        "algorithm": "md5"
      },
      {
        "hash": "8ab080c1406dff77f8897955cf977e9ad779e40ab3a07bc2f8694fbd2fc2be21",
        "algorithm": "sha256"
      }
    ],
    "name": "tonytest1",
    "size": 9840497,
    "status": "ready",
    "userId": "2f4daa89-4e58-4ee7-bd32-186fb05500ce",
    "createdAt": 1651595072766,
    "updatedAt": 1651595089059,
    "videoSpec": {
      "format": "mp4",
      "tracks": [
        {
          "fps": 30,
          "type": "video",
          "codec": "h264",
          "width": 1280,
          "height": 720,
          "bitrate": 2453499,
          "duration": 30.033333,
          "pixelFormat": "yuv420p"
        },
        {
          "type": "audio",
          "codec": "aac",
          "bitrate": 160000,
          "channels": 2,
          "duration": 30.526667,
          "sampleRate": 48000
        }
      ],
      "duration": 30.526667
    },
    "playbackId": "9a6fw3cmw5mzzywe",
    "playbackUrl": "https://livepeercdn.monster/recordings/2ffd5555-d2a3-4ac7-aedd-41072aa92d27/index.m3u8",
    "downloadUrl": "https://livepeercdn.monster/asset/9a6fw3cmw5mzzywe/video"
  }
]

TODO: Update ReportProgress to include prepare task Improve efficiency by refactoring uploading/downloading the files Check output file to make sure full file is there / correct