feat: Initial commit.

This commit is contained in:
Spencer Brower
2024-01-08 13:35:14 -05:00
commit 555073c428
7 changed files with 114 additions and 0 deletions

1
.envrc Normal file
View File

@@ -0,0 +1 @@
use flake;

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.direnv

4
README.md Normal file
View File

@@ -0,0 +1,4 @@
#
```nu
use ./ffprobe

36
ffprobe Executable file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/env nu
# vim: filetype=nu :
# Multimedia stream analyzer.
export def main [
...input_files: path
] {
$input_files | each {
^ffprobe -v quiet -print_format json -show_format -show_streams $in | from json
}
}
# Retrieve all the streams from a list of ffprobe outputs
export def streams [] {
let streams = ($in | get streams);
match ($streams | describe) {
'list<list<any>>' => ($streams | flatten),
_ => $streams
}
}
# Retrieve all the video streams from a list of ffprobe outputs
export def "streams video" [] {
$in | streams | where codec_type == "video"
}
# Retrieve all the audio streams from a list of ffprobe outputs
export def "streams audio" [] {
$in | streams | where codec_type == "audio"
}
# Get the dimensions of a video stream
export def "dimensions" [] {
$in | select width height
}

22
filters.nu Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env -S nu --stdin
def "parse filter" [
] {
$in | parse --regex '^(?<name>[^=]+)=(?<params>.*)' | first |
update params {|row| $row.params | parse --regex `(?<param>[^=]+)=(?<value>[^:]+):?` }
}
def "filter to-string" [] {
each { |filter| $'($filter.name)=($filter.params | format '{param}={value}')' } |
str join ':'
}
def "complex-filters to-string" [
--pretty-print (-p)
]: table<input: list<string>, filters: table<name: string, params: table<param: string, value: string>>, output: string> -> string {
$in | update filters {
|$row| $row.filters | flatten | filter to-string
} | update input { |row|
$row.input | str join ']['
} | format '[{input}]{filters}[{output}]' | str join (";" + (if $pretty_print { "\n" } else { "" })) | str replace --all '[]' ''
}

27
flake.lock generated Normal file
View File

@@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1704538339,
"narHash": "sha256-1734d3mQuux9ySvwf6axRWZRBhtcZA9Q8eftD6EZg6U=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "46ae0210ce163b3cba6c7da08840c1d63de9c701",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

23
flake.nix Normal file
View File

@@ -0,0 +1,23 @@
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in
{
devShells.x86_64-linux.default = pkgs.mkShell {
packages = with pkgs; [
ffmpeg
sbcl
nushellFull
];
};
};
}