commit
05cff486bc
1 changed files with 7 additions and 13 deletions
20
video.go
20
video.go
|
@ -24,7 +24,7 @@ type Video struct {
|
|||
hasstreams bool // Flag storing whether file has additional data streams.
|
||||
framebuffer []byte // Raw frame data.
|
||||
metadata map[string]string // Video metadata.
|
||||
pipe *io.ReadCloser // Stdout pipe for ffmpeg process.
|
||||
pipe io.ReadCloser // Stdout pipe for ffmpeg process.
|
||||
cmd *exec.Cmd // ffmpeg command.
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ func (video *Video) init() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
video.pipe = &pipe
|
||||
video.pipe = pipe
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return err
|
||||
|
@ -232,23 +232,17 @@ func (video *Video) Read() bool {
|
|||
}
|
||||
}
|
||||
|
||||
total := 0
|
||||
for total < video.width*video.height*video.depth {
|
||||
n, err := (*video.pipe).Read(video.framebuffer[total:])
|
||||
if err == io.EOF {
|
||||
video.Close()
|
||||
return false
|
||||
}
|
||||
total += n
|
||||
if _, err := io.ReadFull(video.pipe, video.framebuffer); err != nil {
|
||||
video.Close()
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Closes the pipe and stops the ffmpeg process.
|
||||
func (video *Video) Close() {
|
||||
if video.pipe != nil {
|
||||
(*video.pipe).Close()
|
||||
video.pipe.Close()
|
||||
}
|
||||
if video.cmd != nil {
|
||||
video.cmd.Wait()
|
||||
|
@ -263,7 +257,7 @@ func (video *Video) cleanup() {
|
|||
go func() {
|
||||
<-c
|
||||
if video.pipe != nil {
|
||||
(*video.pipe).Close()
|
||||
video.pipe.Close()
|
||||
}
|
||||
if video.cmd != nil {
|
||||
video.cmd.Process.Kill()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue