mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Fix file collisions
This commit is contained in:
parent
a99317cce4
commit
2ae26d108d
@ -18,8 +18,8 @@ func NewAudioStream(file *FileStream, idx int32) *AudioStream {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (as *AudioStream) getSegmentName() string {
|
||||
return fmt.Sprintf("segment-a-%d-%%d.m4s", as.index)
|
||||
func (as *AudioStream) getIdentifier() string {
|
||||
return fmt.Sprintf("a%d", as.index)
|
||||
}
|
||||
|
||||
func (as *AudioStream) getFlags() Flags {
|
||||
|
@ -89,7 +89,7 @@ func (fs *FileStream) GetMaster() string {
|
||||
}
|
||||
master += "AUDIO=\"audio\","
|
||||
master += "CLOSED-CAPTIONS=NONE\n"
|
||||
master += fmt.Sprintf("./%s/index.m3u8\n", Original)
|
||||
master += fmt.Sprintf("%s/index.m3u8\n", Original)
|
||||
}
|
||||
|
||||
aspectRatio := float32(fs.Info.Video.Width) / float32(fs.Info.Video.Height)
|
||||
@ -110,7 +110,7 @@ func (fs *FileStream) GetMaster() string {
|
||||
master += fmt.Sprintf("CODECS=\"%s\",", transmux_codec)
|
||||
master += "AUDIO=\"audio\","
|
||||
master += "CLOSED-CAPTIONS=NONE\n"
|
||||
master += fmt.Sprintf("./%s/index.m3u8\n", quality)
|
||||
master += fmt.Sprintf("%s/index.m3u8\n", quality)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -130,7 +130,7 @@ func (fs *FileStream) GetMaster() string {
|
||||
if audio.IsDefault {
|
||||
master += "DEFAULT=YES,"
|
||||
}
|
||||
master += fmt.Sprintf("URI=\"./audio/%d/index.m3u8\"\n", audio.Index)
|
||||
master += fmt.Sprintf("URI=\"audio/%d/index.m3u8\"\n", audio.Index)
|
||||
}
|
||||
return master
|
||||
}
|
||||
|
@ -24,11 +24,17 @@ const (
|
||||
|
||||
type StreamHandle interface {
|
||||
getTranscodeArgs(segments string) []string
|
||||
getSegmentName() string
|
||||
getIdentifier() string
|
||||
getFlags() Flags
|
||||
GetIndex() (string, error)
|
||||
}
|
||||
|
||||
// First %d is encoder_id, second %d is segment number (escaped for ffmpeg)
|
||||
const (
|
||||
SegmentNameFormat = "%d-segment-%%d.m4s"
|
||||
InitNameFormat = "%d-init.mp4"
|
||||
)
|
||||
|
||||
type Stream struct {
|
||||
handle StreamHandle
|
||||
file *FileStream
|
||||
@ -213,8 +219,7 @@ func (ts *Stream) run(start int32) error {
|
||||
segments = []float64{9999999}
|
||||
}
|
||||
|
||||
outpath := fmt.Sprintf("%s/%d", ts.file.Out, encoder_id)
|
||||
fmt.Print(outpath)
|
||||
outpath := fmt.Sprintf("%s/%s", ts.file.Out, ts.handle.getIdentifier())
|
||||
err := os.MkdirAll(outpath, 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -271,8 +276,8 @@ func (ts *Stream) run(start int32) error {
|
||||
"-hls_time", fmt.Sprint(OptimalFragmentDuration),
|
||||
"-start_number", fmt.Sprint(start_segment),
|
||||
"-hls_segment_type", "fmp4",
|
||||
"-hls_fmp4_init_filename", fmt.Sprintf("%s/init.mp4", outpath),
|
||||
"-hls_segment_filename", fmt.Sprintf("%s/%s", outpath, ts.handle.getSegmentName()),
|
||||
"-hls_fmp4_init_filename", fmt.Sprintf("%s/%s", outpath, fmt.Sprintf(InitNameFormat, encoder_id)),
|
||||
"-hls_segment_filename", fmt.Sprintf("%s/%s", outpath, fmt.Sprintf(SegmentNameFormat, encoder_id)),
|
||||
// Make the playlist easier to parse in our program by only outputing 1 segment and no endlist marker
|
||||
// anyways this list is only read once and we generate our own.
|
||||
"-hls_list_size", "1",
|
||||
@ -300,7 +305,7 @@ func (ts *Stream) run(start int32) error {
|
||||
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(stdout)
|
||||
format := ts.handle.getSegmentName()
|
||||
format := fmt.Sprintf(SegmentNameFormat, encoder_id)
|
||||
should_stop := false
|
||||
is_init_ready := false
|
||||
|
||||
@ -383,10 +388,10 @@ func (ts *Stream) GetInit() (string, error) {
|
||||
select {
|
||||
case <-ts.init.channel:
|
||||
return fmt.Sprintf(
|
||||
"%s/%d/%s",
|
||||
"%s/%s/%s",
|
||||
ts.file.Out,
|
||||
ts.init.encoder,
|
||||
"init.mp4",
|
||||
ts.handle.getIdentifier(),
|
||||
fmt.Sprintf(InitNameFormat, ts.init.encoder),
|
||||
), nil
|
||||
case <-time.After(60 * time.Second):
|
||||
return "", errors.New("could not retrieve the selected segment (timeout)")
|
||||
@ -436,10 +441,13 @@ func (ts *Stream) GetSegment(segment int32) (string, error) {
|
||||
}
|
||||
ts.prerareNextSegements(segment)
|
||||
return fmt.Sprintf(
|
||||
"%s/%d/%s",
|
||||
"%s/%s/%s",
|
||||
ts.file.Out,
|
||||
ts.segments[segment].encoder,
|
||||
fmt.Sprintf(ts.handle.getSegmentName(), segment),
|
||||
ts.handle.getIdentifier(),
|
||||
fmt.Sprintf(
|
||||
fmt.Sprintf(SegmentNameFormat, ts.segments[segment].encoder),
|
||||
segment,
|
||||
),
|
||||
), nil
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,8 @@ func (vs *VideoStream) getFlags() Flags {
|
||||
return VideoF
|
||||
}
|
||||
|
||||
func (vs *VideoStream) getSegmentName() string {
|
||||
return fmt.Sprintf("segment-%s-%%d.m4s", vs.quality)
|
||||
func (vs *VideoStream) getIdentifier() string {
|
||||
return fmt.Sprintf("%s", vs.quality)
|
||||
}
|
||||
|
||||
func closestMultiple(n int32, x int32) int32 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user