Added checks for videos with no audio

This commit is contained in:
Alex Eidt 2022-04-01 17:00:53 -07:00
parent 22247d6492
commit abdeecf6e4
2 changed files with 30 additions and 12 deletions

View file

@ -50,19 +50,35 @@ func parseFFprobe(input []byte) map[string]string {
// Adds Video data to the video struct from the ffprobe output. // Adds Video data to the video struct from the ffprobe output.
func addVideoData(data map[string]string, video *Video) { func addVideoData(data map[string]string, video *Video) {
video.width = int(parse(data["width"])) if width, ok := data["width"]; ok {
video.height = int(parse(data["height"])) video.width = int(parse(width))
video.duration = float64(parse(data["duration"])) }
video.frames = int(parse(data["nb_frames"])) if height, ok := data["height"]; ok {
video.height = int(parse(height))
split := strings.Split(data["r_frame_rate"], "/") }
if len(split) == 2 && split[0] != "" && split[1] != "" { if duration, ok := data["duration"]; ok {
video.fps = parse(split[0]) / parse(split[1]) video.duration = float64(parse(duration))
}
if frames, ok := data["nb_frames"]; ok {
video.frames = int(parse(frames))
} }
video.bitrate = int(parse(data["bit_rate"])) if fps, ok := data["r_frame_rate"]; ok {
video.codec = data["codec_name"] split := strings.Split(fps, "/")
video.pix_fmt = data["pix_fmt"] if len(split) == 2 && split[0] != "" && split[1] != "" {
video.fps = parse(split[0]) / parse(split[1])
}
}
if bitrate, ok := data["bit_rate"]; ok {
video.bitrate = int(parse(bitrate))
}
if codec, ok := data["codec_name"]; ok {
video.codec = codec
}
if pix_fmt, ok := data["pix_fmt"]; ok {
video.pix_fmt = pix_fmt
}
} }
// Parses the given data into a float64. // Parses the given data into a float64.

View file

@ -79,7 +79,9 @@ func NewVideo(filename string) *Video {
video := &Video{filename: filename, depth: 3} video := &Video{filename: filename, depth: 3}
addVideoData(videoData, video) addVideoData(videoData, video)
video.audio_codec = audioData["codec_name"] if audio_codec, ok := audioData["codec_name"]; ok {
video.audio_codec = audio_codec
}
return video return video
} }