@@ -322,7 +322,6 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions, $generate = t
322322 */
323323 public function getAudioUrl ($ filePath , $ audioOptions ): string
324324 {
325- Craft::info ('testing123 ' , __METHOD__ );
326325 $ result = '' ;
327326 $ settings = Transcoder::$ plugin ->getSettings ();
328327 $ subfolder = '' ;
@@ -388,39 +387,43 @@ public function getAudioUrl($filePath, $audioOptions): string
388387
389388 // Assemble the destination path and final ffmpeg command
390389 $ destAudioPath .= $ destAudioFile ;
391- $ ffmpegCmd .= ' -f '
390+ $ ffmpegCmd .= ' -map_metadata -1 - f '
392391 .$ thisEncoder ['fileFormat ' ]
393392 .' -y ' .escapeshellarg ($ destAudioPath );
394- //.' 1> '.$progressFile.' 2>&1 & echo $!';
395- Craft::info ('laget command ' , __METHOD__ );
396- // Make sure there isn't a lockfile for this audio file already
397- // $lockFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destAudioFile.'.lock';
398- // $oldPid = @file_get_contents($lockFile);
399- // if ($oldPid !== false) {
400- // exec("ps $oldPid", $ProcessState);
401- // if (\count($ProcessState) >= 2) {
402- // return $result;
403- // }
404- // // It's finished transcoding, so delete the lockfile and progress file
405- // @unlink($lockFile);
406- // @unlink($progressFile);
407- // }
408- Craft::info ('lockfile ' , __METHOD__ );
393+
394+ if (!$ audioOptions ['synchronous ' ]) {
395+ $ ffmpegCmd .=' 1> ' .$ progressFile .' 2>&1 & echo $! ' ;
396+ // Make sure there isn't a lockfile for this audio file already
397+ $ lockFile = sys_get_temp_dir ().DIRECTORY_SEPARATOR .$ destAudioFile .'.lock ' ;
398+ $ oldPid = @file_get_contents ($ lockFile );
399+ if ($ oldPid !== false ) {
400+ exec ("ps $ oldPid " , $ ProcessState );
401+ if (\count ($ ProcessState ) >= 2 ) {
402+ return $ result ;
403+ }
404+ // It's finished transcoding, so delete the lockfile and progress file
405+ @unlink ($ lockFile );
406+ @unlink ($ progressFile );
407+ }
408+ }
409409
410410 // If the audio file already exists and hasn't been modified, return it. Otherwise, start it transcoding
411411 if (file_exists ($ destAudioPath ) && (@filemtime ($ destAudioPath ) >= @filemtime ($ filePath ))) {
412412 $ url = $ settings ['transcoderUrls ' ]['audio ' ] . $ subfolder ?? $ settings ['transcoderUrls ' ]['default ' ];
413413 $ result = Craft::getAlias ($ url ).$ destAudioFile ;
414414 } else {
415415 // Kick off the transcoding
416- Craft::info ($ ffmpegCmd , __METHOD__ );
417416 $ this ->executeShellCommand ($ ffmpegCmd );
418- $ url = $ settings ['transcoderUrls ' ]['audio ' ] . $ subfolder ?? $ settings ['transcoderUrls ' ]['default ' ];
419- $ result = Craft::getAlias ($ url ).$ destAudioFile ;
420- Craft::info ($ result , __METHOD__ );
421-
422- // Create a lockfile in tmp
423- // file_put_contents($lockFile, $pid);
417+
418+ if ($ audioOptions ['synchronous ' ]) {
419+ Craft::info ($ ffmpegCmd , __METHOD__ );
420+ $ url = $ settings ['transcoderUrls ' ]['audio ' ] . $ subfolder ?? $ settings ['transcoderUrls ' ]['default ' ];
421+ $ result = Craft::getAlias ($ url ).$ destAudioFile ;
422+ } else {
423+ Craft::info ($ ffmpegCmd ."\nffmpeg PID: " .$ pid , __METHOD__ );
424+ // Create a lockfile in tmp
425+ file_put_contents ($ lockFile , $ pid );
426+ }
424427 }
425428 }
426429
0 commit comments