Search code examples
videomlt

Melt command: how to read video properties?


How to read the total number of frames from a video with "melt" command Same for time and frames per second.


Solution

  • I found a possible answer to get the properties in a XML format.

    Use: melt movie.flv -consumer xml

    Code for php:

    //get total frames and framerate
    
    ob_start();
    system('melt '.$video.' -consumer xml');
    $clip_prop = ob_get_contents();
    ob_end_clean();
    
    $xml_prop = new DOMDocument();
    $xml_prop->loadXML( $clip_prop );
    
    $properties = $xml_prop->getElementsByTagName("property");
    
    foreach( $properties as $property )
    {
         $attribute = $property->getAttribute("name");
         //for total frames
         if( $attribute == "length" )
              $frames = $property->nodeValue;
         //for frame rates
         if( $attribute == "meta.media.0.stream.frame_rate" )
              $fps = $property->nodeValue;
    }