====== ffmpeg - Video - Size ======
===== Using Perl Regex =====
ffmpeg -i "input.mkv" -c copy -f null /dev/null 2>&1 | tail -n 2 | grep -Po "(?<=video\:)([0-9]+)"
or
ffmpeg -i "input.mkv" -c copy -f null /dev/null 2>&1 | tail -n 2 | grep -Po "video\:([0-9]+)(?=kB)" | cut -f 2 -d ":
**NOTE:** Gets the size directly from ffmpeg.
----
===== Get the video size from the stream =====
ffprobe -v error -select_streams v:$i -show_entries stream=size -of default=noprint_wrappers=1:nokey=1 "input.mkv" | uniq
**WARNING:** This often returns N/A for some container formats, such as MKV.
----
===== Get the video size from the container =====
ffprobe -v error -select_streams v:0 -show_entries format=size -of default=noprint_wrappers=1:nokey=1 "input.mkv" | uniq
**WARNING:** This gets the entire container size, not just the video stream...
----
===== Calculate video size manually using packet size =====
This method reads each video packet, individually, and totals up each packet size.
* Sums up the **size** attribute of **-show_entries** command.
video_sizes=$(ffprobe -v error -select_streams v:0 -skip_frame nokey -show_entries packet=size -of default=nokey=1:noprint_wrappers=1 "input.mkv")
sum_video_size=0
precision=6
count_video_pkt_size=0
echo "Calculating video size..."
for video_size in $video_sizes; do
(( sum_video_size+=video_size ))
(( count_video_size++ ))
done;
size=$( echo "scale=6; ${sum_video_size}" | bc)
**NOTE:** This is very accurate but may be slow...
----