From ecba00ff1d1905415ca880dd38bbadc878df8aa5 Mon Sep 17 00:00:00 2001 From: James Howell Date: Sun, 16 Aug 2026 10:54:34 +0000 Subject: [PATCH] Add termux-camera-video wrapper script --- CMakeLists.txt | 1 + scripts/termux-camera-video.in | 94 ++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 scripts/termux-camera-video.in diff --git a/CMakeLists.txt b/CMakeLists.txt index c8b1f9e..256cc93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ set(script_files scripts/termux-call-log scripts/termux-camera-info scripts/termux-camera-photo + scripts/termux-camera-video scripts/termux-clipboard-get scripts/termux-clipboard-set scripts/termux-contact-list diff --git a/scripts/termux-camera-video.in b/scripts/termux-camera-video.in new file mode 100644 index 0000000..5cf604f --- /dev/null +++ b/scripts/termux-camera-video.in @@ -0,0 +1,94 @@ +#!@TERMUX_PREFIX@/bin/bash +set -e + +SCRIPTNAME=termux-camera-video + +show_usage () { + echo "Usage: $SCRIPTNAME [args]" + echo "Record video using a camera on your device" + echo + echo "-h Shows this help" + echo "-d Start recording w/ defaults" + echo "-f Start recording to specific file (must end in .mp4)" + echo "-c Start recording using specified camera id (see termux-camera-info)" + echo "-l Start recording w/ specified duration limit (in seconds, unlimited for 0)" + echo "-b Start recording w/ specified video bitrate (in kbps)" + echo "-r Start recording w/ specified frame rate" + echo "-n Start recording w/o audio" + echo "-i Get info about current recording" + echo "-q Quits recording" +} + +usage_error () { + echo + show_usage + exit 1 +} + +sole() { + if [ "$1 $2" != "-$option $OPTARG" ] || [ $# -gt 2 ]; then + echo "ERROR: No other options should be specified with -$option!" + usage_error + fi +} + +add_params() { + for i in "$@"; do + params[index++]="$i" + done +} + +call_api () { + @TERMUX_PREFIX@/libexec/termux-api CameraVideo "$@" +} + +while getopts h,f:,c:,l:,b:,r:,n,d,i,q option +do + case "$option" in + h) sole "$@" + ;; + f) record=yes + dir="$(dirname "$OPTARG")" + file="$(basename "$OPTARG")" + dir="$(realpath "$dir")" + add_params --es file "$dir/$file" + ;; + c) record=yes + add_params --es camera "$OPTARG" + ;; + # API takes limit in milliseconds + l) record=yes + add_params --ei limit $((OPTARG * 1000)) + ;; + # API takes bitrate in bps + b) record=yes + add_params --ei bitrate $((OPTARG * 1000)) + ;; + r) record=yes + add_params --ei fps $((OPTARG)) + ;; + n) record=yes + add_params --ez audio false + ;; + d) record=yes + ;; + i) sole "$@" + add_params -a info + ;; + q) sole "$@" + add_params -a quit + ;; + *) usage_error + ;; + esac +done + +if [ -v record ]; then + add_params -a record +fi + +if [ -v params ]; then + call_api "${params[@]}" +else + show_usage +fi