194 lines
4.6 kB
1
# ╭────────┬─────────┬───────╮
2
# │ ffmpeg │ devices │ reset │
3
# ╰────────┴─────────┴───────╯
4
5
_rwx_cmd_rwx_ffmpeg_devices_reset() { rwx_ffmpeg_devices_reset "${@}"; }
6
rwx_ffmpeg_devices_reset() {
7
local module="uvcvideo"
8
modprobe --remove "${module}" &&
9
modprobe "${module}"
10
}
11
12
# ╭────────┬────────┬─────────╮
13
# │ ffmpeg │ device │ formats │
14
# ╰────────┴────────┴─────────╯
15
16
rwx_ffmpeg_device_formats() {
17
local device="${1}"
18
[ -n "${device}" ] || device="/dev/video0"
19
ffmpeg \
20
-f "v4l2" \
21
-list_formats "all" \
22
-i "${device}"
23
}
24
25
# ╭────────┬───────╮
26
# │ ffmpeg │ input │
27
# ╰────────┴───────╯
28
29
rwx_ffmpeg_input_blue_yeti() {
30
local device="alsa_input.\
31
usb-Generic_Blue_Microphones_2051BAB04XY8-00.analog-stereo"
32
set -- \
33
-f "pulse" \
34
-i "${device}" \
35
-ac "2" \
36
-ar "48000"
37
local argument
38
for argument in "${@}"; do echo "${argument}"; done
39
}
40
41
rwx_ffmpeg_input_dell_precision() {
42
local device="alsa_input.\
43
pci-0000_00_1f.3.analog-stereo"
44
set -- \
45
-f "pulse" \
46
-i "${device}" \
47
-ac "2" \
48
-ar "48000"
49
local argument
50
for argument in "${@}"; do echo "${argument}"; done
51
}
52
53
rwx_ffmpeg_input_file() {
54
local file="${1}"
55
local from="${2}"
56
local to="${3}"
57
[ -n "${file}" ] || return
58
set -- \
59
-i "${file}"
60
if [ -n "${to}" ]; then
61
set -- "${@}" \
62
-ss "${from}" \
63
-to "${to}"
64
fi
65
local argument
66
for argument in "${@}"; do echo "${argument}"; done
67
}
68
69
rwx_ffmpeg_input_hdmi() {
70
local device="${1}"
71
[ -n "${device}" ] || device="/dev/video0"
72
set -- \
73
-f "v4l2" \
74
-video_size "1920x1080" \
75
-framerate "60" \
76
-input_format "yuyv422" \
77
-i "${device}"
78
local argument
79
for argument in "${@}"; do echo "${argument}"; done
80
}
81
82
# ╭────────┬────────╮
83
# │ ffmpeg │ output │
84
# ╰────────┴────────╯
85
86
rwx_ffmpeg_output_audio_fast() {
87
set -- \
88
-codec:a "flac" \
89
-compression_level "0"
90
local argument
91
for argument in "${@}"; do echo "${argument}"; done
92
}
93
94
rwx_ffmpeg_output_audio_slow() {
95
set -- \
96
-codec:a "libopus" \
97
-b:a "128k"
98
local argument
99
for argument in "${@}"; do echo "${argument}"; done
100
}
101
102
rwx_ffmpeg_output_file() {
103
local file="${1}"
104
[ -n "${file}" ] || return
105
set -- \
106
-y "${file}"
107
local argument
108
for argument in "${@}"; do echo "${argument}"; done
109
}
110
111
rwx_ffmpeg_output_video_fast() {
112
set -- \
113
-codec:v "libx264" \
114
-preset "ultrafast" \
115
-crf "0"
116
local argument
117
for argument in "${@}"; do echo "${argument}"; done
118
}
119
120
rwx_ffmpeg_output_video_slow() {
121
local crf="${1}"
122
local codec="${2}"
123
[ -n "${codec}" ] || codec="libx264"
124
if [ -z "${crm}" ]; then
125
case "${codec}" in
126
"libx264") crf="23" ;;
127
"libx265") crf="28" ;;
128
*) ;;
129
esac
130
fi
131
set -- \
132
-codec:v "${codec}" \
133
-preset "veryslow" \
134
-crf "${crf}" \
135
-movflags "+faststart" \
136
-pix_fmt "yuv420p"
137
local argument
138
for argument in "${@}"; do echo "${argument}"; done
139
}
140
141
# ╭────────┬────────╮
142
# │ ffmpeg │ record │
143
# ╰────────┴────────╯
144
145
rwx_ffmpeg_record_hdmi_precision() {
146
local file="${1}"
147
[ -n "${file}" ] || return
148
# LATER alternative
149
# shellcheck disable=SC2046,SC2312
150
set -- \
151
$(rwx_ffmpeg_input_hdmi) \
152
$(rwx_ffmpeg_input_dell_precision) \
153
$(rwx_ffmpeg_output_video_fast) \
154
$(rwx_ffmpeg_output_audio_fast) \
155
$(rwx_ffmpeg_output_file "${file}")
156
echo "${@}"
157
ffmpeg "${@}"
158
}
159
160
rwx_ffmpeg_record_hdmi_yeti() {
161
local file="${1}"
162
[ -n "${file}" ] || return
163
# LATER alternative
164
# shellcheck disable=SC2046,SC2312
165
set -- \
166
$(rwx_ffmpeg_input_hdmi) \
167
$(rwx_ffmpeg_input_blue_yeti) \
168
$(rwx_ffmpeg_output_video_fast) \
169
$(rwx_ffmpeg_output_audio_fast) \
170
$(rwx_ffmpeg_output_file "${file}")
171
echo "${@}"
172
ffmpeg "${@}"
173
}
174
175
# ╭────────┬────────╮
176
# │ ffmpeg │ reduce │
177
# ╰────────┴────────╯
178
179
rwx_ffmpeg_reduce() {
180
local input="${1}"
181
local output="${2}"
182
local from="${3}"
183
local to="${4}"
184
[ -n "${output}" ] || return
185
# LATER alternative
186
# shellcheck disable=SC2046,SC2312
187
set -- \
188
$(rwx_ffmpeg_input_file "${input}" "${from}" "${to}") \
189
$(rwx_ffmpeg_output_video_slow) \
190
$(rwx_ffmpeg_output_audio_slow) \
191
$(rwx_ffmpeg_output_file "${output}")
192
echo "${@}"
193
ffmpeg "${@}"
194
}
195