Fix ffmpeg error when trying to scale and copy video (#4660)

This commit is contained in:
WithoutPants
2024-03-07 09:02:45 +11:00
committed by GitHub
parent 7733a214d3
commit 4614471ad9
2 changed files with 19 additions and 31 deletions

View File

@@ -32,19 +32,19 @@ func (g Generator) TranscodeVideo(ctx context.Context, input string, hash string
}
// TranscodeAudio will copy the video stream as is, and transcode audio.
func (g Generator) TranscodeAudio(ctx context.Context, input string, hash string, options TranscodeOptions) error {
func (g Generator) TranscodeAudio(ctx context.Context, input string, hash string) error {
lockCtx := g.LockManager.ReadLock(ctx, input)
defer lockCtx.Cancel()
return g.makeTranscode(lockCtx, hash, g.transcodeAudio(input, options))
return g.makeTranscode(lockCtx, hash, g.transcodeAudio(input))
}
// TranscodeCopyVideo will copy the video stream as is, and drop the audio stream.
func (g Generator) TranscodeCopyVideo(ctx context.Context, input string, hash string, options TranscodeOptions) error {
func (g Generator) TranscodeCopyVideo(ctx context.Context, input string, hash string) error {
lockCtx := g.LockManager.ReadLock(ctx, input)
defer lockCtx.Cancel()
return g.makeTranscode(lockCtx, hash, g.transcodeCopyVideo(input, options))
return g.makeTranscode(lockCtx, hash, g.transcodeCopyVideo(input))
}
func (g Generator) makeTranscode(lockCtx *fsutil.LockContext, hash string, generateFn generateFn) error {
@@ -129,19 +129,11 @@ func (g Generator) transcodeVideo(input string, options TranscodeOptions) genera
}
}
func (g Generator) transcodeAudio(input string, options TranscodeOptions) generateFn {
func (g Generator) transcodeAudio(input string) generateFn {
return func(lockCtx *fsutil.LockContext, tmpFn string) error {
var videoArgs ffmpeg.Args
if options.Width != 0 && options.Height != 0 {
var videoFilter ffmpeg.VideoFilter
videoFilter = videoFilter.ScaleDimensions(options.Width, options.Height)
videoArgs = videoArgs.VideoFilter(videoFilter)
}
args := transcoder.Transcode(input, transcoder.TranscodeOptions{
OutputPath: tmpFn,
VideoCodec: ffmpeg.VideoCodecCopy,
VideoArgs: videoArgs,
AudioCodec: ffmpeg.AudioCodecAAC,
})
@@ -149,14 +141,8 @@ func (g Generator) transcodeAudio(input string, options TranscodeOptions) genera
}
}
func (g Generator) transcodeCopyVideo(input string, options TranscodeOptions) generateFn {
func (g Generator) transcodeCopyVideo(input string) generateFn {
return func(lockCtx *fsutil.LockContext, tmpFn string) error {
var videoArgs ffmpeg.Args
if options.Width != 0 && options.Height != 0 {
var videoFilter ffmpeg.VideoFilter
videoFilter = videoFilter.ScaleDimensions(options.Width, options.Height)
videoArgs = videoArgs.VideoFilter(videoFilter)
}
var audioArgs ffmpeg.Args
audioArgs = audioArgs.SkipAudio()
@@ -164,7 +150,6 @@ func (g Generator) transcodeCopyVideo(input string, options TranscodeOptions) ge
args := transcoder.Transcode(input, transcoder.TranscodeOptions{
OutputPath: tmpFn,
VideoCodec: ffmpeg.VideoCodecCopy,
VideoArgs: videoArgs,
AudioArgs: audioArgs,
})