h265 and CRF in a specific region

Viewed 168

I need to create an h265 with a region that is compressed with a different CRF.

I was thinking of generating 2 compressed videos from the original using h265 with different CRFs and then blending each frame. The final step is to create an h265 video from the blended frames using the min CRF between the two. Does it make sense or there is a simpler and better way?

1 Answers

libx265 supports Region of Interest (ROI). You can use the addroi filter to select the ROI and provide the desired quantisation offset.

Example using extreme values for demonstration purposes to make the top half of the frame have a much better quality than the bottom:

Mandelbrot with ROI applied

ffmpeg -i input.mkv -vf "addroi=x=0:y=0:w=iw:h=ih/2:qoffset=-1/2" -c:v libx265 -crf 51 -c:a copy output.mkv

Multiple regions can be marked by applying the filter multiple times.

Related