From 20c0cfa111dc4d693ecb01938ca477965813b1fe Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Tue, 26 May 2026 19:21:54 +0900 Subject: [PATCH] first commit --- cam | 32 ++++++++++++++++++++++++++++++++ camv | 29 +++++++++++++++++++++++++++++ scr | 26 ++++++++++++++++++++++++++ scrv | 41 +++++++++++++++++++++++++++++++++++++++++ trk | 16 ++++++++++++++++ 5 files changed, 144 insertions(+) create mode 100755 cam create mode 100755 camv create mode 100755 scr create mode 100755 scrv create mode 100755 trk diff --git a/cam b/cam new file mode 100755 index 0000000..3878414 --- /dev/null +++ b/cam @@ -0,0 +1,32 @@ +#!/bin/sh +# cam: snap a frame from /dev/video0. press s to capture, q to cancel. +# cam -> clipboard +# cam photo.png -> file + +if [ -n "$1" ]; then + out=$1 + keep=1 +else + out=$(mktemp --suffix=.png) + keep= +fi +conf=$(mktemp) +trap 'rm -f "$conf"; [ -z "$keep" ] && rm -f "$out"' EXIT + +printf 's screenshot-to-file "%s" ; quit\n' "$out" > "$conf" + +mpv av://v4l2:/dev/video0 \ + --demuxer-lavf-format=video4linux2 \ + --demuxer-lavf-o=input_format=mjpeg,video_size=1280x720 \ + --profile=low-latency \ + --force-window=immediate \ + --geometry=50%:50% \ + --input-conf="$conf" \ + --title=cam --osd-msg1="s: snap q: cancel" \ + --really-quiet 2>/dev/null + +[ -s "$out" ] || exit 0 +[ -n "$keep" ] && exit 0 + +xclip -selection clipboard -t image/png -loops 1 < "$out" & +sleep 0.1 diff --git a/camv b/camv new file mode 100755 index 0000000..48efe37 --- /dev/null +++ b/camv @@ -0,0 +1,29 @@ +#!/bin/sh +# camv: preview /dev/video0; s to start recording, q to stop. +# camv -> /tmp/cam-.mp4 +# camv movie.mp4 -> save to that path + +out=${1:-/tmp/cam-$(date +%Y%m%d-%H%M%S).mp4} +raw=$(mktemp --suffix=.mkv) +conf=$(mktemp) +trap 'rm -f "$conf" "$raw"' EXIT + +printf 's set stream-record "%s" ; show-text REC\n' "$raw" > "$conf" + +mpv av://v4l2:/dev/video0 \ + --demuxer-lavf-format=video4linux2 \ + --demuxer-lavf-o=input_format=mjpeg,video_size=640x480 \ + --profile=low-latency \ + --force-window=immediate \ + --geometry=50%:50% \ + --input-conf="$conf" \ + --title=camv --osd-msg1="s: rec q: stop" \ + --really-quiet 2>/dev/null + +[ -s "$raw" ] || exit 0 + +ffmpeg -hide_banner -loglevel fatal -nostdin \ + -vaapi_device /dev/dri/renderD128 -i "$raw" \ + -vf 'format=nv12,hwupload' \ + -c:v h264_vaapi -qp 28 -y "$out" +echo "$out" diff --git a/scr b/scr new file mode 100755 index 0000000..8b0d524 --- /dev/null +++ b/scr @@ -0,0 +1,26 @@ +#!/bin/bash + +if ! command -v slop >/dev/null; then + echo "scr: slop not found" >&2 + exit 1 +fi + +copy=0 +if [ $# -eq 0 ]; then + copy=1 + out=$(mktemp --suffix=.png) +else + out=$1 +fi + +coords=$(slop -f "%x %y %w %h" 2>/dev/null) || exit 1 +read x y w h <<<"$coords" + +ffmpeg -f x11grab -loglevel error -s ${w}x${h} \ + -i ${DISPLAY}+${x},${y} -frames:v 1 -y "$out" + +if [ $copy -eq 1 ]; then + xclip -selection clipboard -t image/png -i "$out" +fi + +echo "$out" diff --git a/scrv b/scrv new file mode 100755 index 0000000..9ec94a0 --- /dev/null +++ b/scrv @@ -0,0 +1,41 @@ +#!/bin/bash + +# Video Quality +# The range of the CRF scale is 0–51, where 0 is lossless, 23 is the default, +# and 51 is worst quality possible. A lower value generally leads to higher +# quality, and a subjectively sane range is 17–28 +QUALITY=28 + +if ! command -v slop &> /dev/null +then + echo "slop command not found. Please install slop." + exit 1 +fi + +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +filename="$1" + +echo "Select the desktop area to record." +coords=$(slop -f "%x %y %w %h" 2>/dev/null) + +x=$(echo $coords | awk '{print $1}') +y=$(echo $coords | awk '{print $2}') +width=$(echo $coords | awk '{print $3}') +height=$(echo $coords | awk '{print $4}') + +width=$((width / 2 * 2)) +height=$((height / 2 * 2)) + +echo "Recording started. Press 'q' to stop recording." + + #\#-f alsa -i pulse -c:v libx264 -preset ultrafast -crf ${QUALITY} \ + #-c:v libx264 -preset ultrafast -crf ${QUALITY} \ + #-tune zerolatency -pix_fmt yuv420p -f mp4 $filename +ffmpeg -f x11grab -loglevel quiet -s ${width}x${height} -i ${DISPLAY}+$x,$y \ + -c:v libx264 -pix_fmt yuv420p -crf ${QUALITY} -preset ultrafast -f mp4 $filename + +echo "Recording stopped." diff --git a/trk b/trk new file mode 100755 index 0000000..a466ed2 --- /dev/null +++ b/trk @@ -0,0 +1,16 @@ +#!/bin/sh +# trk — translate English↔Korean, direction picked from input. + +if [ $# -gt 0 ]; then + text=$* +else + text=$(cat) +fi + +if printf '%s' "$text" | grep -qP '[\x{AC00}-\x{D7A3}\x{3131}-\x{3163}]'; then + pair=ko:en +else + pair=en:ko +fi + +exec trans -b "$pair" "$text"