diff --git a/src/PHPVideoToolkit/VideoFormat/H264.php b/src/PHPVideoToolkit/VideoFormat/H264.php index 55f18c3..bdd7061 100644 --- a/src/PHPVideoToolkit/VideoFormat/H264.php +++ b/src/PHPVideoToolkit/VideoFormat/H264.php @@ -30,13 +30,15 @@ public function __construct($input_output_type=Format::OUTPUT, Config $config=nu 'h264_preset' => null, 'h264_tune' => null, 'h264_constant_quantization' => null, - 'h264_profile' => null + 'h264_profile' => null, + 'h264_level' => null, )); $this->_format_to_command = array_merge($this->_format_to_command, array( 'h264_preset' => '-preset ', 'h264_tune' => '-tune ', 'h264_constant_quantization' => '-qp ', - 'h264_profile' => '-profile:v ' + 'h264_profile' => '-profile:v ', + 'h264_level' => '-level ', )); $this->_restricted_video_presets = null; @@ -106,6 +108,27 @@ public function setH264Profile($profile=null) return $this; } + public function setH264Level($level=null) + { + $this->_blockSetOnInputFormat('h264 level'); + + if($level === null) + { + $this->_format['h264_level'] = null; + return $this; + } + + // Levels are described in Annex A of H.264 standard + // https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-H.264-200305-S!!PDF-E&type=items + if(in_array($level, array(1, 1.1, 1.2, 1.3, 2, 2.1, 2.2, 3, 3.1, 3.2, 4, 4.1, 4.2, 5, 5.1)) === false) + { + throw new Exception('Unrecognised h264 level "'.$level.'" set in \\PHPVideoToolkit\\'.get_class($this).'::setH264Level'); + } + + $this->_format['h264_level'] = sprintf('%.1f', $level); + return $this; + } + public function enableH264LosslessEncoding() { $this->_format['h264_constant_quantization'] = 0;