Skip to content
Advertisement

ffmpeg not detecting video file duration

Am using the following code to detect video duration before uploading using ffmpeg, but it doesn’t seem to work:

<?php
  $file=sample.avi;
  $time = exec("$ffmpeg -i /path/".$file." 2>&1 | 
  grep Duration | cut -d ' ' -f 4 | sed s/,//");
  echo $time;
?>

I need to echo video duration as text input to sql before uploading file to server.

Advertisement

Answer

i used https://github.com/wseemann/FFmpegMediaMetadataRetriever

with following code to retrive video duration

FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever();
mmr.setDataSource(mUri);
String time = mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION);
int VideoDuration = Integer.parseInt(time);
mmr.release();
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement