0

So I am in php running an ffprobe command on files and grabbing the output (to get duration, time, etc)

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

Where $location is the files location + filename. Now this command works 100% perfectly for .mp4 / .avi / everything else I have tried. Except .mov, when using .mov my "output" variable is empty. Is there any way to fix this / change this?

CMOS
  • 2,727
  • 8
  • 47
  • 83
  • 1
    `-v quite` should be `-v quiet`. Apart from that your command works fine for me on version 2.6 and retrieves all the info. Can you provide a small sample? – aergistal Mar 25 '15 at 18:05
  • 1
    If ffprobe is getting invoked, this really isn't a programming question, it's a question about ffprobe itself. – Barett Mar 25 '15 at 18:30
  • Sorry that was just a typo on stack, it is correct on server. As far as I can tell the issue is that ffprobe returns the correct info for mp4 files but mov just returns nothing. – CMOS Mar 25 '15 at 18:53
  • I am on version 2.2, although I a m not seeing anything in the change logs that seem like it would have an impact. – CMOS Mar 25 '15 at 18:55
  • Can you try with a sample from Apple and see if it works? [https://support.apple.com/en-us/HT201549](https://support.apple.com/en-us/HT201549) – aergistal Mar 25 '15 at 20:14
  • For me `ffprobe` provides the expected output from a mov input when run manually via cli. Does it for you? – llogan Apr 01 '15 at 18:12

2 Answers2

0

I finally fixed this issue by converting only audio out of the video file, this is extremely fast in ffmpeg and you can set quality very low and get the duration from that consistently. Even if there is no audio it will still grab an audio file the same length as the film. Takes less than a second and gives you reliable data.

CMOS
  • 2,727
  • 8
  • 47
  • 83
  • The audio duration is not guaranteed to be the same as the video, and anyway, you can use `ffprobe` to get the duration from the container or any stream you want (see the `-select_streams` and/or `-show_entries` options). – llogan Apr 01 '15 at 18:15
-2

You won't get much information on a mov file with ffprobe. Use exiftool:

Install the tool on your server: http://owl.phy.queensu.ca/~phil/exiftool/install.html

if you did:

exiftool IMG_0014.MOV > a.txt

the output is

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

If you just need information from a video file you can use ffmpeg and all these other classes and function out there online uses ffmpeg to query video files anyway.

$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
    );

}
unixmiah
  • 3,081
  • 1
  • 12
  • 26
  • Will this also work for .avi or .mp4? or is it specifically for .mov – CMOS Mar 25 '15 at 17:51
  • it will work for all, the information you is get is a lot more in detail. – unixmiah Mar 25 '15 at 17:52
  • But is this just reading meta data? The point of this process is to check duration as to prevent long uploads, could someone edit their meta data and then bypass this? – CMOS Mar 25 '15 at 17:55
  • 1
    "You won't get much information on a mov file with ffprobe". Why not, did you try? – aergistal Mar 25 '15 at 18:03