Trap exit code for ffmpeg
parent
5cb165d15f
commit
cbad0bb175
29
stream.go
29
stream.go
|
@ -524,6 +524,7 @@ func (s *Stream) transcode(startId int) {
|
||||||
|
|
||||||
go s.monitorTranscodeOutput(cmdStdOut, startAt)
|
go s.monitorTranscodeOutput(cmdStdOut, startAt)
|
||||||
go s.monitorStderr(cmdStdErr)
|
go s.monitorStderr(cmdStdErr)
|
||||||
|
go s.monitorExit()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stream) checkGoal(id int) {
|
func (s *Stream) checkGoal(id int) {
|
||||||
|
@ -617,9 +618,6 @@ func (s *Stream) monitorTranscodeOutput(cmdStdOut io.ReadCloser, startAt float64
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join the process
|
|
||||||
coder.Wait()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stream) monitorStderr(cmdStdErr io.ReadCloser) {
|
func (s *Stream) monitorStderr(cmdStdErr io.ReadCloser) {
|
||||||
|
@ -640,3 +638,28 @@ func (s *Stream) monitorStderr(cmdStdErr io.ReadCloser) {
|
||||||
log.Println("ffmpeg-error:", string(line))
|
log.Println("ffmpeg-error:", string(line))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Stream) monitorExit() {
|
||||||
|
// Join the process
|
||||||
|
coder := s.coder
|
||||||
|
err := coder.Wait()
|
||||||
|
|
||||||
|
// Try to get exit status
|
||||||
|
if exitError, ok := err.(*exec.ExitError); ok {
|
||||||
|
exitcode := exitError.ExitCode()
|
||||||
|
log.Printf("%s-%s: ffmpeg exited with status: %d", s.m.id, s.quality, exitcode)
|
||||||
|
|
||||||
|
s.mutex.Lock()
|
||||||
|
defer s.mutex.Unlock()
|
||||||
|
|
||||||
|
// If error code is >0, there was an error in transcoding
|
||||||
|
if exitcode > 0 && s.coder == coder {
|
||||||
|
// Notify all outstanding chunks
|
||||||
|
for _, chunk := range s.chunks {
|
||||||
|
for _, n := range chunk.notifs {
|
||||||
|
n <- true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue