mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 12:14:46 -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
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (as *AudioStream) getSegmentName() string {
|
func (as *AudioStream) getIdentifier() string {
|
||||||
return fmt.Sprintf("segment-a-%d-%%d.m4s", as.index)
|
return fmt.Sprintf("a%d", as.index)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (as *AudioStream) getFlags() Flags {
|
func (as *AudioStream) getFlags() Flags {
|
||||||
|
@ -89,7 +89,7 @@ func (fs *FileStream) GetMaster() string {
|
|||||||
}
|
}
|
||||||
master += "AUDIO=\"audio\","
|
master += "AUDIO=\"audio\","
|
||||||
master += "CLOSED-CAPTIONS=NONE\n"
|
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)
|
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 += fmt.Sprintf("CODECS=\"%s\",", transmux_codec)
|
||||||
master += "AUDIO=\"audio\","
|
master += "AUDIO=\"audio\","
|
||||||
master += "CLOSED-CAPTIONS=NONE\n"
|
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 {
|
if audio.IsDefault {
|
||||||
master += "DEFAULT=YES,"
|
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
|
return master
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,17 @@ const (
|
|||||||
|
|
||||||
type StreamHandle interface {
|
type StreamHandle interface {
|
||||||
getTranscodeArgs(segments string) []string
|
getTranscodeArgs(segments string) []string
|
||||||
getSegmentName() string
|
getIdentifier() string
|
||||||
getFlags() Flags
|
getFlags() Flags
|
||||||
GetIndex() (string, error)
|
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 {
|
type Stream struct {
|
||||||
handle StreamHandle
|
handle StreamHandle
|
||||||
file *FileStream
|
file *FileStream
|
||||||
@ -213,8 +219,7 @@ func (ts *Stream) run(start int32) error {
|
|||||||
segments = []float64{9999999}
|
segments = []float64{9999999}
|
||||||
}
|
}
|
||||||
|
|
||||||
outpath := fmt.Sprintf("%s/%d", ts.file.Out, encoder_id)
|
outpath := fmt.Sprintf("%s/%s", ts.file.Out, ts.handle.getIdentifier())
|
||||||
fmt.Print(outpath)
|
|
||||||
err := os.MkdirAll(outpath, 0o755)
|
err := os.MkdirAll(outpath, 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -271,8 +276,8 @@ func (ts *Stream) run(start int32) error {
|
|||||||
"-hls_time", fmt.Sprint(OptimalFragmentDuration),
|
"-hls_time", fmt.Sprint(OptimalFragmentDuration),
|
||||||
"-start_number", fmt.Sprint(start_segment),
|
"-start_number", fmt.Sprint(start_segment),
|
||||||
"-hls_segment_type", "fmp4",
|
"-hls_segment_type", "fmp4",
|
||||||
"-hls_fmp4_init_filename", fmt.Sprintf("%s/init.mp4", outpath),
|
"-hls_fmp4_init_filename", fmt.Sprintf("%s/%s", outpath, fmt.Sprintf(InitNameFormat, encoder_id)),
|
||||||
"-hls_segment_filename", fmt.Sprintf("%s/%s", outpath, ts.handle.getSegmentName()),
|
"-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
|
// 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.
|
// anyways this list is only read once and we generate our own.
|
||||||
"-hls_list_size", "1",
|
"-hls_list_size", "1",
|
||||||
@ -300,7 +305,7 @@ func (ts *Stream) run(start int32) error {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
scanner := bufio.NewScanner(stdout)
|
scanner := bufio.NewScanner(stdout)
|
||||||
format := ts.handle.getSegmentName()
|
format := fmt.Sprintf(SegmentNameFormat, encoder_id)
|
||||||
should_stop := false
|
should_stop := false
|
||||||
is_init_ready := false
|
is_init_ready := false
|
||||||
|
|
||||||
@ -383,10 +388,10 @@ func (ts *Stream) GetInit() (string, error) {
|
|||||||
select {
|
select {
|
||||||
case <-ts.init.channel:
|
case <-ts.init.channel:
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"%s/%d/%s",
|
"%s/%s/%s",
|
||||||
ts.file.Out,
|
ts.file.Out,
|
||||||
ts.init.encoder,
|
ts.handle.getIdentifier(),
|
||||||
"init.mp4",
|
fmt.Sprintf(InitNameFormat, ts.init.encoder),
|
||||||
), nil
|
), nil
|
||||||
case <-time.After(60 * time.Second):
|
case <-time.After(60 * time.Second):
|
||||||
return "", errors.New("could not retrieve the selected segment (timeout)")
|
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)
|
ts.prerareNextSegements(segment)
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"%s/%d/%s",
|
"%s/%s/%s",
|
||||||
ts.file.Out,
|
ts.file.Out,
|
||||||
ts.segments[segment].encoder,
|
ts.handle.getIdentifier(),
|
||||||
fmt.Sprintf(ts.handle.getSegmentName(), segment),
|
fmt.Sprintf(
|
||||||
|
fmt.Sprintf(SegmentNameFormat, ts.segments[segment].encoder),
|
||||||
|
segment,
|
||||||
|
),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@ func (vs *VideoStream) getFlags() Flags {
|
|||||||
return VideoF
|
return VideoF
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vs *VideoStream) getSegmentName() string {
|
func (vs *VideoStream) getIdentifier() string {
|
||||||
return fmt.Sprintf("segment-%s-%%d.m4s", vs.quality)
|
return fmt.Sprintf("%s", vs.quality)
|
||||||
}
|
}
|
||||||
|
|
||||||
func closestMultiple(n int32, x int32) int32 {
|
func closestMultiple(n int32, x int32) int32 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user