android gpu h264,CUDA GPU Accelerated h264/h265/HEVC Video Encoding with ffmpeg

CUDA GPU Accelerated h264/h265/HEVC Video Encoding with ffmpeg

High Quality FFMPEG Video Encoding

High quality is not always easy to define. I would define high quality as equal or near same quality as the original and this is the goal.

The commandline tool ffmpeg offers great flexibility when it comes to video and audio encoding with a great advantage: it’s free of use.

Prerequisites for High Quality – High Efficiency Video Encoding

Source Movie File: DNxHD 4:2:2 10-bit or ProResHQ / Cineform with minimum video bitrate 185mbit movie in HD resolution or better

Quality

Using the preset option delivers quality that easyily surpasses Adobe Media Encoder, especially colorbanding and macroblocks artifacts reduced significantly with ffmpeg when using the h264 codec with the -crf option.

Compression comparison: 700x400px 1:1 crop from a 1920×1080 sequence. Booth are encoded with 6 Mbit average bitrate – fot the ffmpeg version, the -crf option was used and for the AME version, the CBR option was used to encode. See the difference on the arm in motion.

INFO: A new eBook is in the works about video encoding with lots of ffmpeg examples, high quality encoding settings, workflows with Adobe Premiere and many in-depth infos.

“The Secrets of ffmpeg”

by Patrick Zadrobilek

Subscribe to the NTown Newsletter to get informed when it’s beeing realeased!

c709319e03f6d3ee656ff7cd52849524.png

2a985a1d5371caf0c972dd2181afe476.png

Left: ffmpeg -crf / Right: Premiere Adobe Media Encoder CBR

Speed

With ffmpeg and a decent GPU (like a Quadro P4000) the h265/HEVC encoder finaly gets a good speedboost with up to 90fps when encoding HD movies with the below parameter values and 200fps when using the GPU accelerated h264 encoder.

This speed is achieved with a Quadro P4000 from NVidia when encoding 1920×1080 movies with -preset slow. The GTX 780 Ti still encodes with 50-60fps in FullHD with the h264 hardware GPU encoder with high quality settings – currently a graphics adapter with good good speed/cost factor would be a GTX 1070 or GTX 1080.

Encoding high quality h264 video with CPU only:

ffmpeg.exe -i inmovie.mov -c:v libx264 -pix_fmt yuv420p -preset slow -tune film -crf 19 -c:a aac -b:a 224k outmovie.mp4

Parameters

-preset slow preset for HQ encoding (see x264 preset profiles below)

-tune film preset for film content (see x264 tune profiles below)

-crf 16 constant quality factor lower is better (good values for HD are 14-19)

-a aac AAC audio codec is most common for MP4 movie files

NOTE: Use -crf if bitrate is not so important and the quality factor is more important. Choose -b:v if you need a limitation for the bitrate and size of the video.

Encoding high quality h264 video via GPU:

ffmpeg.exe -hwaccel cuvid -i inmovie.mov -c:v h264_nvenc -pix_fmt yuv420p -preset slow -rc vbr_hq -b:v 6M -maxrate:v 10M -c:a aac -b:a 224k outmovie.mp4

Parameters

-hwaccel cuvid uses NVidia CUDA GPU acceleration for decoding (also working: dxva2)

-c:v h264_nvenc uses NVidia h264 GPU Encoder

-pix_fmt yuv420p 4:2:0 color subsampling

-preset slow HQ gpu encoding

-rc vbr_hq uses RC option to enable variable bitrate encoding with GPU encoding

-qmin:v 19 -qmax:v 14 sets minimum and maximum quantization values (optional)

-b:v 6M -maxrate:v 10M sets average (target) and maximum bitrate allowed for the encoder

NOTE: There are a lot more options for GPU hardware encoding/decoding. With the options above the GPU is used for DECODING and ENCODING – these are the most reliable GPU encoding options. This way it is possible to process the frames, for example with the -vf option.

Encoding high quality h265/HEVC 10-bit video via GPU:

ffmpeg.exe -hwaccel cuvid -i inmovie.mov -pix_fmt p010le -c:v hevc_nvenc -preset slow -rc vbr_hq -b:v 6M -maxrate:v 10M -c:a aac -b:a 240k outmovie.mp4

Parameters

-hwaccel cuvid uses NVidia CUDA GPU acceleration for decoding (also working: dxva2)

-pix_fmt p010le YUV 4:2:0 10-bit

-c:v hevc_nvenc uses HEVC/h265 GPU hardware encoder

-preset slow HQ gpu encoding

-rc vbr_hq uses RC option to enable variable bitrate encoding with GPU encoding

-qmin:v 19 -qmax:v 14 sets minimum and maximum quantization values (optional)

-b:v 6M -maxrate:v 10M sets average and maximum bitrate allowed for the encoder

NOTE: HEVC 10-bit has very good quality when playing with an advanced media player like Media Player Classic – Home Cinema (supports 10-bit playback on supported graphics cards like Quadro P4000 and supported displays like HP Dreamcolor), but because Youtube and Vimeo lacks 10-bit support, the h264 8-bit movies look better on the online video platforms once uploaded there.

FFMPEG -preset slow Parameters:

cabac=1 / ref=5 / deblock=1:0:0 / analyse=0x3:0x113 / me=umh / subme=8 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=3 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=2 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=50 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00

Sources and Detailed Infos

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值