From 674406054b3654a27ab58d9449a728a37866b57c Mon Sep 17 00:00:00 2001 From: Spencer Brower Date: Sun, 3 Mar 2024 00:48:03 -0500 Subject: [PATCH] docs: Added *more* examples to `README.md`. --- .gomplate.yml | 6 +++- Makefile | 7 +++-- README.md | 48 ++++++++++++++++++++++++++++++ README.md.tmpl | 15 ++++++++++ examples/dimensions.nu | 10 +++++++ examples/ffprobe-multiple-files.nu | 13 ++++++++ examples/ffprobe.nu | 7 +++-- examples/streams-audio.nu | 10 +++++++ examples/streams-video.nu | 10 +++++++ 9 files changed, 121 insertions(+), 5 deletions(-) create mode 100755 examples/dimensions.nu create mode 100755 examples/ffprobe-multiple-files.nu create mode 100755 examples/streams-audio.nu create mode 100755 examples/streams-video.nu diff --git a/.gomplate.yml b/.gomplate.yml index 202582f..460f737 100644 --- a/.gomplate.yml +++ b/.gomplate.yml @@ -7,5 +7,9 @@ plugins: ffprobe: ./get_ffprobe_commands_table version: ./nu_version ffprobe_example: ./examples/ffprobe.nu -pluginTimeout: 10s + ffprobe_multiple_files_example: ./examples/ffprobe-multiple-files.nu + ffprobe_streams_audio_example: ./examples/streams-audio.nu + ffprobe_streams_video_example: ./examples/streams-video.nu + ffprobe_dimensions_example: ./examples/dimensions.nu +#pluginTimeout: 10s diff --git a/Makefile b/Makefile index 456f985..7b7f969 100644 --- a/Makefile +++ b/Makefile @@ -2,12 +2,15 @@ SHELL:=/nix/store/zicq9x6aznw7x202564p8iy0rm04py6l-nushell-0.89.0/bin/nu all: README.md -README.md: examples/videos/sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4 - gomplate --config .gomplate.yml -V +README.md: examples/videos/sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4 examples/videos/sample-videos.com/video321/mkv/720/big_buck_bunny_720p_1mb.mkv + gomplate --config .gomplate.yml examples/videos/sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4: wget -x -P examples/videos https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4 +examples/videos/sample-videos.com/video321/mkv/720/big_buck_bunny_720p_1mb.mkv: + wget -x -P examples/videos https://sample-videos.com/video321/mkv/720/big_buck_bunny_720p_1mb.mkv + clean: rm -f README.md diff --git a/README.md b/README.md index e9d3d6e..5edd41e 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,56 @@ Utility commands for working with ffmpeg in nushell. ``` - `ffprobe` multiple files at once +```nu +> ffprobe https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4 https://sample-videos.com/video321/mkv/720/big_buck_bunny_720p_1mb.mkv +╭────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─────╮ +│ # │ streams │ ... │ +├────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────┤ +│ 0 │ ╭───┬────────────┬───────────────────────────────────────────┬─────────┬────────────┬──────────────────┬────────────┬─────╮ │ ... │ +│ │ │ # │ codec_name │ codec_long_name │ profile │ codec_type │ codec_tag_string │ codec_tag │ ... │ │ │ +│ │ ├───┼────────────┼───────────────────────────────────────────┼─────────┼────────────┼──────────────────┼────────────┼─────┤ │ │ +│ │ │ 0 │ h264 │ H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 │ Main │ video │ avc1 │ 0x31637661 │ ... │ │ │ +│ │ │ 1 │ aac │ AAC (Advanced Audio Coding) │ LC │ audio │ mp4a │ 0x6134706d │ ... │ │ │ +│ │ ╰───┴────────────┴───────────────────────────────────────────┴─────────┴────────────┴──────────────────┴────────────┴─────╯ │ │ +│ 1 │ ╭───┬────────────┬─────────────────────────────┬────────────────┬────────────┬──────────────────┬───────────┬───────┬─────╮ │ ... │ +│ │ │ # │ codec_name │ codec_long_name │ profile │ codec_type │ codec_tag_string │ codec_tag │ width │ ... │ │ │ +│ │ ├───┼────────────┼─────────────────────────────┼────────────────┼────────────┼──────────────────┼───────────┼───────┼─────┤ │ │ +│ │ │ 0 │ mpeg4 │ MPEG-4 part 2 │ Simple Profile │ video │ [0][0][0][0] │ 0x0000 │ 1280 │ ... │ │ │ +│ │ │ 1 │ aac │ AAC (Advanced Audio Coding) │ LC │ audio │ [0][0][0][0] │ 0x0000 │ ❎ │ ... │ │ │ +│ │ ╰───┴────────────┴─────────────────────────────┴────────────────┴────────────┴──────────────────┴───────────┴───────┴─────╯ │ │ +╰────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴─────╯ + +``` + - Use `streams`, `streams video`, and `streams audio` to filter `ffprobe` output + +```nu +> ffprobe https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4 | streams video +╭────┬─────────────┬────────────────────────────────────────────┬──────────┬─────────────┬───────────────────┬─────────────┬────────┬─────╮ +│ # │ codec_name │ codec_long_name │ profile │ codec_type │ codec_tag_string │ codec_tag │ width │ ... │ +├────┼─────────────┼────────────────────────────────────────────┼──────────┼─────────────┼───────────────────┼─────────────┼────────┼─────┤ +│ 0 │ h264 │ H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 │ Main │ video │ avc1 │ 0x31637661 │ 1280 │ ... │ +╰────┴─────────────┴────────────────────────────────────────────┴──────────┴─────────────┴───────────────────┴─────────────┴────────┴─────╯ + +> ffprobe https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4 | streams audio +╭────┬─────────────┬──────────────────────────────┬─────────┬────────────┬──────────────────┬────────────┬────────────┬─────────────┬─────╮ +│ # │ codec_name │ codec_long_name │ profile │ codec_type │ codec_tag_string │ codec_tag │ sample_fmt │ sample_rate │ ... │ +├────┼─────────────┼──────────────────────────────┼─────────┼────────────┼──────────────────┼────────────┼────────────┼─────────────┼─────┤ +│ 1 │ aac │ AAC (Advanced Audio Coding) │ LC │ audio │ mp4a │ 0x6134706d │ fltp │ 48000 │ ... │ +╰────┴─────────────┴──────────────────────────────┴─────────┴────────────┴──────────────────┴────────────┴────────────┴─────────────┴─────╯ + +``` + - get the `dimensions` of a video stream as a record + +```nu +> ffprobe https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4 | streams video | first | dimensions +╭────────┬──────╮ +│ width │ 1280 │ +│ height │ 720 │ +╰────────┴──────╯ + +``` - Tab-completion for filter options. i.e. `fps --round` will yield `zero inf down up near` - Apply and parse complex filters to a video (Work In Progress) diff --git a/README.md.tmpl b/README.md.tmpl index 469228b..f7c96de 100644 --- a/README.md.tmpl +++ b/README.md.tmpl @@ -17,8 +17,23 @@ Utility commands for working with ffmpeg in nushell. ``` - `ffprobe` multiple files at once + +```nu +{{ ffprobe_multiple_files_example }} +``` + - Use `streams`, `streams video`, and `streams audio` to filter `ffprobe` output + +```nu +{{ ffprobe_streams_video_example }} +{{ ffprobe_streams_audio_example }} +``` + - get the `dimensions` of a video stream as a record + +```nu +{{ ffprobe_dimensions_example }} +``` - Tab-completion for filter options. i.e. `fps --round` will yield `zero inf down up near` - Apply and parse complex filters to a video (Work In Progress) diff --git a/examples/dimensions.nu b/examples/dimensions.nu new file mode 100755 index 0000000..ff1d4e8 --- /dev/null +++ b/examples/dimensions.nu @@ -0,0 +1,10 @@ +#!/usr/bin/env nu + +use ../ffprobe ["main" "dimensions" "streams video"]; + +# Extract the dimensions of a video stream +def main [] { + echo "> ffprobe https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4 | streams video | first | dimensions" + ffprobe $'($env.FILE_PWD)/videos/sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4' + | streams video | first | dimensions +} diff --git a/examples/ffprobe-multiple-files.nu b/examples/ffprobe-multiple-files.nu new file mode 100755 index 0000000..f728d14 --- /dev/null +++ b/examples/ffprobe-multiple-files.nu @@ -0,0 +1,13 @@ +#!/usr/bin/env nu + +use ../ffprobe; + +# Use ffprobe on mutliple files at once +def main [] { + echo "> ffprobe https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4 https://sample-videos.com/video321/mkv/720/big_buck_bunny_720p_1mb.mkv" + ( + ffprobe + $'($env.FILE_PWD)/videos/sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4' + $'($env.FILE_PWD)/videos/sample-videos.com/video321/mkv/720/big_buck_bunny_720p_1mb.mkv' + ) +} diff --git a/examples/ffprobe.nu b/examples/ffprobe.nu index 80cf7a5..a15f771 100755 --- a/examples/ffprobe.nu +++ b/examples/ffprobe.nu @@ -2,5 +2,8 @@ use ../ffprobe; -echo "> ffprobe https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4" -ffprobe $'($env.FILE_PWD)/videos/sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4' +# Return a table from ffprobe +def main [] { + echo "> ffprobe https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4" + ffprobe $'($env.FILE_PWD)/videos/sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4' +} diff --git a/examples/streams-audio.nu b/examples/streams-audio.nu new file mode 100755 index 0000000..10f4c3a --- /dev/null +++ b/examples/streams-audio.nu @@ -0,0 +1,10 @@ +#!/usr/bin/env nu + +use ../ffprobe ["main" "streams audio"]; + +# Extract the audio streams from a video +def main [] { + echo "> ffprobe https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4 | streams audio" + ffprobe $'($env.FILE_PWD)/videos/sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4' + | streams audio +} diff --git a/examples/streams-video.nu b/examples/streams-video.nu new file mode 100755 index 0000000..1662e0e --- /dev/null +++ b/examples/streams-video.nu @@ -0,0 +1,10 @@ +#!/usr/bin/env nu + +use ../ffprobe ["main" "streams video"]; + +# Extract the video streams from a video +def main [] { + echo "> ffprobe https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4 | streams video" + ffprobe $'($env.FILE_PWD)/videos/sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4' + | streams video +}