Skip to content

Commit

Permalink
generate marker previews using endSeconds value
Browse files Browse the repository at this point in the history
  • Loading branch information
stg-annon committed Dec 8, 2024
1 parent 0621d87 commit 8edbd32
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions internal/manager/task_generate_markers.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func (t *GenerateMarkersTask) generateSceneMarkers(ctx context.Context) {

func (t *GenerateMarkersTask) generateMarker(videoFile *models.VideoFile, scene *models.Scene, sceneMarker *models.SceneMarker) {
sceneHash := scene.GetHash(t.fileNamingAlgorithm)
seconds := int(sceneMarker.Seconds)
seconds := float64(sceneMarker.Seconds)

g := t.generator

if err := g.MarkerPreviewVideo(context.TODO(), videoFile.Path, sceneHash, seconds, instance.Config.GetPreviewAudio()); err != nil {
if err := g.MarkerPreviewVideo(context.TODO(), videoFile.Path, sceneHash, seconds, sceneMarker.EndSeconds, instance.Config.GetPreviewAudio()); err != nil {
logger.Errorf("[generator] failed to generate marker video: %v", err)
logErrorOutput(err)
}
Expand Down
35 changes: 21 additions & 14 deletions pkg/scene/generate/marker_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,26 @@ const (
markerScreenshotQuality = 2
)

func (g Generator) MarkerPreviewVideo(ctx context.Context, input string, hash string, seconds int, includeAudio bool) error {
func (g Generator) MarkerPreviewVideo(ctx context.Context, input string, hash string, seconds float64, endSeconds *float64, includeAudio bool) error {
lockCtx := g.LockManager.ReadLock(ctx, input)
defer lockCtx.Cancel()

output := g.MarkerPaths.GetVideoPreviewPath(hash, seconds)
output := g.MarkerPaths.GetVideoPreviewPath(hash, int(seconds))
if !g.Overwrite {
if exists, _ := fsutil.FileExists(output); exists {
return nil
}
}

duration := float64(markerPreviewDuration)
if endSeconds != nil {
duration = float64(*endSeconds) - seconds
}

if err := g.generateFile(lockCtx, g.MarkerPaths, mp4Pattern, output, g.markerPreviewVideo(input, sceneMarkerOptions{
Seconds: seconds,
Audio: includeAudio,
Seconds: seconds,
Duration: duration,
Audio: includeAudio,
})); err != nil {
return err
}
Expand All @@ -44,8 +50,9 @@ func (g Generator) MarkerPreviewVideo(ctx context.Context, input string, hash st
}

type sceneMarkerOptions struct {
Seconds int
Audio bool
Seconds float64
Duration float64
Audio bool
}

func (g Generator) markerPreviewVideo(input string, options sceneMarkerOptions) generateFn {
Expand All @@ -69,8 +76,8 @@ func (g Generator) markerPreviewVideo(input string, options sceneMarkerOptions)
)

trimOptions := transcoder.TranscodeOptions{
Duration: markerPreviewDuration,
StartTime: float64(options.Seconds),
Duration: options.Duration,
StartTime: options.Seconds,
OutputPath: tmpFn,
VideoCodec: ffmpeg.VideoCodecLibX264,
VideoArgs: videoArgs,
Expand All @@ -90,11 +97,11 @@ func (g Generator) markerPreviewVideo(input string, options sceneMarkerOptions)
}
}

func (g Generator) SceneMarkerWebp(ctx context.Context, input string, hash string, seconds int) error {
func (g Generator) SceneMarkerWebp(ctx context.Context, input string, hash string, seconds float64) error {
lockCtx := g.LockManager.ReadLock(ctx, input)
defer lockCtx.Cancel()

output := g.MarkerPaths.GetWebpPreviewPath(hash, seconds)
output := g.MarkerPaths.GetWebpPreviewPath(hash, int(seconds))
if !g.Overwrite {
if exists, _ := fsutil.FileExists(output); exists {
return nil
Expand Down Expand Up @@ -143,11 +150,11 @@ func (g Generator) sceneMarkerWebp(input string, options sceneMarkerOptions) gen
}
}

func (g Generator) SceneMarkerScreenshot(ctx context.Context, input string, hash string, seconds int, width int) error {
func (g Generator) SceneMarkerScreenshot(ctx context.Context, input string, hash string, seconds float64, width int) error {
lockCtx := g.LockManager.ReadLock(ctx, input)
defer lockCtx.Cancel()

output := g.MarkerPaths.GetScreenshotPath(hash, seconds)
output := g.MarkerPaths.GetScreenshotPath(hash, int(seconds))
if !g.Overwrite {
if exists, _ := fsutil.FileExists(output); exists {
return nil
Expand All @@ -167,7 +174,7 @@ func (g Generator) SceneMarkerScreenshot(ctx context.Context, input string, hash
}

type SceneMarkerScreenshotOptions struct {
Seconds int
Seconds float64
Width int
}

Expand All @@ -180,7 +187,7 @@ func (g Generator) sceneMarkerScreenshot(input string, options SceneMarkerScreen
Width: options.Width,
}

args := transcoder.ScreenshotTime(input, float64(options.Seconds), ssOptions)
args := transcoder.ScreenshotTime(input, options.Seconds, ssOptions)

return g.generate(lockCtx, args)
}
Expand Down

0 comments on commit 8edbd32

Please sign in to comment.