-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement save to disk for h264 video stream (#27)
* Add 'save_video' global flag * Handle 'save_video' flag * Move keyframer to its own pkg * Rename 'thumbnailer.go' -> 'thumbnail.go' * Implement h264 file writer * Move to ingest.go
- Loading branch information
Showing
10 changed files
with
235 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package control | ||
|
||
import "github.com/Glimesh/waveguide/pkg/disk" | ||
|
||
func (s *Stream) configureVideoWriter(codec string) { | ||
videoWriter := disk.NewNoopVideoWriter() | ||
if s.saveVideo { | ||
if vw, err := disk.NewVideoWriter(codec, "out.h264"); err == nil { | ||
videoWriter = vw | ||
} else { | ||
s.log.Debug("video save enabled but failed to create video writer") | ||
s.log.Warnf("video writer: %v", err) | ||
s.log.Debug("falling back to noop video writer") | ||
} | ||
} | ||
s.videoWriter = videoWriter | ||
} | ||
|
||
func (s *Stream) writer(done chan struct{}) { | ||
s.log.Debug("starting file writer") | ||
LOOP: | ||
for { | ||
select { | ||
case <-done: | ||
break LOOP | ||
case p := <-s.videoWriterChan: | ||
if err := s.videoWriter.WriteVideo(p); err != nil { | ||
s.log.Debugf("writer: %v", err) | ||
break LOOP | ||
} | ||
} | ||
} | ||
s.log.Debug("ending writer") | ||
s.videoWriter.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package control | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/pion/rtp" | ||
) | ||
|
||
func (s *Stream) thumbnailer(done chan struct{}) { | ||
OUTER: | ||
for { | ||
s.log.Debug("waiting for thumbnail request signal") | ||
select { | ||
case <-s.requestThumbnail: | ||
case <-done: | ||
break OUTER | ||
} | ||
s.log.Debug("thumbnail request received") | ||
|
||
for len(s.thumbnailReceiver) > 0 { | ||
<-s.thumbnailReceiver | ||
} | ||
s.log.Debug("thumbnail buffer drained") | ||
|
||
var pkt *rtp.Packet | ||
|
||
t := time.Now() | ||
INNER: | ||
for { | ||
select { | ||
case pkt = <-s.thumbnailReceiver: | ||
case <-done: | ||
s.log.Debug("stopping thumbnail receiver") | ||
break OUTER | ||
} | ||
|
||
select { | ||
case <-done: | ||
break OUTER | ||
default: | ||
// use a deadline of 10 seconds to retrieve a keyframe | ||
if time.Since(t) > time.Second*10 { | ||
s.log.Warn("keyframe not available") | ||
break INNER | ||
} | ||
keyframe := s.kf.GetKeyframe(pkt) | ||
if keyframe != nil { | ||
s.log.Debug("got keyframe") | ||
s.lastThumbnail <- keyframe | ||
s.log.Debug("sent keyframe") | ||
// reset and sleep after sending one keyframe | ||
s.kf.Reset() | ||
break INNER | ||
} | ||
} | ||
} | ||
} | ||
s.log.Debug("ending thumbnailer") | ||
} |
Oops, something went wrong.