8000 add duration check for input files by ad-astra-video · Pull Request #434 · livepeer/lpms · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add duration check for input files #434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var ErrTranscoderHw = errors.New("TranscoderInvalidHardware")
var ErrTranscoderInp = errors.New("TranscoderInvalidInput")
var ErrTranscoderClipConfig = errors.New("TranscoderInvalidClipConfig")
var ErrTranscoderVid = errors.New("TranscoderInvalidVideo")
var ErrTranscoderDuration = errors.New("TranscoderInvalidDuration")
var ErrTranscoderStp = errors.New("TranscoderStopped")
var ErrTranscoderFmt = errors.New("TranscoderUnrecognizedFormat")
var ErrTranscoderPrf = errors.New("TranscoderUnrecognizedProfile")
Expand Down Expand Up @@ -880,6 +881,10 @@ func (t *Transcoder) Transcode(input *TranscodeOptionsIn, ps []TranscodeOptions)
if err != nil {
return nil, err
}
if format.DurSecs > 300 {
glog.Errorf("Input file %s has duration of %d seconds, which is more than 5 minutes. This is not supported by the transcoder.", input.Fname, format.DurSecs)
return nil, ErrTranscoderDuration
}
// TODO hoist the rest of this into C so we don't have to invoke GetCodecInfo
if !t.started {
// NeedsBypass is state where video is present in container & without any frames
Expand Down
43 changes: 43 additions & 0 deletions ffmpeg/ffmpeg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ffmpeg
import (
"bufio"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
Expand Down Expand Up @@ -2424,3 +2425,45 @@ func TestTranscoder_PNGDemuxerOpts(t *testing.T) {
assert.Equal(t, 3, res.Decoded.Frames)
assert.Equal(t, 180, res.Encoded[0].Frames)
}

func TestTranscode_DurationLimit(t *testing.T) {
run, dir := setupTest(t)
defer os.RemoveAll(dir)
cmd := `
# generate a 1fps sample
ffmpeg -i "$1"/../transcoder/test.ts -c copy -bsf:v setts=ts=N/TB/1 -frames:v 301 -y test.ts
# double check the sample actually has the characteristics we expect
ffprobe -show_format test.ts | grep duration=301.00
`
run(cmd)

// Set up transcode options
fileInput := &TranscodeOptionsIn{
Fname: fmt.Sprintf("%v/test.ts", dir),
}
options := []TranscodeOptions{
{
Oname: fmt.Sprintf("%s/out-test.ts", dir),
VideoEncoder: ComponentOptions{Name: "copy"},
AudioEncoder: ComponentOptions{Name: "copy"},
Muxer: ComponentOptions{Name: "md5"},
},
}

// transcode long input from file, should error out
_, err := Transcode3(fileInput, options)
assert.Equal(t, ErrTranscoderDuration, err)

// transcode long input from pipe, should *not* error out
ir, iw, err := os.Pipe()
go func(iw *os.File) {
defer iw.Close()
f, _ := os.Open(fileInput.Fname)
io.Copy(iw, f)
}(iw)
pipeInput := &TranscodeOptionsIn{
Fname: fmt.Sprintf("pipe:%d", ir.Fd()),
}
_, err = Transcode3(pipeInput, options)
assert.Nil(t, err)
}
Loading
0