FFMPEG检索不适用于MOV文件的持续时间

时间:2015-03-25 17:18:26

标签: php linux ffmpeg transcoding ffprobe

所以我在php中对文件运行ffprobe命令并获取输出(以获取持续时间,时间等)

exec("usr/bin/ffprobe -v quiet-print_format json -show_format -show_streams $location", $output, $exitCode); 

其中$ location是文件位置+文件名。现在这个命令100%完美地适用于.mp4 / .avi /我试过的其他所有内容。除.mov外,当使用.mov时,我的“输出”变量为空。有没有办法解决这个/改变这个?

2 个答案:

答案 0 :(得分:0)

我最后通过仅转换视频文件中的音频来修复此问题,这在ffmpeg中非常快,您可以将质量设置得非常低并从中始终获得持续时间。即使没有音频,它仍然会获取与电影长度相同的音频文件。只需不到一秒钟,就可以获得可靠的数据。

答案 1 :(得分:-2)

使用ffprobe,您将无法获得有关mov文件的更多信息。使用exiftool:

在您的服务器上安装该工具: http://owl.phy.queensu.ca/~phil/exiftool/install.html

如果你这样做:

exiftool IMG_0014.MOV > a.txt

输出

ExifTool Version Number         : 8.60
File Name                       : IMG_0014.MOV
Directory                       : .
File Size                       : 19 MB
File Modification Date/Time     : 2013:07:19 12:03:22-10:00
File Permissions                : rw-r--r--
File Type                       : MOV
MIME Type                       : video/quicktime
Major Brand                     : Apple QuickTime (.MOV/QT)
Minor Version                   : 0.0.0
Compatible Brands               : qt
Movie Data Size                 : 19979709
Movie Header Version            : 0
Modify Date                     : 2013:07:19 22:03:21
Time Scale                      : 600
Duration                        : 7.27 s
Preferred Rate                  : 1
Preferred Volume                : 100.00%
Preview Time                    : 0 s
Preview Duration                : 0 s
Poster Time                     : 0 s
Selection Time                  : 0 s
Selection Duration              : 0 s
Current Time                    : 0 s
Next Track ID                   : 3
Track Header Version            : 0
Track Create Date               : 2013:07:19 22:03:13
Track Modify Date               : 2013:07:19 22:03:21
Track ID                        : 1
Track Duration                  : 7.27 s
Track Layer                     : 0
Track Volume                    : 0.00%
Image Width                     : 1920
Image Height                    : 1080
Graphics Mode                   : ditherCopy
Op Color                        : 32768 32768 32768
Compressor ID                   : avc1
Source Image Width              : 1920
Source Image Height             : 1080
X Resolution                    : 72
Y Resolution                    : 72
Compressor Name                 : H.264
Bit Depth                       : 24
Video Frame Rate                : 27.011
Camera Identifier               : Back
Frame Readout Time              : 28512 microseconds
Matrix Structure                : 1 0 0 0 1 0 0 0 1
Media Header Version            : 0
Media Create Date               : 2013:07:19 22:03:13
Media Modify Date               : 2013:07:19 22:03:21
Media Time Scale                : 44100
Media Duration                  : 7.31 s
Media Language Code             : und
Balance                         : 0
Handler Class                   : Data Handler
Handler Vendor ID               : Apple
Handler Description             : Core Media Data Handler
Audio Channels                  : 1
Audio Bits Per Sample           : 16
Audio Sample Rate               : 44100
Audio Format                    : chan
Model                           : iPhone 4S
Software Version                : 6.1.3
Create Date                     : 2013:07:20 08:03:13+10:00
Make                            : Apple
Handler Type                    : Metadata Tags
Make (und-AU)                   : Apple
Creation Date (und-AU)          : 2013:07:20 08:03:13+10:00
Software (und-AU)               : 6.1.3
Model (und-AU)                  : iPhone 4S
Avg Bitrate                     : 22 Mbps
Image Size                      : 1920x1080
Rotation                        : 90

如果您只需要视频文件中的信息,您可以使用ffmpeg和所有其他类和功能在线使用ffmpeg来查询视频文件。

$ffmpeg_path = 'ffmpeg'; //or: /usr/bin/ffmpeg - depends on your installation
$vid = 'PATH/TO/VIDEO'; //Replace here!

if (file_exists($vid)) {

    $video_attributes = _get_video_attributes($vid, $ffmpeg_path);

    print_r('Video codec: ' . $video_attributes['codec'] . ' - width: '  . $video_attributes['width'] 
            . ' - height: ' .  $video_attributes['height'] . ' <br/>');

    print_r('Video duration: ' . $video_attributes['hours'] . ':' . $video_attributes['mins'] . ':'
           . $video_attributes['secs'] . '.'. $video_attributes['ms']);
} else { echo 'File does not exist.'; }

function _get_video_attributes($video, $ffmpeg) {

    $command = $ffmpeg . ' -i ' . $video . ' -vstats 2>&1';  
    $output = shell_exec($command);  

    $regex_sizes = "/Video: ([^,]*), ([^,]*), ([0-9]{1,4})x([0-9]{1,4})/";
    if (preg_match($regex_sizes, $output, $regs)) {
        $codec = $regs [1] ? $regs [1] : null;
        $width = $regs [3] ? $regs [3] : null;
        $height = $regs [4] ? $regs [4] : null;
     }

    $regex_duration = "/Duration: ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}).([0-9]{1,2})/";
    if (preg_match($regex_duration, $output, $regs)) {
        $hours = $regs [1] ? $regs [1] : null;
        $mins = $regs [2] ? $regs [2] : null;
        $secs = $regs [3] ? $regs [3] : null;
        $ms = $regs [4] ? $regs [4] : null;
    }

    return array ('codec' => $codec,
            'width' => $width,
            'height' => $height,
            'hours' => $hours,
            'mins' => $mins,
            'secs' => $secs,
            'ms' => $ms
    );

}