fixes (desc)
Some checks failed
telegram message / notify (push) Has been cancelled

- m3u8 parser
- segments download
- video-audio merge
This commit is contained in:
stefanodvx 2025-04-23 01:44:25 +02:00
parent 330cc39583
commit c8d0666d1d
5 changed files with 254 additions and 174 deletions

46
util/av/merge_segments.go Normal file
View file

@ -0,0 +1,46 @@
package av
import (
"fmt"
"os"
ffmpeg "github.com/u2takey/ffmpeg-go"
)
func MergeSegments(
segmentPaths []string,
outputPath string,
) (string, error) {
if len(segmentPaths) == 0 {
return "", fmt.Errorf("no segments to merge")
}
listFilePath := outputPath + ".segments.txt"
listFile, err := os.Create(listFilePath)
if err != nil {
return "", fmt.Errorf("failed to create segment list file: %w", err)
}
defer listFile.Close()
defer os.Remove(listFilePath)
for _, segmentPath := range segmentPaths {
fmt.Fprintf(listFile, "file '%s'\n", segmentPath)
}
err = ffmpeg.
Input(listFilePath, ffmpeg.KwArgs{
"f": "concat",
"safe": "0",
"protocol_whitelist": "file,pipe",
}).
Output(outputPath, ffmpeg.KwArgs{
"c": "copy",
"movflags": "+faststart",
}).
Silent(true).
OverWriteOutput().
Run()
if err != nil {
os.Remove(outputPath)
return "", fmt.Errorf("failed to merge segments: %w", err)
}
return outputPath, nil
}