User Tools

Site Tools


ffmpeg:video:duration

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ffmpeg:video:duration [2025/05/27 18:27] peterffmpeg:video:duration [2025/05/27 18:34] (current) – [By Packet duration_time] peter
Line 22: Line 22:
  
 <WRAP info> <WRAP info>
-**NOTE:**  This returns an estimate of the duration based on the bitrate and size of the file.+**NOTE:**  This gets the figures directly from ffmpeg. 
 + 
 +  * This returns an estimate of the duration based on the bitrate and size of the file. 
 </WRAP> </WRAP>
  
Line 60: Line 63:
  
 <code bash> <code bash>
-video_pkt_durations=$(ffprobe -v error -select_streams v:$i -skip_frame nokey -show_entries packet=duration_time -of default=nokey=1:noprint_wrappers=1 "input.mkv")+video_pkt_durations=$(ffprobe -v error -select_streams v:-skip_frame nokey -show_entries packet=duration_time -of default=nokey=1:noprint_wrappers=1 "input.mkv")
  
 sum_video_pkt_duration=0 sum_video_pkt_duration=0
Line 68: Line 71:
 #echo "Calculating video pkt_duration..." #echo "Calculating video pkt_duration..."
 for video_pkt_duration in $video_pkt_durations; do for video_pkt_duration in $video_pkt_durations; do
-  sum_video_pkt_duration=$( echo "${sum_video_pkt_duration} + ${video_pkt_duration}" | bc)+  sum_video_pkt_duration=$(echo "${sum_video_pkt_duration} + ${video_pkt_duration}" | bc)
  
   (( count_video_pkt_duration++ ))   (( count_video_pkt_duration++ ))
 done; done;
  
-video_duration=$( echo "scale=6; ${sum_video_pkt_duration} " | bc)+video_duration=$( echo "scale=${precision}; ${sum_video_pkt_duration} " | bc)
  
 echo "DURATION=${video_duration}" echo "DURATION=${video_duration}"
 echo "VIDEO FRAMES=${count_video_pkt_duration}" echo "VIDEO FRAMES=${count_video_pkt_duration}"
 </code> </code>
 +
 +<WRAP info>
 +**NOTE:**  This is very accurate but may take a while.
 +</WRAP>
  
 ---- ----
  
-===== By Size and Bitrate ===== +===== Calculate duration using Size and Bitrate =====
- +
-Calculate it.+
  
 <code bash> <code bash>
 duration=$( echo "scale=6; (${video_size} * 8) / ${bitrate}" | bc) duration=$( echo "scale=6; (${video_size} * 8) / ${bitrate}" | bc)
 </code> </code>
 +
 +----
 +
 +===== Calculate duration using Size and Bitrate =====
 +
 +<code bash>
 +duration = NUMBER_OF_FRAMES / FPS
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  Returns the duration in seconds.
 +</WRAP>
  
 ---- ----
  
  
ffmpeg/video/duration.1748370430.txt.gz · Last modified: 2025/05/27 18:27 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki