Skip to content

Instantly share code, notes, and snippets.

@gullinbursti
Last active August 13, 2023 21:58
Show Gist options
  • Save gullinbursti/2cedb943ef651e4ed27f017a5f078fdc to your computer and use it in GitHub Desktop.
Save gullinbursti/2cedb943ef651e4ed27f017a5f078fdc to your computer and use it in GitHub Desktop.
ffprobe JSON w/ jq
f=~/Desktop/ama_stac-x3h-1320s_an.mp4
ffprobe -i $f -of json -show_streams 2> /dev/null | jq --color-output \
--arg created_ts "`stat -f '%B' -t '%s' ${f}`" \
--arg modified_ts "`stat -f '%c' -t '%s' ${f}`" \
--arg exif_ts "`exiftool -fast -quiet -ignoreMinorErrors -s3 -forcePrint -dateFormat '%s' -time:all --File:MDItemContentCreationDate_Ranking --File:MDItemContentModificationDate_Ranking --File:MDItemDateAdded_Ranking --File:MDItemInterestingDate_Ranking ${f} | tr '\n' ',' | sed 's/^\(.*\),$/\[\1\]/g'`" \
'.streams[0]? |
.bit_rate = (.bit_rate | tonumber) |
.full_seconds = (.duration | tonumber) |
.exif_ts = (($exif_ts | gsub(",?0000:00:00 00:00:00,?"; "")) | fromjson) |
.tot_frames = (.nb_frames | tonumber) | .file_epoch = ($created_ts | tonumber) | .moddified_epoch = ($modified_ts | tonumber) |
.epochs = {
created : ($created_ts | tonumber),
modified : ($modified_ts | tonumber),
exif : (.exif_ts | min),
meta : .tags.creation_time? | (if(. != null) then ((. | sub(".0{6}Z$"; "Z") | fromdate) - 3600) else ($created_ts | tonumber) end)
} | .timestamps = .epochs |
.f_rates = {
avg_base : ((.avg_frame_rate | sub("^(?<base>[0-9]+)\/(?<radix>[0-9]+)$"; "\(.base)")) | tonumber),
avg_radix : ((.avg_frame_rate | sub("^(?<base>[0-9]+)\/(?<radix>[0-9]+)$"; "\(.radix)")) | tonumber),
rel_base : ((.r_frame_rate | sub("^(?<base>[0-9]+)\/(?<radix>[0-9]+)$"; "\(.base)")) | tonumber),
rel_radix : ((.r_frame_rate | sub("^(?<base>[0-9]+)\/(?<radix>[0-9]+)$"; "\(.radix)")) | tonumber) } |
.dur = {
hrs : (((.full_seconds / 3600) | floor) | tostring),
min : ((((.full_seconds % 3600) / 60) | floor) | tostring),
sec : ((.full_seconds % 60) + (((((.duration | sub("[0-9]*.(?<dec>[0-9]+)$"; "\(.dec)")) | tonumber) / 1000) | round) / 1000) | tostring)
} | { tags,
codec_name,
pix_fmt,
tot_frames,
full_seconds,
bit_rate,
framerate_avg : .f_rates | ((((.avg_base / .avg_radix) * 100) | round) / 100),
pri_attribs : {
dimensions : {
org : ((.width | tostring)+"x"+(.height | tostring)),
dbl : (((.width * 2.000) | tostring)+"x"+((.height * 2.000) | tostring)),
half : (((.width * 0.500) | tostring)+"x"+((.height * 0.500) | tostring)),
third : (((.width * (1/3)) | tostring)+"x"+((.height * (1/3)) | tostring)),
quart : (((.width * 0.250) | tostring)+"x"+((.height * 0.250) | tostring))
}, duration : .dur | (
(if((.hrs | tonumber) >= 10) then .hrs else ("0"+.hrs) end)+":"+
(if((.min | tonumber) >= 10) then .min else ("0"+.min) end)+":"+
(if((.sec | tonumber) >= 10) then .sec else ("0"+.sec) end)
), framerate : .f_rates | ((((.rel_base / .rel_radix) * 100) | round) / 100),
human_bit_rate : .bit_rate | (
(if(. < 1000) then ((.bit_rate | tostring) | sub("$"; " b"))
else (if(. > 1000000) then ((((((. / 1000000) * 100) | round) / 100) | tostring) | sub("$"; " mb"))
else ((((((. / 1000) * 100) | round) / 100) | tostring) | sub("$"; " kb")) end) end) |
tostring | sub("$"; "/s")
)
}, timestamps : .epochs | {
created : ((.created | todate) | ascii_upcase),
modified : ((.modified | todate) | ascii_upcase),
exif : ((.exif | todate) | ascii_upcase),
meta : ((.meta | todate) | ascii_upcase),
earliest : ((([.created, .modified, .exif, .meta] | min) | strflocaltime("%d-%b-%Y %T%z")) | ascii_upcase), latest : ((([.created, .modified, .exif, .meta] | max) | strflocaltime("%d-%b-%Y %T%z")) | ascii_upcase)
}
}
| del(.dur) | del(.f_rates) | del(.epochs) | del(.exif_ts)
'
ffprobe -hide_banner -i $f -of json -show_streams 2> /dev/null
@gullinbursti
Copy link
Author

Prerequisites (OSX / macOS):

  • homebrew / macports
  • exiftool
  • ffprobe
  • gdate
  • jq

brew install coreutils exiftool ffmpeg jq
port install coreutils exiftool ffmpeg jq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment