rwx/sh/ffmpeg.sh

195 lines
4.5 KiB
Bash
Raw Normal View History

2025-01-12 15:26:56 +00:00
# ╭────────┬─────────┬───────╮
# │ ffmpeg │ devices │ reset │
# ╰────────┴─────────┴───────╯
_rwx_cmd_rwx_ffmpeg_devices_reset() { rwx_ffmpeg_devices_reset "${@}"; }
rwx_ffmpeg_devices_reset() {
local module="uvcvideo"
modprobe --remove "${module}" &&
modprobe "${module}"
}
2025-01-12 16:26:29 +00:00
# ╭────────┬────────┬─────────╮
# │ ffmpeg │ device │ formats │
# ╰────────┴────────┴─────────╯
rwx_ffmpeg_device_formats() {
local device="${1}"
[ -n "${device}" ] || device="/dev/video0"
ffmpeg \
-f "v4l2" \
-list_formats "all" \
-i "${device}"
}
2025-01-12 23:14:47 +00:00
# ╭────────┬───────╮
# │ ffmpeg │ input │
# ╰────────┴───────╯
2025-01-13 03:49:31 +00:00
rwx_ffmpeg_input_blue_yeti() {
local device="alsa_input.\
usb-Generic_Blue_Microphones_2051BAB04XY8-00.analog-stereo"
set -- \
-f "pulse" \
-i "${device}" \
-ac "2" \
-ar "48000"
local argument
for argument in "${@}"; do echo "${argument}"; done
}
2025-01-28 08:38:27 +00:00
rwx_ffmpeg_input_dell_precision() {
local device="alsa_input.\
pci-0000_00_1f.3.analog-stereo"
set -- \
-f "pulse" \
-i "${device}" \
-ac "2" \
-ar "48000"
local argument
for argument in "${@}"; do echo "${argument}"; done
}
2025-01-12 23:14:47 +00:00
rwx_ffmpeg_input_file() {
local file="${1}"
local from="${2}"
local to="${3}"
[ -n "${file}" ] || return
set -- \
-i "${file}"
if [ -n "${to}" ]; then
set -- "${@}" \
-ss "${from}" \
-to "${to}"
fi
local argument
for argument in "${@}"; do echo "${argument}"; done
}
2025-01-28 08:21:42 +00:00
rwx_ffmpeg_input_hdmi() {
2025-01-12 23:14:47 +00:00
local device="${1}"
[ -n "${device}" ] || device="/dev/video0"
set -- \
-f "v4l2" \
-video_size "1920x1080" \
-framerate "60" \
-input_format "yuyv422" \
-i "${device}"
local argument
for argument in "${@}"; do echo "${argument}"; done
}
# ╭────────┬────────╮
# │ ffmpeg │ output │
# ╰────────┴────────╯
2025-01-13 03:49:31 +00:00
rwx_ffmpeg_output_audio_fast() {
set -- \
-codec:a "flac" \
-compression_level "0"
local argument
for argument in "${@}"; do echo "${argument}"; done
}
rwx_ffmpeg_output_audio_slow() {
set -- \
-codec:a "libopus" \
-b:a "128k"
local argument
for argument in "${@}"; do echo "${argument}"; done
}
rwx_ffmpeg_output_file() {
2025-01-12 23:14:47 +00:00
local file="${1}"
[ -n "${file}" ] || return
2025-01-13 03:49:31 +00:00
set -- \
-y "${file}"
local argument
for argument in "${@}"; do echo "${argument}"; done
}
rwx_ffmpeg_output_video_fast() {
2025-01-12 23:14:47 +00:00
set -- \
-codec:v "libx264" \
-preset "ultrafast" \
2025-01-13 03:49:31 +00:00
-crf "0"
2025-01-12 23:14:47 +00:00
local argument
for argument in "${@}"; do echo "${argument}"; done
}
2025-01-13 03:49:31 +00:00
rwx_ffmpeg_output_video_slow() {
local crf="${1}"
local codec="${2}"
2025-01-12 23:14:47 +00:00
[ -n "${codec}" ] || codec="libx264"
if [ -z "${crm}" ]; then
case "${codec}" in
2025-01-13 06:44:14 +00:00
"libx264") crf="23" ;;
"libx265") crf="28" ;;
*) ;;
2025-01-12 23:14:47 +00:00
esac
fi
set -- \
-codec:v "${codec}" \
-preset "veryslow" \
-crf "${crf}" \
-movflags "+faststart" \
2025-01-13 03:49:31 +00:00
-pix_fmt "yuv420p"
2025-01-12 23:14:47 +00:00
local argument
for argument in "${@}"; do echo "${argument}"; done
}
# ╭────────┬────────╮
# │ ffmpeg │ record │
# ╰────────┴────────╯
2025-01-28 08:38:27 +00:00
rwx_ffmpeg_record_hdmi_precision() {
local file="${1}"
[ -n "${file}" ] || return
2025-02-03 18:29:02 +00:00
# LATER alternative
2025-02-03 18:38:50 +00:00
# shellcheck disable=SC2046,SC2312
2025-01-28 08:38:27 +00:00
set -- \
$(rwx_ffmpeg_input_hdmi) \
$(rwx_ffmpeg_input_dell_precision) \
$(rwx_ffmpeg_output_video_fast) \
$(rwx_ffmpeg_output_audio_fast) \
$(rwx_ffmpeg_output_file "${file}")
echo "${@}"
ffmpeg "${@}"
}
2025-01-28 08:21:42 +00:00
rwx_ffmpeg_record_hdmi_yeti() {
2025-01-12 23:14:47 +00:00
local file="${1}"
[ -n "${file}" ] || return
2025-02-03 18:29:02 +00:00
# LATER alternative
2025-02-03 18:38:50 +00:00
# shellcheck disable=SC2046,SC2312
2025-01-12 23:14:47 +00:00
set -- \
2025-01-28 08:21:42 +00:00
$(rwx_ffmpeg_input_hdmi) \
2025-01-13 03:49:31 +00:00
$(rwx_ffmpeg_input_blue_yeti) \
$(rwx_ffmpeg_output_video_fast) \
$(rwx_ffmpeg_output_audio_fast) \
$(rwx_ffmpeg_output_file "${file}")
echo "${@}"
ffmpeg "${@}"
}
# ╭────────┬────────╮
# │ ffmpeg │ reduce │
# ╰────────┴────────╯
rwx_ffmpeg_reduce() {
local input="${1}"
local output="${2}"
local from="${3}"
local to="${4}"
[ -n "${output}" ] || return
2025-02-03 18:29:02 +00:00
# LATER alternative
2025-02-03 18:38:50 +00:00
# shellcheck disable=SC2046,SC2312
2025-01-13 03:49:31 +00:00
set -- \
$(rwx_ffmpeg_input_file "${input}" "${from}" "${to}") \
$(rwx_ffmpeg_output_video_slow) \
$(rwx_ffmpeg_output_audio_slow) \
$(rwx_ffmpeg_output_file "${output}")
2025-01-12 23:14:47 +00:00
echo "${@}"
ffmpeg "${@}"
}