diff --git a/provider/zencoder/zencoder.go b/provider/zencoder/zencoder.go index ff844191..3ed84556 100644 --- a/provider/zencoder/zencoder.go +++ b/provider/zencoder/zencoder.go @@ -98,7 +98,7 @@ func (z *zencoderProvider) buildOutputs(job *db.Job) ([]*zencoder.OutputSettings zencoderOutputs = append(zencoderOutputs, &zencoderOutput) } if hlsOutputs > 0 { - z.optimizeOutputsForHLS(zencoderOutputs) + zencoderOutputs, err := z.optimizeOutputsForHLS(zencoderOutputs) outputsWithHLSPlaylist := make([]*zencoder.OutputSettings, len(zencoderOutputs)+1) copy(outputsWithHLSPlaylist, zencoderOutputs) hlsPlaylist, err := z.buildHLSPlaylist(zencoderOutputs, hlsOutputs, job) @@ -106,41 +106,57 @@ func (z *zencoderProvider) buildOutputs(job *db.Job) ([]*zencoder.OutputSettings return nil, fmt.Errorf("Error building hls master playlist: %s", err.Error()) } outputsWithHLSPlaylist[len(zencoderOutputs)] = &hlsPlaylist - zencoderOutputs = outputsWithHLSPlaylist + return outputsWithHLSPlaylist, nil } return zencoderOutputs, nil } -func (z *zencoderProvider) optimizeOutputsForHLS(outputs []*zencoder.OutputSettings) { +func (z *zencoderProvider) optimizeOutputsForHLS(outputs []*zencoder.OutputSettings) ([]*zencoder.OutputSettings, error) { for i, hlsOutput := range outputs { if hlsOutput.Format == "ts" { for _, mp4Output := range outputs { - if mp4Output.Format == "mp4" && z.isOutputCompatible(hlsOutput, mp4Output) { - newHlsOutput := zencoder.OutputSettings{ - Filename: hlsOutput.Filename, - Label: hlsOutput.Label, - BaseUrl: hlsOutput.BaseUrl, - Format: hlsOutput.Format, - Source: mp4Output.Label, - CopyAudio: true, - CopyVideo: true, - Type: "segmented", + if mp4Output.Format == "mp4" { + isCompatible, err := z.isOutputCompatible(hlsOutput, mp4Output) + if err != nil { + return nil, err + } else if isCompatible { + newHlsOutput := zencoder.OutputSettings{ + Filename: hlsOutput.Filename, + Label: hlsOutput.Label, + BaseUrl: hlsOutput.BaseUrl, + Format: hlsOutput.Format, + Source: mp4Output.Label, + CopyAudio: true, + CopyVideo: true, + Type: "segmented", + } + outputs[i] = &newHlsOutput } - outputs[i] = &newHlsOutput } } } } + return outputs, nil } -func (z *zencoderProvider) isOutputCompatible(hlsOutput, mp4Output *zencoder.OutputSettings) bool { - localHlsPreset, _ := z.GetPreset(hlsOutput.Label) +func (z *zencoderProvider) isOutputCompatible(hlsOutput, mp4Output *zencoder.OutputSettings) (bool, error) { + localHlsPreset, err := z.GetPreset(hlsOutput.Label) + if err != nil { + return false, err + } hls := localHlsPreset.(*db.LocalPreset) localMp4Preset, _ := z.GetPreset(hlsOutput.Label) + if err != nil { + return false, err + } mp4 := localMp4Preset.(*db.LocalPreset) - return reflect.DeepEqual(hls.Preset.Video, mp4.Preset.Video) && reflect.DeepEqual(hls.Preset.Audio, mp4.Preset.Audio) && hls.Preset.RateControl == mp4.Preset.RateControl + isCompatible := reflect.DeepEqual(hls.Preset.Video, mp4.Preset.Video) && + reflect.DeepEqual(hls.Preset.Audio, mp4.Preset.Audio) && + hls.Preset.RateControl == mp4.Preset.RateControl + + return isCompatible, nil } func (z *zencoderProvider) buildHLSPlaylist(outputs []*zencoder.OutputSettings, hlsOutputs int, job *db.Job) (zencoder.OutputSettings, error) {