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 }