Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Post segment for transcode to Livepeer network directly from go code #92

Merged
merged 4 commits into from
Oct 27, 2022

Conversation

AlexKordic
Copy link
Contributor

Followup issues:

How to test

Prepare ./sample.ts in snippet dir.

Use this snippet:

package transcode_test

import (
	"fmt"
	"math/rand"
	"os"
	"testing"
	"time"

	"github.com/livepeer/catalyst-api/cache"
	"github.com/livepeer/catalyst-api/config"
	"github.com/livepeer/catalyst-api/transcode"
	"github.com/stretchr/testify/require"
)

func TestTranscode(t *testing.T) {
	rand.Seed(time.Now().Unix())

	file, err := os.Open("./sample.ts")
	require.NoError(t, err)
	defer file.Close()

	creds := transcode.Credentials{
		AccessToken:  "REPLACE-ME-WITH-SECRET",
		CustomApiUrl: "https://origin.livepeer.com/api/",
	}
	request := transcode.SegmentTranscodeRequest{
		StreamName:      config.RandomTrailer(),
		Credentials:     creds,
		SequenceNumber:  0,
		MediaDataReader: file,
		MediaDurationMs: 971,
		TargetProfiles: []cache.EncodedProfile{
			{Name: "p360", Bitrate: 800000, Width: 640, Height: 360, FPS: 24, Profile: "H264High"},
			{Name: "p720", Bitrate: 3000000, Width: 1280, Height: 720, FPS: 24, Profile: "H264High"},
		},
		LocalBroadcaster: nil,
		TranscodeTimeout: 6 * time.Second,
		ApiTimeout:       2 * time.Second,
	}
	manifestId, err := transcode.CreateStream(request)
	require.NoError(t, err)
	defer transcode.ReleaseManifestId(request, manifestId)
	encoded, err := transcode.TranscodeSegment(request, manifestId)
	require.NoError(t, err)
	for _, rendition := range encoded.Renditions {
		fmt.Printf("> got rendition name=%s url=%v data=%d\n", rendition.Name, rendition.MediaUrl, len(rendition.MediaData))
		err = os.WriteFile(fmt.Sprintf("./rendition_%s.ts", rendition.Name), rendition.MediaData, 0666)
		require.NoError(t, err)
	}
}

@codecov
Copy link

codecov bot commented Oct 27, 2022

Codecov Report

Merging #92 (d6d902e) into main (6fa7738) will decrease coverage by 7.77921%.
The diff coverage is 0.00000%.

Impacted file tree graph

@@                 Coverage Diff                 @@
##                main         #92         +/-   ##
===================================================
- Coverage   46.77996%   39.00075%   -7.77921%     
===================================================
  Files             21          24          +3     
  Lines           1118        1341        +223     
===================================================
  Hits             523         523                 
- Misses           533         756        +223     
  Partials          62          62                 
Impacted Files Coverage Δ
cache/transcoding.go 60.25641% <ø> (ø)
clients/broadcaster.go 0.00000% <0.00000%> (ø)
clients/broadcaster_local.go 0.00000% <0.00000%> (ø)
clients/broadcaster_remote.go 0.00000% <0.00000%> (ø)
handlers/transcode.go 42.30769% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fa7738...d6d902e. Read the comment docs.

Impacted Files Coverage Δ
cache/transcoding.go 60.25641% <ø> (ø)
clients/broadcaster.go 0.00000% <0.00000%> (ø)
clients/broadcaster_local.go 0.00000% <0.00000%> (ø)
clients/broadcaster_remote.go 0.00000% <0.00000%> (ø)
handlers/transcode.go 42.30769% <ø> (ø)

@thomshutt thomshutt merged commit d95d823 into main Oct 27, 2022
@thomshutt thomshutt deleted the ak/direct_transcode branch October 27, 2022 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants