mirror of
https://github.com/wader/fq.git
synced 2024-10-26 11:49:54 +03:00
dev: Move examples and snippets to wiki
This commit is contained in:
parent
d62bb59f66
commit
9cd1d0f3e3
@ -1,55 +0,0 @@
|
||||
#!/usr/bin/env fq -d mp4 -f
|
||||
|
||||
# TODO: esds, make fancy printer? shared?
|
||||
# TODO: handle -1 media_time
|
||||
# TODO: fragmented mp4
|
||||
|
||||
# root
|
||||
# moov
|
||||
# mvhd (movie header)
|
||||
# trak (track)
|
||||
# mdia
|
||||
# mdhd (media header)
|
||||
# hdlr (handler?)
|
||||
# minf
|
||||
# stbl
|
||||
# stsd (sample description)
|
||||
# elst (edit list)
|
||||
|
||||
( first(.boxes[] | select(.type == "moov")?)
|
||||
| first(.boxes[] | select(.type == "mvhd")?) as $mvhd
|
||||
| {
|
||||
duration: $mvhd.duration,
|
||||
time_scale: $mvhd.time_scale,
|
||||
duration_s: ($mvhd.duration / $mvhd.time_scale),
|
||||
tracks:
|
||||
[ .boxes[]
|
||||
| select(.type == "trak")
|
||||
| first(.. | select(.type == "mdhd")?) as $mdhd
|
||||
| first(.. | select(.type == "hdlr")?) as $hdlr
|
||||
| first(.. | select(.type == "stsd")?) as $stsd
|
||||
| first(.. | select(.type == "elst")?) as $elst
|
||||
| first(.. | select(.type == "stts")?) as $stts
|
||||
| ([$stts.entries[] | .count * .delta] | add) as $stts_sum
|
||||
| {
|
||||
component_type: $hdlr.component_subtype,
|
||||
# the sample descriptors are handled as boxes by the mp4 decoder
|
||||
data_format: $stsd.boxes[0].type,
|
||||
media_scale: $mdhd.time_scale,
|
||||
edit_list:
|
||||
[ $elst.entries[]
|
||||
| {
|
||||
track_duration: .segment_duration,
|
||||
media_time: .media_time,
|
||||
track_duration_s: (.segment_duration / $mvhd.time_scale),
|
||||
media_time_s: (.media_time / $mdhd.time_scale)
|
||||
}
|
||||
],
|
||||
stts: {
|
||||
sum: $stts_sum,
|
||||
sum_s: ($stts_sum / $mdhd.time_scale)
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
@ -1,84 +0,0 @@
|
||||
def protobuf_to_value:
|
||||
.fields | map({(.name | tostring): (.enum // .value)}) | add;
|
||||
|
||||
# converted from https://github.com/FFmpeg/FFmpeg/blob/870bfe16a12bf09dca3a4ae27ef6f81a2de80c40/libavutil/display.c av_display_rotation_get
|
||||
def mp4_matrix_structure_rotation:
|
||||
( .a as $s0
|
||||
| .c as $s3
|
||||
| .b as $s1
|
||||
| .d as $s4
|
||||
| ($s0*$s0 + $s3*$s3 | sqrt) as $scale0
|
||||
| ($s1*$s1 + $s4*$s4 | sqrt) as $scale1
|
||||
| atan2($s1/$scale1; $s0 / $scale0) * 180 / 3.14159265359
|
||||
| -round
|
||||
);
|
||||
|
||||
def flac_dump:
|
||||
[ "fLaC"
|
||||
, first(.. | select(format == "flac_metadatablocks"))
|
||||
, (.. | select(format == "flac_frame"))
|
||||
] | tobits;
|
||||
|
||||
def urldecode:
|
||||
gsub(
|
||||
"%(?<c>[a-fA-F0-9]{2})";
|
||||
( .c
|
||||
| ascii_downcase
|
||||
| explode
|
||||
# "0"-"9" or "a"-"f"
|
||||
| map(.-48 | if .>=49 then .-39 else . end)
|
||||
| [.[0]*16+.[1]]
|
||||
| implode
|
||||
)
|
||||
);
|
||||
|
||||
# see all first frames where sample_rate changes
|
||||
# ex: .frames | changes(.header.sample_rate)
|
||||
def changes(f): streaks_by(f)[].[0];
|
||||
|
||||
def to_radix62sp: to_radix(62; "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
def from_radix62sp: from_radix(62; {
|
||||
"0": 0, "1": 1, "2": 2, "3": 3,"4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9,
|
||||
"a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15, "g": 16,
|
||||
"h": 17, "i": 18, "j": 19, "k": 20, "l": 21, "m": 22, "n": 23,
|
||||
"o": 24, "p": 25, "q": 26, "r": 27, "s": 28, "t": 29, "u": 30,
|
||||
"v": 31, "w": 32, "x": 33, "y": 34, "z": 35,
|
||||
"A": 36, "B": 37, "C": 38, "D": 39, "E": 40, "F": 41, "G": 42,
|
||||
"H": 43, "I": 44, "J": 45, "K": 46, "L": 47, "M": 48, "N": 49,
|
||||
"O": 50, "P": 51, "Q": 52, "R": 53, "S": 54, "T": 55, "U": 56,
|
||||
"V": 57, "W": 58, "X": 59, "Y": 60, "Z": 61
|
||||
});
|
||||
|
||||
# "01:09:55.76" -> 4195.76
|
||||
# 4195.76 -> "01:09:55.76"
|
||||
def duration:
|
||||
def lpad($s; $w): ($s * ($w+1-length))[1:] + .;
|
||||
def _string:
|
||||
( split(":")
|
||||
| map(tonumber)
|
||||
| reverse
|
||||
| [foreach .[] as $n (0; . + 1; pow(60; .-1) * $n)]
|
||||
# sum smallest to largest seem to improve precision
|
||||
| sort
|
||||
| reverse
|
||||
| add
|
||||
);
|
||||
def _number:
|
||||
if . == 0 then 0
|
||||
else
|
||||
[ ( [ (recurse(if . > 0 then intdiv(.; 60) else empty end) | . % 60)]
|
||||
| reverse
|
||||
| .[1:]
|
||||
| map(tostring | lpad("0"; 2))
|
||||
| join(":")
|
||||
)
|
||||
# ugly but float is not accurate enough
|
||||
, ( tostring
|
||||
| split(".")[1] // empty
|
||||
| ".", .
|
||||
)
|
||||
] | join("")
|
||||
end;
|
||||
if type == "string" then _string
|
||||
elif type == "number" then _number
|
||||
else error("expected string or number") end;
|
Loading…
Reference in New Issue
Block a user