ffmpeg:video:duration
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
ffmpeg:video:duration [2025/05/27 18:08] – created peter | ffmpeg:video:duration [2025/05/27 18:34] (current) – [By Packet duration_time] peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== ffmpeg - Video - Duration ====== | ====== ffmpeg - Video - Duration ====== | ||
+ | |||
+ | ===== Using Regex ===== | ||
<code bash> | <code bash> | ||
Line 20: | Line 22: | ||
<WRAP info> | <WRAP info> | ||
- | **NOTE: | + | **NOTE: |
+ | |||
+ | * This returns an estimate of the duration based on the bitrate and size of the file. | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Getting the data from the video stream ===== | ||
+ | |||
+ | <code bash> | ||
+ | ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1: | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Getting the data from the container ===== | ||
+ | |||
+ | <code bash> | ||
+ | ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1: | ||
+ | |||
+ | ffprobe -v error -select_streams v:0 -show_entries format=duration -of default=noprint_wrappers=1: | ||
+ | </ | ||
+ | |||
+ | <WRAP important> | ||
+ | **WARNING: | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== By Packet duration_time ===== | ||
+ | |||
+ | This method reads each video packet, individually, | ||
+ | |||
+ | * Sums up the **duration_time** of the **-show_entries** command. | ||
+ | |||
+ | <code bash> | ||
+ | video_pkt_durations=$(ffprobe -v error -select_streams v:0 -skip_frame nokey -show_entries packet=duration_time -of default=nokey=1: | ||
+ | |||
+ | sum_video_pkt_duration=0 | ||
+ | precision=6 | ||
+ | count_video_pkt_duration=0 | ||
+ | |||
+ | #echo " | ||
+ | for video_pkt_duration in $video_pkt_durations; | ||
+ | sum_video_pkt_duration=$(echo " | ||
+ | |||
+ | (( count_video_pkt_duration++ )) | ||
+ | done; | ||
+ | |||
+ | video_duration=$( echo " | ||
+ | |||
+ | echo " | ||
+ | echo "VIDEO FRAMES=${count_video_pkt_duration}" | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Calculate duration using Size and Bitrate ===== | ||
+ | |||
+ | <code bash> | ||
+ | duration=$( echo " | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Calculate duration using Size and Bitrate ===== | ||
+ | |||
+ | <code bash> | ||
+ | duration = NUMBER_OF_FRAMES / FPS | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
</ | </ | ||
ffmpeg/video/duration.1748369288.txt.gz · Last modified: 2025/05/27 18:08 by peter