Added checks for videos with no audio
This commit is contained in:
parent
22247d6492
commit
abdeecf6e4
2 changed files with 30 additions and 12 deletions
32
utils.go
32
utils.go
|
@ -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))
|
||||||
|
}
|
||||||
|
if duration, ok := data["duration"]; ok {
|
||||||
|
video.duration = float64(parse(duration))
|
||||||
|
}
|
||||||
|
if frames, ok := data["nb_frames"]; ok {
|
||||||
|
video.frames = int(parse(frames))
|
||||||
|
}
|
||||||
|
|
||||||
split := strings.Split(data["r_frame_rate"], "/")
|
if fps, ok := data["r_frame_rate"]; ok {
|
||||||
|
split := strings.Split(fps, "/")
|
||||||
if len(split) == 2 && split[0] != "" && split[1] != "" {
|
if len(split) == 2 && split[0] != "" && split[1] != "" {
|
||||||
video.fps = parse(split[0]) / parse(split[1])
|
video.fps = parse(split[0]) / parse(split[1])
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
video.bitrate = int(parse(data["bit_rate"]))
|
if bitrate, ok := data["bit_rate"]; ok {
|
||||||
video.codec = data["codec_name"]
|
video.bitrate = int(parse(bitrate))
|
||||||
video.pix_fmt = data["pix_fmt"]
|
}
|
||||||
|
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.
|
||||||
|
|
4
video.go
4
video.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue