From 006abeb31ccd569df19654610b1b6601ea48e891 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 13 Jan 2025 00:14:47 +0100 Subject: [PATCH] ffmpeg/draft --- sh/ffmpeg.sh | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/sh/ffmpeg.sh b/sh/ffmpeg.sh index 0fb29e1..da6b5ee 100644 --- a/sh/ffmpeg.sh +++ b/sh/ffmpeg.sh @@ -21,3 +21,91 @@ rwx_ffmpeg_device_formats() { -list_formats "all" \ -i "${device}" } + +# ╭────────┬───────╮ +# │ ffmpeg │ input │ +# ╰────────┴───────╯ + +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 +} + +rwx_ffmpeg_input_nearstream_ccd10() { + 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 │ +# ╰────────┴────────╯ + +rwx_ffmpeg_output_fast() { + local file="${1}" + [ -n "${file}" ] || return + set -- \ + -codec:v "libx264" \ + -preset "ultrafast" \ + -crf "0" \ + -y "${file}" + local argument + for argument in "${@}"; do echo "${argument}"; done +} + +rwx_ffmpeg_output_slow() { + local file="${1}" + local crf="${2}" + local codec="${3}" + [ -n "${file}" ] || return + [ -n "${codec}" ] || codec="libx264" + if [ -z "${crm}" ]; then + case "${codec}" in + "libx264") crf="23" ;; + "libx265") crf="28" ;; + *) ;; + esac + fi + set -- \ + -codec:v "${codec}" \ + -preset "veryslow" \ + -crf "${crf}" \ + -movflags "+faststart" \ + -pix_fmt "yuv420p" \ + -y "${file}" + local argument + for argument in "${@}"; do echo "${argument}"; done +} + +# ╭────────┬────────╮ +# │ ffmpeg │ record │ +# ╰────────┴────────╯ + +rwx_ffmpeg_record_ccd10() { + local file="${1}" + [ -n "${file}" ] || return + set -- \ + $(rwx_ffmpeg_input_nearstream_ccd10) \ + $(rwx_ffmpeg_output_fast "${file}") + local argument + echo "${@}" + ffmpeg "${@}" +}