flv stream data handling, temporary dump to a file instead of ffmpeg
This commit is contained in:
parent
050e8b104f
commit
cbf1492b0e
2 changed files with 48 additions and 0 deletions
|
@ -2,9 +2,14 @@ package rtmp
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"stream_server/rtmp/flv"
|
||||
)
|
||||
|
||||
func HandleDataLoop(chnk_wrp_ptr *ChunkWrapper) {
|
||||
file_writer, err := flv.NewFLVWriter(chnk_wrp_ptr.params.stream_key)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for {
|
||||
p, err := chnk_wrp_ptr.ReadChunk()
|
||||
if err != nil {
|
||||
|
@ -14,4 +19,5 @@ func HandleDataLoop(chnk_wrp_ptr *ChunkWrapper) {
|
|||
fmt.Println(p.msg_type, p.msg_len)
|
||||
}
|
||||
}
|
||||
file_writer.Close()
|
||||
}
|
||||
|
|
42
rtmp/flv/writer.go
Normal file
42
rtmp/flv/writer.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package flv
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
type FLVWriter struct {
|
||||
W io.Writer
|
||||
curr_offset int
|
||||
}
|
||||
|
||||
func NewFLVWriter(stream_dir string) (*FLVWriter, error) {
|
||||
writer := new(FLVWriter)
|
||||
base_dir, _ := os.UserHomeDir()
|
||||
filepipe, err := os.Create(base_dir + "/live/" + stream_dir + "/stream.flv")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
writer.W = filepipe
|
||||
if err = writer.write_flv_header(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writer, nil
|
||||
}
|
||||
|
||||
func (writer *FLVWriter) Close() (error) {
|
||||
return writer.W.(*os.File).Close()
|
||||
}
|
||||
|
||||
func (writer *FLVWriter) write_flv_header() (err error) {
|
||||
header := make([]byte, 13)
|
||||
copy(header[:3], "FLV")
|
||||
header[3] = 1
|
||||
header[4] = 5
|
||||
header[8] = 9
|
||||
|
||||
n, err := writer.W.Write(header)
|
||||
writer.curr_offset += n
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in a new issue