I am developing software that allows users to upload their own videos, which
the software then strings together like a concat operation.
Since the input videos all have different formats, resolutions, bit depths,
color spaces, color transfers, and color primaries, I need to normalize these
videos.
What is the best way to implement normalization so that the output video is not
too dark, too bright, or tinted red?
This is my current Node.js implementation:
// HDR -> SDR
if (data.isHLG || data.isPQ) {
vf = `zscale=primariesin=${data.isPQ||data.isHLG ? 'bt2020' :
data.primariesIn}:transferin=${data.transferIn}:matrixin=${data.matrixIn}:rangein=${data.rangeIn},`
+
`zscale=t=linear:npl=100,format=gbrpf32le,` +
`tonemap=tonemap=mobius:param=0.3:desat=0.7,` +
`zscale=primaries=bt709:transfer=bt709:matrix=bt709:range=tv:dither=error_diffusion,`
+
`format=yuv420p,${padding},setsar=1`;
}
// SDR → SDR
else {
vf =
`zscale=primariesin=${data.primariesIn}:transferin=${data.transferIn}:matrixin=${data.matrixIn}:rangein=${data.rangeIn},`
+
`zscale=primaries=bt709:transfer=bt709:matrix=bt709:range=tv:dither=error_diffusion,`
+
`format=yuv420p,${padding},setsar=1`;
}
// Reset color for 8-bit videos.
await execAsync(`
ffmpeg -y ${hardware} -i "${data.sourcePath}" \
-vf "${vf}" \
${encoding} \
${PARAMS.KEY_FRAMES_ZERO} \
-color_range tv -color_trc bt709 -color_primaries bt709 -colorspace
bt709 \
${PARAMS.AUDIO_CODEC} \
${PARAMS.MOV_FLAGS} \
"${data.targetPath}"
`);
_______________________________________________
ffmpeg-user mailing list -- [email protected]
To unsubscribe send an email to [email protected]