Skip to content

Commit

Permalink
Update with logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Jan 9, 2025
1 parent 7aab22b commit b7da420
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions objects/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -889,12 +889,15 @@ private static function exec($format_id, $pathFileName, $destinationFile, $encod
if (empty($global['disableHLSAudioMultitrack'])) {
_error_log("AVideo-Encoder Format::exec use HLSProcessor");
$dynamic = HLSProcessor::createHLSWithAudioTracks($pathFileName, $destinationFile);
_error_log("AVideo-Encoder Format::exec use HLSProcessor Complete");
} else {
_error_log("AVideo-Encoder Format::exec disableHLSAudioMultitrack");
$dynamic = self::preProcessDynamicHLS($pathFileName, $destinationFile);
}
$destinationFile = $dynamic[0];
$fc = $dynamic[1];

_error_log("AVideo-Encoder Format::exec destinationFile=$destinationFile fc=$fc ");
} else { // use default 3 resolutions
$destinationFile = self::preProcessHLS($destinationFile);
}
Expand All @@ -908,6 +911,7 @@ private static function exec($format_id, $pathFileName, $destinationFile, $encod
$code = replaceFFMPEG($code);
$code = removeUserAgentIfNotURL($code);
if (empty($code)) {
_error_log("AVideo-Encoder Format::exec code is empty ");
$obj->msg = "Code not found ($format_id, $pathFileName, $destinationFile, $encoder_queue_id)";
} else {
$obj->code = $code;
Expand Down
15 changes: 9 additions & 6 deletions objects/HLSProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public static function createHLSWithAudioTracks($pathFileName, $destinationFile)

if (file_exists($keyInfoFile)) {
// Reuse existing keyinfo and key
_error_log("HLSProcessor: Reusing existing key and keyinfo");
_error_log("HLSProcessor: createHLSWithAudioTracks Reusing existing key and keyinfo");
$keyFileName = basename(file($keyInfoFile)[0]); // Extract key filename from keyinfo
} else {
// Create encryption key
_error_log("HLSProcessor: Creating new encryption key and keyinfo");
_error_log("HLSProcessor: createHLSWithAudioTracks Creating new encryption key and keyinfo");
$key = openssl_random_pseudo_bytes(16);
$keyFileName = "enc_" . uniqid() . ".key";
file_put_contents($destinationFile . $keyFileName, $key);
Expand Down Expand Up @@ -61,14 +61,15 @@ public static function createHLSWithAudioTracks($pathFileName, $destinationFile)
"-hls_segment_filename \"{$audioTsPattern}\" {$audioFile}";

$audioCommand = removeUserAgentIfNotURL($audioCommand);
_error_log("Executing audio FFmpeg command: {$audioCommand}");
_error_log("HLSProcessor: createHLSWithAudioTracks Executing audio FFmpeg command: {$audioCommand}");
exec($audioCommand, $output, $result_code); // Execute FFmpeg command

if (!file_exists($audioFile)) {
_error_log("audioFile error: {$audioCommand} " . json_encode(array($output)));
_error_log("HLSProcessor: createHLSWithAudioTracks audioFile error: {$audioCommand} " . json_encode(array($output)));
rmdir("{$destinationFile}audio_tracks/{$langDir}");
unset($audioTracks[$key]);
} else {
_error_log("HLSProcessor: createHLSWithAudioTracks audioFile Success" );
// Add audio track entry to the master playlist
$default = ($track->index == 0) ? "YES" : "NO"; // Set first audio track as default
$masterPlaylist .= "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"audio_group\",NAME=\"{$track->title}\",LANGUAGE=\"{$language}\",DEFAULT={$default},AUTOSELECT=YES,URI=\"audio_tracks/{$langDir}/audio.m3u8\"".PHP_EOL;
Expand All @@ -80,6 +81,7 @@ public static function createHLSWithAudioTracks($pathFileName, $destinationFile)
// Generate HLS files for each resolution
foreach ($resolutions as $key => $value) {
if ($resolution >= $value) {
_error_log("HLSProcessor: createHLSWithAudioTracks Resolution found: {$value}");
$encodingSettings = Format::ENCODING_SETTINGS[$value];
$rate = $encodingSettings['maxrate']; // Use the maxrate from ENCODING_SETTINGS
$framerate = isset($videoFramerate[$key]) && $videoFramerate[$key] > 0 ? $videoFramerate[$key] : 30;
Expand All @@ -96,11 +98,12 @@ public static function createHLSWithAudioTracks($pathFileName, $destinationFile)

$resolutionsFound++;
} else {
_error_log("HLSProcessor: Skipped resolution {$value} for {$pathFileName} (video height is {$resolution})");
_error_log("HLSProcessor: createHLSWithAudioTracks Skipped resolution {$value} for {$pathFileName} (video height is {$resolution})");
}
}

if (empty($resolutionsFound)) {
_error_log("HLSProcessor: createHLSWithAudioTracks Resolution found is empty");
// did not find any resolution, process the default one
$encodingSettings = Format::ENCODING_SETTINGS[480];
$rate = $encodingSettings['maxrate']; // Use the maxrate from ENCODING_SETTINGS
Expand All @@ -124,7 +127,7 @@ public static function createHLSWithAudioTracks($pathFileName, $destinationFile)

// Write the master playlist to the destination file
file_put_contents($destinationFile . "index.m3u8", $masterPlaylist);
_error_log("Master playlist written to: {$destinationFile}index.m3u8");
_error_log("HLSProcessor: createHLSWithAudioTracks Master playlist written to: {$destinationFile}index.m3u8");

return array($destinationFile, $ffmpegCommand);
}
Expand Down

0 comments on commit b7da420

Please sign in to comment.