Skip to content

Commit

Permalink
ffmpeg: Allow decoding of yuvj420p.
Browse files Browse the repository at this point in the history
Seems to have worked, although it's not yet clear whether the
full color range is properly processed within the GPU, or if
there is some truncation happening. In any case, the resulting
quality looks Close Enough.
  • Loading branch information
j0sh committed Apr 10, 2020
1 parent aa8cd0c commit 02ac425
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ffmpeg/lpms_ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,9 @@ static int open_video_decoder(input_params *params, struct input_ctx *ctx)
AVCodec *c = avcodec_find_decoder_by_name("h264_cuvid");
if (c) codec = c;
else fprintf(stderr, "Cuvid decoder not found; defaulting to software\n");
if (AV_PIX_FMT_YUV420P != ic->streams[ctx->vi]->codecpar->format) {
if (AV_PIX_FMT_YUV420P != ic->streams[ctx->vi]->codecpar->format &&
AV_PIX_FMT_YUVJ420P != ic->streams[ctx->vi]->codecpar->format) {
// TODO check whether the color range is truncated if yuvj420p is used
ret = lpms_ERR_INPUT_PIXFMT;
dd_err("Non 4:2:0 pixel format detected in input\n");
}
Expand Down
20 changes: 20 additions & 0 deletions ffmpeg/nvidia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,26 @@ func TestNvidia_Pixfmts(t *testing.T) {
`
run(cmd)

// Check that yuvj420p is allowed (jpeg color range)
// TODO check for color range truncation?
cmd = `
ffmpeg -loglevel warning -i test.ts -an -c:v libx264 -pix_fmt yuvj420p -t 1 inj420p.mp4
ffprobe -loglevel warning inj420p.mp4 -show_streams -select_streams v | grep pix_fmt=yuvj420p
`
run(cmd)
err = Transcode2(&TranscodeOptionsIn{
Fname: dir + "/inj420p.mp4",
Accel: Nvidia,
}, []TranscodeOptions{{
Oname: dir + "/outj420p.mp4",
Profile: prof,
Accel: Nvidia,
},
})
if err != nil {
t.Error(err)
}

return
// Following test vaidates YUV 4:4:4 pixel format encoding which is only supported on limited set of devices for e.g. P100
// https://developer.nvidia.com/video-encode-decode-gpu-support-matrix
Expand Down

0 comments on commit 02ac425

Please sign in to comment.