Skip to content

Commit

Permalink
ffmpeg: Throw error instead of bypassing for audio-only stream
Browse files Browse the repository at this point in the history
  • Loading branch information
jailuthra committed Sep 24, 2020
1 parent dddf135 commit d5c85d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
4 changes: 3 additions & 1 deletion ffmpeg/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,9 @@ func audioOnlySegment(t *testing.T, accel Acceleration) {
Accel: accel,
}}
_, err := tc.Transcode(in, out)
if err != nil {
if i == 2 && (err == nil || err.Error() != "No video parameters found while initializing stream") {
t.Error("Expected to fail for audio-only segment but did not")
} else if i != 2 && err != nil {
t.Error(err)
}
}
Expand Down
31 changes: 3 additions & 28 deletions ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ func (t *Transcoder) Transcode(input *TranscodeOptionsIn, ps []TranscodeOptions)
if !t.started {
ret := int(C.lpms_is_bypass_needed(C.CString(input.Fname)))
if ret != 1 {
// no bypass needed, continue
// Stream is either OK or completely broken, let the transcoder handle it
t.started = true
} else {
// audio-only segment, bypassed transcoding
return bypassTranscoding(input, ps)
// Audio-only segment, fail fast right here as we cannot handle them nicely
return nil, errors.New("No video parameters found while initializing stream")
}
}
fname := C.CString(input.Fname)
Expand Down Expand Up @@ -377,31 +377,6 @@ func (t *Transcoder) Transcode(input *TranscodeOptionsIn, ps []TranscodeOptions)
return &TranscodeResults{Encoded: tr, Decoded: dec}, nil
}

// Force copy-transcoding for audio-only segments
func bypassTranscoding(input *TranscodeOptionsIn, ps []TranscodeOptions) (*TranscodeResults, error) {
glog.Warningf("Input %s has audio & video streams but no video frames. Bypassing the transcoder.", input.Fname)
for i, p := range ps {
if p.Profile != (VideoProfile{}) && p.Profile.Format != FormatMP4 {
// we only bypass when a VideoProfile is set (i.e. not a copy/drop) and output format
// is mpegts.
// FIXME: Temporary fix. The transcoder is not the place for such hacky code
p.Profile = VideoProfile{Name: p.Profile.Name, Format: FormatMPEGTS}
if "drop" != p.VideoEncoder.Name && "copy" != p.VideoEncoder.Name {
p.VideoEncoder = ComponentOptions{Name: "copy"}
}
if "drop" != p.AudioEncoder.Name && "copy" != p.AudioEncoder.Name {
p.AudioEncoder = ComponentOptions{Name: "copy"}
}
ps[i] = p
}
}
// use a new thread to transcode
t := NewTranscoder()
t.started = true
defer t.StopTranscoder()
return t.Transcode(input, ps)
}

func NewTranscoder() *Transcoder {
return &Transcoder{
handle: C.lpms_transcode_new(),
Expand Down

0 comments on commit d5c85d8

Please sign in to comment.