Run unified player in preview-only mode

This commit is contained in:
Stu Leak 2026-01-07 02:27:46 -05:00
parent 037b771b0d
commit d8c649427b

View File

@ -97,6 +97,12 @@ func NewUnifiedPlayer(config Config) *UnifiedPlayer {
}, },
audioBufferSize: 32768, // 170ms at 48kHz for smooth playback audioBufferSize: 32768, // 170ms at 48kHz for smooth playback
} }
if config.WindowWidth > 0 {
player.windowW = config.WindowWidth
}
if config.WindowHeight > 0 {
player.windowH = config.WindowHeight
}
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
player.ctx = ctx player.ctx = ctx
@ -155,26 +161,28 @@ func (p *UnifiedPlayer) Load(path string, offset time.Duration) error {
} }
} }
// Initialize audio context for playback if !p.previewMode {
sampleRate := 48000 // Initialize audio context for playback
channels := 2 sampleRate := 48000
channels := 2
ctx, ready, err := oto.NewContext(&oto.NewContextOptions{ ctx, ready, err := oto.NewContext(&oto.NewContextOptions{
SampleRate: sampleRate, SampleRate: sampleRate,
ChannelCount: channels, ChannelCount: channels,
Format: oto.FormatSignedInt16LE, Format: oto.FormatSignedInt16LE,
BufferSize: 4096, // 85ms chunks for smooth playback BufferSize: 4096, // 85ms chunks for smooth playback
}) })
if err != nil { if err != nil {
logging.Error(logging.CatPlayer, "Failed to create audio context: %v", err) logging.Error(logging.CatPlayer, "Failed to create audio context: %v", err)
return err return err
} }
if ready != nil { if ready != nil {
<-ready <-ready
} }
p.audioContext = ctx p.audioContext = ctx
logging.Info(logging.CatPlayer, "Audio context initialized successfully") logging.Info(logging.CatPlayer, "Audio context initialized successfully")
}
// Start FFmpeg process for unified A/V output // Start FFmpeg process for unified A/V output
err = p.startVideoProcess() err = p.startVideoProcess()
@ -183,7 +191,9 @@ func (p *UnifiedPlayer) Load(path string, offset time.Duration) error {
} }
// Start audio stream processing // Start audio stream processing
go p.readAudioStream() if !p.previewMode {
go p.readAudioStream()
}
return nil return nil
} }
@ -545,18 +555,31 @@ func (p *UnifiedPlayer) startVideoProcess() error {
"-hide_banner", "-loglevel", "error", "-hide_banner", "-loglevel", "error",
"-ss", fmt.Sprintf("%.3f", p.currentTime.Seconds()), "-ss", fmt.Sprintf("%.3f", p.currentTime.Seconds()),
"-i", p.currentPath, "-i", p.currentPath,
// Video stream to pipe 4 }
"-map", "0:v:0", if p.previewMode {
"-f", "rawvideo", args = append(args,
"-pix_fmt", "rgb24", "-map", "0:v:0",
"-r", "24", // We'll detect actual framerate "-an",
"pipe:4", "-f", "rawvideo",
// Audio stream to pipe 5 "-pix_fmt", "rgb24",
"-map", "0:a:0", "-r", "24",
"-ac", "2", "pipe:1",
"-ar", "48000", )
"-f", "s16le", } else {
"pipe:5", args = append(args,
// Video stream to pipe 4
"-map", "0:v:0",
"-f", "rawvideo",
"-pix_fmt", "rgb24",
"-r", "24", // We'll detect actual framerate
"pipe:4",
// Audio stream to pipe 5
"-map", "0:a:0",
"-ac", "2",
"-ar", "48000",
"-f", "s16le",
"pipe:5",
)
} }
// Add hardware acceleration if available // Add hardware acceleration if available