Skip to content

Commit

Permalink
core: Make the naming of video temp files explicit.
Browse files Browse the repository at this point in the history
The extension doesn't matter, and may no longer be mpegts.
  • Loading branch information
j0sh committed Apr 9, 2020
1 parent 37db400 commit adfa5be
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
7 changes: 6 additions & 1 deletion core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/transcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
14 changes: 6 additions & 8 deletions core/transcoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit adfa5be

Please sign in to comment.