Skip to content
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

probe: add check for jpeg/mpeg type of inputs #451

Merged
merged 2 commits into from
Feb 12, 2023
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
16 changes: 12 additions & 4 deletions video/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ type Prober interface {
ProbeFile(url string) (InputVideo, error)
}

type Probe struct {
}
type Probe struct{}

func (p Probe) ProbeFile(url string) (iv InputVideo, err error) {
var data *ffprobe.ProbeData
Expand All @@ -39,11 +38,20 @@ func (p Probe) ProbeFile(url string) (iv InputVideo, err error) {
}

func parseProbeOutput(probeData *ffprobe.ProbeData) (InputVideo, error) {
// parse bitrate
// check for a valid video stream
videoStream := probeData.FirstVideoStream()
if videoStream == nil {
return InputVideo{}, errors.New("error probing mp4 input file from s3: no video stream found")
return InputVideo{}, errors.New("error checking for video: no video stream found")
}
// check for unsupported video stream(s)
if strings.ToLower(videoStream.CodecName) == "mjpeg" || strings.ToLower(videoStream.CodecName) == "jpeg" {
return InputVideo{}, fmt.Errorf("error checking for video: %s is not supported", videoStream.CodecName)
}
// We rely on this being present to get required information about the input video, so error out if it isn't
if probeData.Format == nil {
return InputVideo{}, fmt.Errorf("error parsing input video: format information missing")
}
// parse bitrate
bitRateValue := videoStream.BitRate
if bitRateValue == "" {
bitRateValue = probeData.Format.BitRate
Expand Down
52 changes: 52 additions & 0 deletions video/probe_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package video

import (
"testing"

"github.com/stretchr/testify/require"
"gopkg.in/vansante/go-ffprobe.v2"
)

func TestItRejectsWhenNoVideoTrackPresent(t *testing.T) {
_, err := parseProbeOutput(&ffprobe.ProbeData{
Streams: []*ffprobe.Stream{
{
CodecType: "audio",
},
},
})
require.ErrorContains(t, err, "no video stream found")
}

func TestItRejectsWhenMJPEGVideoTrackPresent(t *testing.T) {
_, err := parseProbeOutput(&ffprobe.ProbeData{
Streams: []*ffprobe.Stream{
{
CodecType: "video",
CodecName: "mjpeg",
},
},
})
require.ErrorContains(t, err, "mjpeg is not supported")

_, err = parseProbeOutput(&ffprobe.ProbeData{
Streams: []*ffprobe.Stream{
{
CodecType: "video",
CodecName: "jpeg",
},
},
})
require.ErrorContains(t, err, "jpeg is not supported")
}

func TestItRejectsWhenVideoBitrateMissing(t *testing.T) {
_, err := parseProbeOutput(&ffprobe.ProbeData{
Streams: []*ffprobe.Stream{
{
CodecType: "video",
},
},
})
require.ErrorContains(t, err, "format information missing")
}