Skip to content

Commit

Permalink
Change scale_cuda to scale_npp (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
leszko authored Sep 18, 2023
1 parent f590417 commit 4fe16b9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
27 changes: 15 additions & 12 deletions ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,43 +447,43 @@ func newAVOpts(opts map[string]string) *C.AVDictionary {
}

// return encoding specific options for the given accel
func configEncoder(inOpts *TranscodeOptionsIn, outOpts TranscodeOptions) (string, string, error) {
func configEncoder(inOpts *TranscodeOptionsIn, outOpts TranscodeOptions) (string, string, string, error) {
inDev := inOpts.Device
outDev := outOpts.Device
encoder := FfEncoderLookup[outOpts.Accel][outOpts.Profile.Encoder]
switch inOpts.Accel {
case Software:
switch outOpts.Accel {
case Software:
return encoder, "scale", nil
return encoder, "scale", "", nil
case Nvidia:
upload := "hwupload_cuda"
if outDev != "" {
upload = upload + "=device=" + outDev
}
return encoder, upload + ",scale_cuda", nil
return encoder, upload + ",scale_npp", "super", nil
}
case Nvidia:
switch outOpts.Accel {
case Software:
return encoder, "scale_cuda", nil
return encoder, "scale_npp", "super", nil
case Nvidia:
// If we encode on a different device from decode then need to transfer
if outDev != "" && outDev != inDev {
return "", "", ErrTranscoderDev // XXX not allowed
return "", "", "", ErrTranscoderDev // XXX not allowed
}
return encoder, "scale_cuda", nil
return encoder, "scale_npp", "super", nil
}
case Netint:
switch outOpts.Accel {
case Software, Nvidia:
return "", "", ErrTranscoderDev // XXX don't allow mix-match between NETINT and sw/nv
return "", "", "", ErrTranscoderDev // XXX don't allow mix-match between NETINT and sw/nv
case Netint:
// Use software scale filter
return encoder, "scale", nil
return encoder, "scale", "", nil
}
}
return "", "", ErrTranscoderHw
return "", "", "", ErrTranscoderHw
}
func accelDeviceType(accel Acceleration) (C.enum_AVHWDeviceType, error) {
switch accel {
Expand Down Expand Up @@ -643,15 +643,18 @@ func createCOutputParams(input *TranscodeOptionsIn, ps []TranscodeOptions) ([]C.
}
}
encoder, scale_filter := p.VideoEncoder.Name, "scale"
var interpAlgo string
if encoder == "" {
encoder, scale_filter, err = configEncoder(input, p)
encoder, scale_filter, interpAlgo, err = configEncoder(input, p)
if err != nil {
return params, finalizer, err
}
}
// preserve aspect ratio along the larger dimension when rescaling
var filters string
filters = fmt.Sprintf("%s='w=if(gte(iw,ih),%d,-2):h=if(lt(iw,ih),%d,-2)'", scale_filter, w, h)
filters := fmt.Sprintf("%s='w=if(gte(iw,ih),%d,-2):h=if(lt(iw,ih),%d,-2)'", scale_filter, w, h)
if interpAlgo != "" {
filters = fmt.Sprintf("%s:interp_algo=%s", filters, interpAlgo)
}
if input.Accel == Nvidia && p.Accel == Software {
// needed for hw dec -> hw rescale -> sw enc
filters = filters + ",hwdownload,format=nv12"
Expand Down
4 changes: 2 additions & 2 deletions ffmpeg/nvidia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ func TestNvidia_API_MixedOutput(t *testing.T) {
diff -u $1.md5 ffmpeg_$1.md5
ffmpeg -loglevel warning -i out_$1.ts -c:a aac -ar 44100 -ac 2 \
-vf hwupload_cuda,fps=123,scale_cuda=w=256:h=144 -c:v h264_nvenc \
-vf hwupload_cuda,fps=123,scale_npp=w=256:h=144 -c:v h264_nvenc \
ffmpeg_nv_$1.ts
# sanity check ffmpeg frame count against ours
Expand Down Expand Up @@ -640,7 +640,7 @@ func TestNvidia_API_AlternatingTimestamps(t *testing.T) {
diff -u $1.md5 ffmpeg_$1.md5
ffmpeg -loglevel warning -i out_$1.ts -c:a aac -ar 44100 -ac 2 \
-vf hwupload_cuda,fps=123,scale_cuda=w=256:h=144 -c:v h264_nvenc \
-vf hwupload_cuda,fps=123,scale_npp=w=256:h=144 -c:v h264_nvenc \
-muxdelay 0 -copyts \
ffmpeg_nv_$1.ts
Expand Down

0 comments on commit 4fe16b9

Please sign in to comment.