Skip to content
Snippets Groups Projects
Commit d39081b4 authored by Florian Meißner's avatar Florian Meißner Committed by Florian Meißner
Browse files

- optimize code

- format duration to mmm:ss
- add option to print bitrate in MBs
parent 1645cd21
Branches
No related tags found
No related merge requests found
#!/usr/bin/env fish
argparse 'sort-by=' -- $argv
. (dirname (status --current-filename))/../helpers/numeric.fish
argparse 'sort-by=' 'm/megabytes' -- $argv
set $_flag_sort_by (set -q $_flag_sort_by && echo $_flag_sort_by || echo 3)
function __t-nil_helper_extract --argument-names key
......@@ -12,25 +14,26 @@ end
filter_by_video | while read f
echo -ne $f\t
set len (ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $f | string trim)
echo -ne (math $len / 60)\t
for medium in v a
set out (ffprobe -v error -select_streams $medium -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 $f 2>/dev/null)\t
[ (string trim "$out" | string collect) = 'N/A' ] && set out (ffprobe -v error -show_entries format=bit_rate -of default=noprint_wrappers=1:nokey=1 $f)
echo -ne (string trim $out)\t
end
# set fish_trace 1
set blah (ffprobe -v error -select_streams v -show_entries stream=width,height,bit_rate,r_frame_rate -of default=noprint_wrappers=1 $f 2>/dev/null)
set blah (ffprobe -v error -select_streams v -show_entries stream=width,height,r_frame_rate:format=duration,bit_rate -of default=noprint_wrappers=1 $f 2>/dev/null | string trim)
set duration (__t-nil_helper_extract duration $blah)
set width (__t-nil_helper_extract width $blah)
set height (__t-nil_helper_extract height $blah)
set fps (__t-nil_helper_extract r_frame_rate $blah)
set bit_rate (__t-nil_helper_extract bit_rate $blah)
set bits_per_pixel (math $bit_rate / \( $width \* $height \* $fps \) )
echo -ne $bits_per_pixel
# if all values are there, calc bits per pixel
for x in blah width height fps bit_rate
__t-nil_helper__is_numeric $$x || set bits_per_pixel "N/A"
end
set -q bits_per_pixel && [ "$bits_per_pixel" != "N/A" ] && set bit_rate (math $bit_rate / \( $width \* $height \* $fps \) )
# formatting at the end, so values can be used for calculations until then
set duration (math --scale 0 $duration / 60):(math --scale 0 $duration % 60 | string pad --char 0 --width 2)
set -q _flag_megabytes && [ "$bit_rate" != "N/A" ] && set bit_rate (math -s 2 $bit_rate / 1024^2)' Mb/s'
echo -ne (string join \t $duration $bit_rate $width"x"$height $fps $bits_per_pixel)
echo
end | pv -l | column -s\t -o\t -t | sort -nt\t -k$_flag_sort_by
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment