Skip to content

Commit

Permalink
mp4,matroska: Add *_path/0 variant that uses format_root
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Nov 29, 2021
1 parent c8fad57 commit db586eb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
17 changes: 14 additions & 3 deletions format/matroska/matroska.jq
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# <matroska value> | matroska_path(".Segment.Tracks[0].TrackEntry[1].CodecID") -> element
# <matroska value> | matroska_path(<matroska value>) -> ".Segment.Tracks[0]"
def matroska_path(p): tree_path(.elements; .id; p);
# <matroska root value> | matroska_path(".Segment.Tracks[0]") -> element
# <matroska root value> | matroska_path -> ".Segment.Tracks[0]"
# <matroska root value> | matroska_path(<matroska root value>) -> ".Segment.Tracks[0]"
def matroska_path(p):
_decode_value(
( if format != "matroska" then error("not matroska format") end
| tree_path(.elements; .id; p)
)
);
def matroska_path:
( . as $c
| format_root
| matroska_path($c)
);
10 changes: 10 additions & 0 deletions format/matroska/testdata/path.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,15 @@ $ fq -d matroska 'matroska_path(".Segment.Tracks[0].TrackEntry[0].CodecID")' /av
0x150| 8f | . | size: 15
0x150| 56 5f 4d 50 45 47 34 2f 49 53 4f 2f| V_MPEG4/ISO/| value: "V_MPEG4/ISO/AVC"
0x160|41 56 43 |AVC |
$ fq -d matroska 'matroska_path(".Segment.Tracks[0].TrackEntry[0].CodecID") | matroska_path' /avc.mkv
".Segment.Tracks.TrackEntry.CodecID"
$ fq -d matroska 'matroska_path(matroska_path(".Segment.Tracks[0].TrackEntry[0].CodecID"))' /avc.mkv
".Segment.Tracks.TrackEntry.CodecID"
$ fq -n '"a" | raw | matroska_path(".Segment")'
exitcode: 5
stderr:
error: not matroska format
$ fq -n '1 | matroska_path(".Segment")'
exitcode: 5
stderr:
error: expected a decode value but got: number (1)
17 changes: 14 additions & 3 deletions format/mp4/mp4.jq
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# <mp4 value> | mp4_path(".moov.trak[1]") -> box
# <mp4 value> | mp4_path(<mp4 value>) -> ".moov.trak"
def mp4_path(p): tree_path(.boxes; .type; p);
# <mp4 root> | mp4_path(".moov.trak[1]") -> box
# box -> | mp4_path -> ".moov.trak[1]"
# box -> | mp4_path(<mp4 root>) -> ".moov.trak[1]"
def mp4_path(p):
_decode_value(
( if format != "mp4" then error("not mp4 format") end
| tree_path(.boxes; .type; p)
)
);
def mp4_path:
( . as $c
| format_root
| mp4_path($c)
);
10 changes: 10 additions & 0 deletions format/mp4/testdata/path.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,15 @@ $ fq -d mp4 'mp4_path(".moov.trak[1]")' /fragmented.mp4
0x280| 00 00 00 5c| ...\| boxes: [2]
0x290|74 6b 68 64 00 00 00 03 00 00 00 00 00 00 00 00|tkhd............|
* |until 0x442.7 (439) | |
$ fq -d mp4 'mp4_path(".moov.trak[1]") | mp4_path' /fragmented.mp4
".moov.trak[1]"
$ fq -d mp4 'mp4_path(mp4_path(".moov.trak[1]"))' /fragmented.mp4
".moov.trak[1]"
$ fq -n '"a" | raw | mp4_path(".moov")'
exitcode: 5
stderr:
error: not mp4 format
$ fq -n '1 | mp4_path(".moov")'
exitcode: 5
stderr:
error: expected a decode value but got: number (1)

0 comments on commit db586eb

Please sign in to comment.