69 lines
1.7 KiB
PHP
69 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace VfxApply;
|
|
|
|
class Input
|
|
{
|
|
protected $filename;
|
|
|
|
protected $audiostreams = [];
|
|
|
|
protected $videostreams = [];
|
|
|
|
public function setFilename($filename)
|
|
{
|
|
$this->filename = $filename;
|
|
}
|
|
|
|
public function getFilename()
|
|
{
|
|
return $this->filename;
|
|
}
|
|
|
|
public function selectFile()
|
|
{
|
|
$cmdl = "zenity --file-selection --title \"Select input file\" ";
|
|
$cmdl.= "--file-filter=\"Video files (mp4,m4v,avi,ogv,mkv)|*.mp4 *.m4v *.avi *.ogv *.mkv\" ";
|
|
$cmdl.= "--file-filter=\"Audio files (mp3,m4a,wav,ogg)|*.mp3 *.m4a *.wav *.ogg\" ";
|
|
$cmdl.= "--file-filter=\"All files|*\" 2>/dev/null";
|
|
|
|
exec($cmdl, $out, $ret);
|
|
if ($ret == 0) {
|
|
$this->filename = trim(array_shift($out));
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function analyze()
|
|
{
|
|
$cmdl = "ffprobe -loglevel error -show_streams -print_format json ".escapeshellarg($this->filename);
|
|
|
|
exec($cmdl, $out, $ret);
|
|
if ($ret != 0) {
|
|
throw new \Exception("Unable to analyze file {$this->filename}");
|
|
}
|
|
$info = json_decode(join("\n",$out));
|
|
|
|
foreach ($info->streams as $stream) {
|
|
if ($stream->codec_type == 'video') {
|
|
$this->videostreams[] = $stream;
|
|
} elseif ($stream->codec_type == 'audio') {
|
|
$this->audiostreams[] = $stream;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public function getVideoDuration()
|
|
{
|
|
$duration = $this->videostreams[0]->duration;
|
|
$frames = $this->videostreams[0]->nb_frames;
|
|
|
|
return (object)[
|
|
"seconds" => floatval($duration),
|
|
"frames" => intval($frames)
|
|
];
|
|
}
|
|
|
|
} |