livepeer / lpms

Livepeer media server
MIT License
282 stars 71 forks source link

Honor minimum encoder resolution #326

Closed AlexKordic closed 2 years ago

AlexKordic commented 2 years ago

Fix for TestTranscoder_Portrait test

Add checkEncoderLimits() call at start of Transcode() function that will adjust output resolution to be at least the size of minimum supported resolution.

Hardcoded constraints are taken from 7th Gen NVENC card

var nvidiaCodecSizeLimts = map[VideoCodec]CodingSizeLimit{
    H264: {146, 50, 4096, 4096},
    H265: {132, 40, 8192, 8192},
}

Fix for mistaking landscape for portrait

360p and 240p profiles don't cause the bug, but produce incorrect output size for portrait video inputs.

When input video is in portrait mode and specified output in landscape mode we convert desired output resolution to be in portrait mode.

output resolution converted
640x360 360x640
426x240 240x426

When output resolution is converted then limits are checked. In case of 144p resolution that causes Invalid argument bug converted resolution is larger than requested to accommodate hardware capabilities.

output resolution converted
256x144 146x259

How to test

Nvidia card is required.

cd ffmpeg
go test . -v -count 1 -tags nvidia -run TestTranscoder_Portrait
=== RUN   TestTranscoder_Portrait
decoder.c:185] No audio stream found in input
--- PASS: TestTranscoder_Portrait (0.43s)
PASS
ok      github.com/livepeer/lpms/ffmpeg 0.439s