Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for H264 levels #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/PHPVideoToolkit/VideoFormat/H264.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <setting>',
'h264_tune' => '-tune <setting>',
'h264_constant_quantization' => '-qp <setting>',
'h264_profile' => '-profile:v <setting>'
'h264_profile' => '-profile:v <setting>',
'h264_level' => '-level <setting>',
));

$this->_restricted_video_presets = null;
Expand Down Expand Up @@ -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;
Expand Down