mirror of
https://github.com/stashapp/stash.git
synced 2025-12-09 01:44:52 +01:00
Fix ffmpeg error when trying to scale and copy video (#4660)
This commit is contained in:
parent
7733a214d3
commit
4614471ad9
2 changed files with 19 additions and 31 deletions
|
|
@ -26,7 +26,7 @@ func (t *GenerateTranscodeTask) GetDescription() string {
|
||||||
return fmt.Sprintf("Generating transcode for %s", t.Scene.Path)
|
return fmt.Sprintf("Generating transcode for %s", t.Scene.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *GenerateTranscodeTask) Start(ctc context.Context) {
|
func (t *GenerateTranscodeTask) Start(ctx context.Context) {
|
||||||
hasTranscode := HasTranscode(&t.Scene, t.fileNamingAlgorithm)
|
hasTranscode := HasTranscode(&t.Scene, t.fileNamingAlgorithm)
|
||||||
if !t.Overwrite && hasTranscode {
|
if !t.Overwrite && hasTranscode {
|
||||||
return
|
return
|
||||||
|
|
@ -72,23 +72,26 @@ func (t *GenerateTranscodeTask) Start(ctc context.Context) {
|
||||||
|
|
||||||
w, h := videoFile.TranscodeScale(transcodeSize.GetMaxResolution())
|
w, h := videoFile.TranscodeScale(transcodeSize.GetMaxResolution())
|
||||||
|
|
||||||
options := generate.TranscodeOptions{
|
// if scale is being set, then we can't use stream copy
|
||||||
Width: w,
|
scaleSet := w == 0 && h == 0
|
||||||
Height: h,
|
|
||||||
}
|
|
||||||
|
|
||||||
if videoCodec == ffmpeg.H264 { // for non supported h264 files stream copy the video part
|
if scaleSet && videoCodec == ffmpeg.H264 { // for non supported h264 files stream copy the video part
|
||||||
if audioCodec == ffmpeg.MissingUnsupported {
|
if audioCodec == ffmpeg.MissingUnsupported {
|
||||||
err = t.g.TranscodeCopyVideo(context.TODO(), videoFile.Path, sceneHash, options)
|
err = t.g.TranscodeCopyVideo(ctx, videoFile.Path, sceneHash)
|
||||||
} else {
|
} else {
|
||||||
err = t.g.TranscodeAudio(context.TODO(), videoFile.Path, sceneHash, options)
|
err = t.g.TranscodeAudio(ctx, videoFile.Path, sceneHash)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
options := generate.TranscodeOptions{
|
||||||
|
Width: w,
|
||||||
|
Height: h,
|
||||||
|
}
|
||||||
|
|
||||||
if audioCodec == ffmpeg.MissingUnsupported {
|
if audioCodec == ffmpeg.MissingUnsupported {
|
||||||
// ffmpeg fails if it tries to transcode an unsupported audio codec
|
// ffmpeg fails if it tries to transcode an unsupported audio codec
|
||||||
err = t.g.TranscodeVideo(context.TODO(), videoFile.Path, sceneHash, options)
|
err = t.g.TranscodeVideo(ctx, videoFile.Path, sceneHash, options)
|
||||||
} else {
|
} else {
|
||||||
err = t.g.Transcode(context.TODO(), videoFile.Path, sceneHash, options)
|
err = t.g.Transcode(ctx, videoFile.Path, sceneHash, options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.
|
// 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)
|
lockCtx := g.LockManager.ReadLock(ctx, input)
|
||||||
defer lockCtx.Cancel()
|
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.
|
// 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)
|
lockCtx := g.LockManager.ReadLock(ctx, input)
|
||||||
defer lockCtx.Cancel()
|
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 {
|
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 {
|
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{
|
args := transcoder.Transcode(input, transcoder.TranscodeOptions{
|
||||||
OutputPath: tmpFn,
|
OutputPath: tmpFn,
|
||||||
VideoCodec: ffmpeg.VideoCodecCopy,
|
VideoCodec: ffmpeg.VideoCodecCopy,
|
||||||
VideoArgs: videoArgs,
|
|
||||||
AudioCodec: ffmpeg.AudioCodecAAC,
|
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 {
|
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
|
var audioArgs ffmpeg.Args
|
||||||
audioArgs = audioArgs.SkipAudio()
|
audioArgs = audioArgs.SkipAudio()
|
||||||
|
|
@ -164,7 +150,6 @@ func (g Generator) transcodeCopyVideo(input string, options TranscodeOptions) ge
|
||||||
args := transcoder.Transcode(input, transcoder.TranscodeOptions{
|
args := transcoder.Transcode(input, transcoder.TranscodeOptions{
|
||||||
OutputPath: tmpFn,
|
OutputPath: tmpFn,
|
||||||
VideoCodec: ffmpeg.VideoCodecCopy,
|
VideoCodec: ffmpeg.VideoCodecCopy,
|
||||||
VideoArgs: videoArgs,
|
|
||||||
AudioArgs: audioArgs,
|
AudioArgs: audioArgs,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue