Last active
April 24, 2019 19:09
-
-
Save j0sh/ab6a588250b0f1f2ca8c41c039ff5c62 to your computer and use it in GitHub Desktop.
Testing GPU with LPMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# FFmpeg configure line | |
./configure --prefix=/home/josh/compiled --disable-stripping --disable-static --enable-shared --enable-gpl --enable-nonfree --enable-libx264 --enable-cuda --enable-cuvid --enable-nvenc --enable-libnpp --extra-ldflags=-L/usr/local/cuda/lib64 --extra-cflags=-I/usr/local/cuda/include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"github.com/livepeer/lpms/ffmpeg" | |
) | |
func run(accel ffmpeg.Acceleration, fname string, outPrefix string) error { | |
return ffmpeg.Transcode2(&ffmpeg.TranscodeOptionsIn{ | |
Fname: fname, | |
Accel: accel, | |
}, []ffmpeg.TranscodeOptions{ | |
ffmpeg.TranscodeOptions{ | |
Oname: fmt.Sprintf("%s_sw_%s", outPrefix, fname), | |
Profile: ffmpeg.P240p30fps16x9, | |
Accel: ffmpeg.Software, | |
}, | |
ffmpeg.TranscodeOptions{ | |
Oname: fmt.Sprintf("%s_gpu_%s", outPrefix, fname), | |
Profile: ffmpeg.P240p30fps16x9, | |
Accel: ffmpeg.Nvidia, | |
}, | |
}) | |
} | |
func main() { | |
if len(os.Args) <= 1 { | |
panic("Expected input file") | |
} | |
fname := os.Args[1] | |
ffmpeg.InitFFmpeg() | |
fmt.Println("Decoding in software: ", fname) | |
if err := run(ffmpeg.Software, fname, "out_swdec"); err != nil { | |
panic(err) | |
} | |
fmt.Println("Decoding in hardware: ", fname) | |
if err := run(ffmpeg.Nvidia, fname, "out_hwdec"); err != nil { | |
panic(err) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Also assumes you have the ffmpeg libs within pkg-config | |
all: | |
CPATH=/usr/local/cuda/include LIBRARY_PATH=/usr/local/cuda/lib64 go build gpu.go | |
bench: | |
CPATH=/usr/local/cuda/include LIBRARY_PATH=/usr/local/cuda/lib64 go build lpms-bench.go | |
clean: | |
rm -f gpu lpms-bench |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use this to create portable executables that run on gpu and non-gpu hardware | |
// select at runtime via `ported-gpu <infile> nvenc` or `ported-gpu <infile> sw` | |
package main | |
import ( | |
"fmt" | |
"os" | |
"github.com/livepeer/lpms/ffmpeg" | |
) | |
func run(accel ffmpeg.Acceleration, fname string, outPrefix string) error { | |
fmt.Println("Encoding with sw") | |
opts := []ffmpeg.TranscodeOptions { | |
ffmpeg.TranscodeOptions{ | |
Oname: fmt.Sprintf("%s_sw_%s", outPrefix, fname), | |
Profile: ffmpeg.P240p30fps16x9, | |
Accel: ffmpeg.Software, | |
}, | |
} | |
if accel == ffmpeg.Nvidia { | |
// add hw acceleration if available | |
fmt.Println("Encoding with nvenc") | |
opts = append(opts, ffmpeg.TranscodeOptions{ | |
Oname: fmt.Sprintf("%s_nvenc_%s", outPrefix, fname), | |
Profile: ffmpeg.P240p30fps16x9, | |
Accel: ffmpeg.Nvidia, | |
}) | |
} | |
return ffmpeg.Transcode2(&ffmpeg.TranscodeOptionsIn{ | |
Fname: fname, | |
Accel: accel, | |
}, opts) | |
} | |
func main() { | |
if len(os.Args) <= 1 { | |
panic("Expected input file") | |
} | |
fname := os.Args[1] | |
accel := ffmpeg.Software | |
accelName := "sw" | |
if len(os.Args) > 2 { | |
switch os.Args[2] { | |
case "nvenc": | |
accel = ffmpeg.Nvidia | |
accelName = "nvenc" | |
default: | |
} | |
} | |
ffmpeg.InitFFmpeg() | |
fmt.Printf("Decoding %s with %s\n", fname, accelName) | |
if err := run(accel, fname, "out_" + accelName); err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment