diff --git a/README.md b/README.md index 06abc23..a3af43b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,26 @@ -# +# nu-ffmpeg + +Utility commands for working with ffmpeg in nushell. + +## Capabilities + +- Return tables from `ffprobe` +- `ffprobe` multiple files at once +- Use `streams`, `streams video`, and `streams audio` to filter `ffprobe` output +- get the `dimensions` of a video stream as a record +- Apply and parse complex filters to a video (Work In Progress) + +## Setup + +The `ffmpeg` and `ffprobe` commands are required to be installed and available +in your path; they are not installed for you. + +Currently nushell versions 0.87.0 - 0.88.1 are supported. + +After that, clone this repository and add the following code to your scripts, +or to your `config.nu` file: ```nu -use ./ffprobe +use /ffprobe +use /filters * +``` diff --git a/ffprobe b/ffprobe index 8b88819..865f6b7 100755 --- a/ffprobe +++ b/ffprobe @@ -4,14 +4,14 @@ # Multimedia stream analyzer. export def main [ ...input_files: path -] { +]: nothing -> table { $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 [] { +export def streams []: table -> table { let streams = ($in | get streams); match ($streams | describe) { @@ -21,16 +21,16 @@ export def streams [] { } # Retrieve all the video streams from a list of ffprobe outputs -export def "streams video" [] { +export def "streams video" []: table -> table { $in | streams | where codec_type == "video" } # Retrieve all the audio streams from a list of ffprobe outputs -export def "streams audio" [] { +export def "streams audio" []: table -> table { $in | streams | where codec_type == "audio" } # Get the dimensions of a video stream -export def "dimensions" [] { +export def "dimensions" []: table -> record { $in | select width height } diff --git a/filters.nu b/filters.nu index dd21249..175caaf 100755 --- a/filters.nu +++ b/filters.nu @@ -1,22 +1,22 @@ #!/usr/bin/env -S nu --stdin -def "parse filter" [ +export def "parse filter" [ ] { $in | parse --regex '^(?[^=]+)=(?.*)' | first | - update params {|row| $row.params | parse --regex `(?[^=]+)=(?[^:]+):?` } + update params { parse --regex `(?[^=]+)=(?[^:]+):?` } } -def "filter to-string" [] { +export def "filter to-string" [] { each { |filter| $'($filter.name)=($filter.params | format '{param}={value}')' } | - str join ':' + str join ':' } -def "complex-filters to-string" [ +export def "complex-filters to-string" [ --pretty-print (-p) ]: table, filters: table>, output: string> -> string { $in | update filters { - |$row| $row.filters | flatten | filter to-string - } | update input { |row| - $row.input | str join '][' + flatten | filter to-string + } | update input { + str join '][' } | format '[{input}]{filters}[{output}]' | str join (";" + (if $pretty_print { "\n" } else { "" })) | str replace --all '[]' '' } diff --git a/flake.nix b/flake.nix index 69520f0..1496599 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "A very basic flake"; + description = "Utility commands for working with video files in nushell"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";