Skip to content

Commit

Permalink
https://github.com/WWBN/AVideo/issues/9813#issuecomment-2594381098
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Jan 16, 2025
1 parent 071025d commit 5833c2d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
15 changes: 11 additions & 4 deletions objects/Format.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

require_once __DIR__ . '/HLSProcessor.php';
require_once __DIR__ . '/MP4Processor.php';
require_once __DIR__ . '/MP3Processor.php';

if (!class_exists('Format')) {
if (!class_exists('ObjectYPT')) {
Expand Down Expand Up @@ -113,7 +115,7 @@ protected static function getFromOrder($order)
}
return $row;
}

public function run($pathFileName, $encoder_queue_id)
{
_error_log("AVideo-Encoder Format::run($pathFileName, $encoder_queue_id) " . json_encode(debug_backtrace()));
Expand Down Expand Up @@ -896,16 +898,21 @@ private static function exec($format_id, $pathFileName, $destinationFile, $encod
}
$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);
}
} elseif ($format_id == 31) { // it is MP4
_error_log("AVideo-Encoder Format::exec line=" . __LINE__);

$advancedCustom = getAdvancedCustomizedObjectData();
if(!empty($advancedCustom->singleResolution->value)){
_error_log("AVideo-Encoder Format::exec line=" . __LINE__);
if (!empty($advancedCustom->singleResolution->value)) {
_error_log("AVideo-Encoder Format::exec MP4Processor::createMP4MaxResolutionFromQueueId($pathFileName, $encoder_queue_id, {$advancedCustom->singleResolution->value})");
return MP4Processor::createMP4MaxResolutionFromQueueId($pathFileName, $encoder_queue_id, $advancedCustom->singleResolution->value);
}else{
} else {
_error_log("AVideo-Encoder Format::exec line=" . __LINE__);
$fc = self::getDynamicCommandFromMP4($pathFileName, $encoder_queue_id);
}
} elseif ($format_id == 32) { // it is WebM
Expand Down
2 changes: 0 additions & 2 deletions objects/HLSProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ static function createMP3AndPM4IfNeed($pathFileName, $destinationFile){
$advancedCustom = getAdvancedCustomizedObjectData();
//_error_log('createMP3AndPM4IfNeed '.json_encode($advancedCustom));
if($advancedCustom->autoConvertToMp4){
require_once __DIR__.'/MP4Processor.php';
try {
MP4Processor::createMP4($pathFileName, $destinationFile.'index.mp4');
} catch (Exception $e) {
Expand All @@ -18,7 +17,6 @@ static function createMP3AndPM4IfNeed($pathFileName, $destinationFile){

}
if($advancedCustom->autoConvertVideosToMP3){
require_once __DIR__.'/MP3Processor.php';
// Usage example
try {
MP3Processor::createMP3($pathFileName, $destinationFile.'index.mp3');
Expand Down
10 changes: 7 additions & 3 deletions objects/MP4Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class MP4Processor
{

public static function createMP4MaxResolutionFromQueueId($pathFileName, $encoder_queue_id, $maxResolution = 1080){
_error_log("MP4Processor::createMP4MaxResolutionFromQueueId [$pathFileName, $encoder_queue_id, $maxResolution ] ");

$inputResolution = self::getResolution($pathFileName);
if($inputResolution> $maxResolution){
$inputResolution = $maxResolution;
Expand All @@ -23,6 +25,7 @@ public static function createMP4MaxResolution($pathFileName, $destinationFile, $

public static function createMP4($pathFileName, $destinationFile, $encoder_queue_id = 0, $inputResolution = null)
{
_error_log("MP4Processor::createMP4 [$pathFileName, $destinationFile, $encoder_queue_id, $inputResolution ] ");
global $global;
// Get allowed resolutions from Format::ENCODING_SETTINGS
$allowedResolutions = array_keys(Format::ENCODING_SETTINGS);
Expand Down Expand Up @@ -52,16 +55,17 @@ public static function createMP4($pathFileName, $destinationFile, $encoder_queue

if(!empty($encoder_queue_id)){
$progressFile = "{$global['systemRootPath']}videos/{$encoder_queue_id}_tmpFile_progress.txt";
$command = "{$command} > 1 $progressFile 2>&1";
$command = "{$command} 1> $progressFile 2>&1";
}

// Execute the FFmpeg command
_error_log("MP4Processor: Executing FFmpeg command: $command");
exec($command, $output, $resultCode);

if ($resultCode !== 0) {
_error_log("MP4Processor: FFmpeg failed with output: " . json_encode($output));
throw new Exception("Failed to create MP4 file.");
_error_log("MP4Processor: FFmpeg failed with output: $resultCode $command" . json_encode($output));
var_dump($resultCode, $output, $command);
throw new Exception("Failed to create MP4 file. $resultCode $command " . json_encode($output));
}

_error_log("MP4Processor: MP4 file created successfully at $destinationFile");
Expand Down

0 comments on commit 5833c2d

Please sign in to comment.