Improve process .insit files.
This commit is contained in:
parent
f9b0103471
commit
7f51f19c6f
@ -8,6 +8,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"reader/internal/config"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -22,21 +23,14 @@ import (
|
||||
)
|
||||
|
||||
// CreateVideo generate TS files and M3U8 playlists.
|
||||
func CreateVideo(dir string) error {
|
||||
// Check if the data folder in the directory.
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dirData := fmt.Sprintf("%s/%s/vod", homeDir, dir)
|
||||
|
||||
exist := storage.Exists(dirData)
|
||||
func CreateVideo() error {
|
||||
exist := storage.Exists(config.DirData)
|
||||
if !exist {
|
||||
return errors.New("directory does not exist")
|
||||
}
|
||||
|
||||
// Read directory.
|
||||
files, err := storage.ReadDir(dirData)
|
||||
files, err := storage.ReadDir(config.DirData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -44,11 +38,13 @@ func CreateVideo(dir string) error {
|
||||
for _, file := range files {
|
||||
// Create logger.
|
||||
cam := log2.CamLogging(
|
||||
fmt.Sprintf("%s/%s/log/reader-cam_%s.log", dirData, file.Name(), strconv.FormatInt(time.Now().Unix(), 10)))
|
||||
fmt.Sprintf("%s/%s/log/reader-cam_%s.log", config.DirData, file.Name(), strconv.FormatInt(time.Now().Unix(), 10)))
|
||||
|
||||
res, err := storage.ReadDir(fmt.Sprintf("%s/%s", dirData, file.Name()))
|
||||
res, err := storage.ReadDir(fmt.Sprintf("%s/%s", config.DirData, file.Name()))
|
||||
if err != nil {
|
||||
cam.Error("error reading directory", zap.String("dir", dir), zap.Error(err))
|
||||
cam.Error(
|
||||
"error reading directory",
|
||||
zap.String("dir", fmt.Sprintf("%s/%s", config.DirData, file.Name())), zap.Error(err))
|
||||
return err
|
||||
}
|
||||
resolutions := make([]string, 0)
|
||||
@ -66,22 +62,31 @@ func CreateVideo(dir string) error {
|
||||
period := time.Duration(per)
|
||||
|
||||
// Create M3U8 playlist.
|
||||
go gen.MediaPlaylistGenerator(dirData, file.Name(), float64(period), resolutions, cam)
|
||||
go gen.MediaPlaylistGenerator(config.DirData, file.Name(), float64(period), resolutions, cam)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
for _, resolution := range resolutions {
|
||||
filenames := gen.StringDirEntryList(
|
||||
fmt.Sprintf("%s/%s/%s", dirData, file.Name(), resolution), "insit", logger.Log)
|
||||
fmt.Sprintf("%s/%s/%s", config.DirData, file.Name(), resolution), "insit", logger.Log)
|
||||
if len(filenames) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
for i := len(filenames) - 2; i < len(filenames)-1; i++ {
|
||||
// Setup MPEG-TS muxer.
|
||||
var h264Format format.H264
|
||||
var aacFormat format.MPEG4Audio
|
||||
|
||||
currentMpegTSMuxer := processor.MpegTSMuxer{
|
||||
H264Format: &h264Format,
|
||||
Mpeg4AudioFormat: &aacFormat,
|
||||
}
|
||||
|
||||
for i := len(filenames) - 6; i < len(filenames)-1; i++ {
|
||||
segment := storage.Segment{}
|
||||
|
||||
// Open file for reading.
|
||||
f, err := os.Open(fmt.Sprintf("%s/%s/%s/%s", dirData, file.Name(), resolution, filenames[i]))
|
||||
f, err := os.Open(fmt.Sprintf("%s/%s/%s/%s", config.DirData, file.Name(), resolution, filenames[i]))
|
||||
if err != nil {
|
||||
cam.Error(
|
||||
"opening file error for file:", zap.String("filename", filenames[i]), zap.Error(err))
|
||||
@ -134,18 +139,9 @@ func CreateVideo(dir string) error {
|
||||
return
|
||||
}
|
||||
|
||||
// Setup MPEG-TS muxer.
|
||||
var h264Format format.H264
|
||||
var aacFormat format.MPEG4Audio
|
||||
|
||||
filename, _ := strings.CutSuffix(filenames[i], ".insit")
|
||||
tsFilename := fmt.Sprintf("%s/%s/%s/%s.ts", dirData, file.Name(), resolution, filename)
|
||||
|
||||
currentMpegTSMuxer := processor.MpegTSMuxer{
|
||||
FileName: tsFilename,
|
||||
H264Format: &h264Format,
|
||||
Mpeg4AudioFormat: &aacFormat,
|
||||
}
|
||||
tsFilename := fmt.Sprintf("%s/%s/%s/%s.ts", config.DirData, file.Name(), resolution, filename)
|
||||
currentMpegTSMuxer.FileName = tsFilename
|
||||
|
||||
err = currentMpegTSMuxer.Initialize()
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user