From adfa5beab97db4022d421e43379deec03dd815aa Mon Sep 17 00:00:00 2001 From: Josh Allmann Date: Fri, 20 Mar 2020 06:19:53 -0700 Subject: [PATCH] core: Make the naming of video temp files explicit. The extension doesn't matter, and may no longer be mpegts. --- core/core_test.go | 7 ++++++- core/orchestrator.go | 4 ++-- core/transcoder.go | 2 +- core/transcoder_test.go | 14 ++++++-------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/core_test.go b/core/core_test.go index 52dd35febb..f9deeb4432 100644 --- a/core/core_test.go +++ b/core/core_test.go @@ -32,7 +32,12 @@ func StubJobId() int64 { return int64(1234) } -var videoProfiles = []ffmpeg.VideoProfile{ffmpeg.P144p30fps16x9, ffmpeg.P240p30fps16x9} +var videoProfiles = func() []ffmpeg.VideoProfile { + p := []ffmpeg.VideoProfile{ffmpeg.P144p30fps16x9, ffmpeg.P240p30fps16x9} + p[0].Format = ffmpeg.FormatMPEGTS + p[1].Format = ffmpeg.FormatMPEGTS + return p +}() func TestTranscode(t *testing.T) { //Set up the node diff --git a/core/orchestrator.go b/core/orchestrator.go index 15a2cbf960..81f4b5bbf7 100644 --- a/core/orchestrator.go +++ b/core/orchestrator.go @@ -464,7 +464,7 @@ func (n *LivepeerNode) transcodeSeg(config transcodeConfig, seg *stream.HLSSegme // we may still end up doing work multiple times. But this is OK for now. //Assume d is in the right format, write it to disk - inName := common.RandName() + ".ts" + inName := common.RandName() + ".tempfile" if _, err := os.Stat(n.WorkDir); os.IsNotExist(err) { err := os.Mkdir(n.WorkDir, 0700) if err != nil { @@ -498,7 +498,7 @@ func (n *LivepeerNode) transcodeSeg(config transcodeConfig, seg *stream.HLSSegme } else { // Need to store segment in our local OS var err error - name := fmt.Sprintf("%d.ts", seg.SeqNo) + name := fmt.Sprintf("%d.tempfile", seg.SeqNo) url, err = config.LocalOS.SaveData(name, seg.Data) if err != nil { return terr(err) diff --git a/core/transcoder.go b/core/transcoder.go index 5bc891b4ed..db4812c4cc 100644 --- a/core/transcoder.go +++ b/core/transcoder.go @@ -212,7 +212,7 @@ func profilesToTranscodeOptions(workDir string, accel ffmpeg.Acceleration, profi opts := make([]ffmpeg.TranscodeOptions, len(profiles), len(profiles)) for i := range profiles { o := ffmpeg.TranscodeOptions{ - Oname: fmt.Sprintf("%s/out_%s.ts", workDir, common.RandName()), + Oname: fmt.Sprintf("%s/out_%s.tempfile", workDir, common.RandName()), Profile: profiles[i], Accel: accel, AudioEncoder: ffmpeg.ComponentOptions{Name: "copy"}, diff --git a/core/transcoder_test.go b/core/transcoder_test.go index feb145d145..d9c3d71a11 100644 --- a/core/transcoder_test.go +++ b/core/transcoder_test.go @@ -19,12 +19,11 @@ func TestLocalTranscoder(t *testing.T) { tc := NewLocalTranscoder(tmp) ffmpeg.InitFFmpeg() - profiles := []ffmpeg.VideoProfile{ffmpeg.P144p30fps16x9, ffmpeg.P240p30fps16x9} - res, err := tc.Transcode("", "test.ts", profiles) + res, err := tc.Transcode("", "test.ts", videoProfiles) if err != nil { t.Error("Error transcoding ", err) } - if len(res.Segments) != len(profiles) { + if len(res.Segments) != len(videoProfiles) { t.Error("Mismatched results") } if Over1Pct(len(res.Segments[0].Data), 164876) { @@ -232,7 +231,7 @@ func TestProfilesToTranscodeOptions(t *testing.T) { profiles = []ffmpeg.VideoProfile{ffmpeg.P144p30fps16x9} opts = profilesToTranscodeOptions(workDir, ffmpeg.Software, profiles) assert.Equal(1, len(opts)) - assert.Equal("foo/out_bar.ts", opts[0].Oname) + assert.Equal("foo/out_bar.tempfile", opts[0].Oname) assert.Equal(ffmpeg.Software, opts[0].Accel) assert.Equal(ffmpeg.P144p30fps16x9, opts[0].Profile) assert.Equal("copy", opts[0].AudioEncoder.Name) @@ -243,7 +242,7 @@ func TestProfilesToTranscodeOptions(t *testing.T) { assert.Equal(2, len(opts)) for i, p := range profiles { - assert.Equal("foo/out_bar.ts", opts[i].Oname) + assert.Equal("foo/out_bar.tempfile", opts[i].Oname) assert.Equal(ffmpeg.Software, opts[i].Accel) assert.Equal(p, opts[i].Profile) assert.Equal("copy", opts[i].AudioEncoder.Name) @@ -254,7 +253,7 @@ func TestProfilesToTranscodeOptions(t *testing.T) { assert.Equal(2, len(opts)) for i, p := range profiles { - assert.Equal("foo/out_bar.ts", opts[i].Oname) + assert.Equal("foo/out_bar.tempfile", opts[i].Oname) assert.Equal(ffmpeg.Nvidia, opts[i].Accel) assert.Equal(p, opts[i].Profile) assert.Equal("copy", opts[i].AudioEncoder.Name) @@ -281,8 +280,7 @@ func TestAudioCopy(t *testing.T) { _, err := ffmpeg.Transcode3(in, out) assert.Nil(err) - profs := []ffmpeg.VideoProfile{ffmpeg.P720p30fps16x9} // dummy - res, err := tc.Transcode("", audioSample, profs) + res, err := tc.Transcode("", audioSample, videoProfiles) assert.Nil(err) o, err := ioutil.ReadFile(audioSample)