Monday, February 21, 2022

[solved] pulseaudio complete, minimal, and cripple installs

Even though "solved", it's really a failure, a failure to avoid PulseAudio After 2 week's work down the drain (see prior post) attempting to eliminate PulseAudio and, at this point, I have to get back to my life. I had a good plan but what ultimately defeated it is ALSA's latest complication of run-time language interactions with /usr/share/alsa/alsa.conf. For me to reverse engineer the many C++ attribute and function calls to the libalsa binary would take me a year to understand and document. They've finally made ALSA impossible. All that ever needed to happen in Linux audio was for OSS to be further developed 15 years ago, but that's probably a DRM casualty of some sort.

At any rate, I did manage to at least cripple PulseAudio so this is what I'll deal with first. With a couple of segues to failures even within the cripple process. Linux sound, man....

Cripple PA

In the simplest 3-step terms...

1. install libpulse normally

Alternatively, simply install one (eg. ffmpeg) of the now tens of programs that check for PulseAudio as a dependency! Lol, but we can see it is now a dependency if we try to *remove* PulseAudio...

2. symlink libpulse binaries to /dev/null

Other than for Google applications (eg, Chromium), PulseAudio is not technically a dependency. Rather applications verify PulseAudio's presence but do not need to use it. Accordingly, we can leave PulseAudio libraries in place, and symlink them to /dev/null. The libraries pass applications' tests for their presence, but do not interfere with our OS, since they are linked to nothing. So...

ln -sf /dev/null /usr/lib/libpulse.so
ln -sf /dev/null /usr/lib/libpulse-simple.so
ln -sf /dev/null /usr/lib/libpulse-mainloop-glib.so
...but leave these two alone...
/usr/lib/pulseaudio/libpulsedsp.so
/usr/lib/pulseaudio/libpulsecommon-15.0.so
These last are left as-is due to Chromium. During each start-up, Chromium checks for the size of at least one of these two libraries. Since /dev/null is "0" in size, Chromium will fail to start-up if, say common-15 is linked to /dev/null.

3. enjoy with one caveat

With this configuration, I've never had the pulse daemon auto-spawn, nor had my ALSA configurations overwritten (unless upgrading ALSA directly), nor had failures inside multi-media applications. This includes ffmpeg, OBS, vlc, Chromium, Ocenaudio, and the standard ALSA apps.

HOWEVER. At one point I broke/unlinked /dev/null from these three libs above to see what would happen. The delinking went smoothly, eg...

ln -sf /usr/lib/libpulse-sismple.so.0 /usr/lib/libpulse-simple.so
...yet the results were suboptimal. That's because /dev/null does not operate like other files, and it was deleted along with the symlink. Then, without /dev/null in the OS, I encountered random operational failures by applications which rely upon its presence.

So, in cases where I have to delete the symlinks, I:
  1. reinstall libpulse. # pacman -S libpulse.
  2. restart. during every startup, the kernel propagates /dev/null wherever needed in the system.

apulse - another failure

Apulse is on the AUR and looked promising. It emulated PulseAudio to placate applications which called PulseAudio, and even installs a small libpulse dummy which might do the same /dev/null moves I did above manually.

Although apulse installed fine and I was able to go back to ALSA I was still stuck with the problem that, eg, obs-studio could not detect my ALSA devices. For those without multi-media requirements such as those of obs-studio, apulse might be a solution.

jack? no

Not unless a dedicated machine for recording. Otherwise too many apps require PA. Two things learned when installing JACK however: stackex: change output card, and requires PAM modification, as I describe in this post.

complete PA install

Running as a user, pactl and pacmd are your friends, and the file ~/.config/pulse/client.conf. There's also more here, and also Arch's T-Shooting Guide. A typical issue are multiple cards detected in ALSA, but not by PA. You'll also want to clean out logs.

Is PA installed and running? Even though it's not technically a daemon (see below), it's usually running at starup from some unknown spawner. Check alsamixer and see if it's been superseded by PulseAudio's single volume bar.

After changes to any setup, we can restore ALSA with...

# systemctl restart alsa-restore.service
...and PulseAudio (for changes, kill it first, then restart it) with...
$ pulseaudio -k
$ pulseaudio -D

As noted here, PulseAudio is typically not a running service nor daemon from startup. Programs call it on a per-use basis. Some applications, eg Chromium, operate with a minimal /usr/bin/libpulse. Cleanest minimal install for pa_context_connect calls (basic libpulse install enough otherwise). I'm not sure, but to stream (eg. OBS), pulseaudio-rtp (only 200Kb) might be added.

# pacman -S pulseaudio-alsa

Packages (3) alsa-plugins-1:1.2.6-3 pulseaudio-15.0-4 pulseaudio-alsa-1:1.2.6-3

Total Download Size: 1.25 MiB
Total Installed Size: 6.19 MiB
Optional dependencies for alsa-plugins
dbus: for maemo plugin [installed]
jack: for pcm_jack plugin [installed]
libavtp: for pcm_aaf plugin [installed]
libsamplerate: for rate_samplerate plugin [installed]
libpulse: for conf_pulse, ctl_pulse and pcm_pulse plugins [installed]
speexdsp: for pcm_speex and rate_speexrate plugins [installed]
ffmpeg: for pcm_a52 plugin [installed]

pavucontrol

For ease of selecting devices (recording, streaming). It's big however, due to dependencies.
# pacman -S pavucontrol

Packages (7) atkmm-2.28.2-2 cairomm-1.14.3-2 glibmm-2.66.2-1 gtkmm3-3.24.5-2 libsigc++-2.10.8-1 pangomm-2.46.2-1 pavucontrol-1:5.0-1

Total Download Size: 2.95 MiB
Total Installed Size: 18.63 MiB

detection issue

configuration files

/etc/pulse/default.pa [detection issues]
/etc/pulse/client.conf [autospawn]
~/.config/pulse/client.conf

Wednesday, February 16, 2022

[FAIL] ALSA, JACK, 2 x cards, no pulseaudio

Basically, it doesn't matter what a post is originally about. If it includes any sound portion, it will end up being pages long attempting to deal with PulseAudio -- attempts to keep it out, to control or limit it, or to circumvent it. Unless you are a retiree with at least a full year's free time, install PulseAudio. The three biggest failures which lead to a full PulseAudio install:

  1. pa_context_connect() calls from an application. These require a full PulseAudio install, not just libpulses.
  2. ALSA developer's decision to add runtime calls (in C++?) into the libalsa binary. OK within itself, but falls apart when it accesses the configuration file /usr/share/alsa/alsa.config. The configuration used to be a plain text file. Now it has to include named variables to respond to libalsa's runtime calls. Documentation is poor and would require a year of full-time work by a user to reverse engineer.
  3. multiple sound cards. If we still had a purely text ALSA config, without runtime calls, might be OK. But with runtime added, an inflexible default must be specified. This limits access to functionality from the other cards needed for eg, HDMI/ELD.

ALSA issues

Can we shrink our ALSA configuration to make it simpler to overlay JACK? Let's try some changes. To restart ALSA after changes....
# systemctl restart alsa-restore.service

1. capture (recording)

$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC892 Analog [ALC892 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 2: ALC892 Alt Analog [ALC892 Alt Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0

*using alsa and jack over pulseaudio (10:42) Nomad Studio, 2016. About 8:00 describes using apulse on PulseAudio apps.


2. cards

$ cat /proc/asound/cards
0 [PCH ]: HDA-Intel - HDA Intel PCH
HDA Intel PCH at 0xf7f30000 irq 40
1 [HDMI ]: HDA-Intel - HDA ATI HDMI
HDA ATI HDMI at 0xf7e60000 irq 41

2. devices

Card 0 w/ 4 devices, Card 1 w/5 HDMI output devices...
$ ls -l /dev/snd
total 0
drwxr-xr-x 2 root root 80 Feb 15 17:46 by-path
crw-rw----+ 1 root audio 116, 14 Feb 15 17:46 controlC0
crw-rw----+ 1 root audio 116, 8 Feb 15 17:46 controlC1
crw-rw----+ 1 root audio 116, 13 Feb 15 17:46 hwC0D0
crw-rw----+ 1 root audio 116, 7 Feb 15 17:46 hwC1D0
crw-rw----+ 1 root audio 116, 10 Feb 15 17:46 pcmC0D0c
crw-rw----+ 1 root audio 116, 9 Feb 15 17:46 pcmC0D0p
crw-rw----+ 1 root audio 116, 11 Feb 15 17:46 pcmC0D1p
crw-rw----+ 1 root audio 116, 12 Feb 15 17:46 pcmC0D2c
crw-rw----+ 1 root audio 116, 6 Feb 15 17:46 pcmC1D10p
crw-rw----+ 1 root audio 116, 2 Feb 15 17:46 pcmC1D3p
crw-rw----+ 1 root audio 116, 3 Feb 15 18:23 pcmC1D7p
crw-rw----+ 1 root audio 116, 4 Feb 15 17:46 pcmC1D8p
crw-rw----+ 1 root audio 116, 5 Feb 16 03:40 pcmC1D9p
crw-rw----+ 1 root audio 116, 1 Feb 15 17:48 seq
crw-rw----+ 1 root audio 116, 33 Feb 15 17:46 timer

3. modules

$ lsmod |grep snd
snd_seq_dummy 16384 0
snd_seq 90112 1 snd_seq_dummy
snd_seq_device 16384 1 snd_seq
snd_hda_codec_realtek 163840 1
snd_hda_codec_generic 98304 1 snd_hda_codec_realtek
snd_hda_codec_hdmi 81920 1
ledtrig_audio 16384 1 snd_hda_codec_generic
snd_hda_intel 61440 0
snd_intel_dspcfg 32768 1 snd_hda_intel
snd_intel_sdw_acpi 20480 1 snd_intel_dspcfg
snd_hda_codec 180224 4 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec_realtek
snd_hda_core 114688 5 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,snd_hda_codec_realtek
snd_hwdep 16384 1 snd_hda_codec
snd_pcm 163840 4 snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,snd_hda_core
snd_timer 45056 2 snd_seq,snd_pcm
snd 126976 10 snd_hda_codec_generic,snd_seq,snd_seq_device,snd_hda_codec_hdmi,snd_hwdep,snd_hda_intel,snd_hda_codec,snd_hda_codec_realtek,snd_timer,snd_pcm
soundcore 16384 1 snd

default problems

Soundcard 0 has analog capture (mic) and playback (speaker, headpone) channels. Card 1 only plays back but it's a necessary card because has digital(HDMI) connection. So, I must capture through 0 and playback through 1. But how?
  • HDMI playback only works when Card 1 is the default ALSA card
  • Recording only works when Card 0 is the default ALSA card
  • Unable to dynamically change default card(s) using amixer (cset cget)
  • ALSA now includes run-time programming language in its config file (alsa.conf). Learning the ALSA library variables and commands necessary for config file (one year's work)
  • OBS detects audio devices only via JACK or PulseAudio, not ALSA

HDMI playback verfied

$ aplay -D plughw:1,9 /usr/share/sounds/alsa/Front_Center.wav

5. current sound configuration

All configuration files deleted except /usr/share/alsa/alsa.conf. I have an "audio" group with myself as a member in /etc/group.

hardware and ELD HDMI detection

Changing ALSA configurations has no effect on items 1-3 above or the ELD/HDMI connection. ALSA is now installed with the kernel as systemd modules -- its functions are upstream of our user-level configuration. ELD handshakes automatically if the HDMI cable is connected and both items are powered-on. ELD verification is simple: find the device with the "1":

$ grep eld_valid /proc/asound/HDMI/eld*

complete alsa.conf

Only one configuration file is necessary to configure ALSA at the user level, /usr/share/alsa/alsa.conf; all other configuration files may be deleted. However a complete alsa.conf is roughly 600 lines and has eight sections; HOOKS, DEFAULTS, PCM, CONTROL, RAW MIDI, SEQUENCER, HW DEPENDENCE, and TIMER. Furthermore, in 2022 these include run-time function calls to the libs which have a somewhat elaborate syntax. I find the 2022 version a kludge.

smallest alsa.conf

What then is the smallest ALSA configuration? I've gotten ALSA working normally with only about 120 lines: a DEFALUTS, small PCM (below), and CONTROL interface sections.

#
# ALSA library configuration file
# permissions are 644

# PCM interface

pcm.capture1 {
type hw
card 0
device 0
}
pcm.capture2 {
type hw
card 0
device 2
}
pcm.hdmi8 {
type hw
card 1
device 8
}
With this I could, eg, record with explicit commands.
]$ arecord -D capture1 test.wav
However, since ALSA installs muted, this wasn't enough for me. I want alsamixer so I can easily unmute, set levels, select outputs. After a few days' work, in order not to deconstruct every run-time function for a customized version, I reluctantly settled on the original 600 line configuration file. For now.

alsa.conf sites

The alsa.conf is fun and time consuming to play with, and I might do it again. Documentation was sparse however. I gleaned from several sites.

Again, we want a JACK connectioin to Card 0, but not make it the system default. Alternatively, we might, if possible make Card 0 the default, but configure card 1 as an HDMI hook.

jack install overview

First you want the smallest possible ALSA configuration. Least elaborate and simple. A default card is required for JACK can be pared down and the problems are few, some due to PAM's typical interference. Capture is more complicated than playback, so we can test our permissions first on card 1. Once we get a basic configuration, we'll get card 1 going then tweak the more finnicky capture settings until card 0 is able to detect and input a mic.

jack install

I typically install jack2, alsa-plugins, jack-example-tools for multi-card, libffado (less error messages), and qjackctl for a GUI.

basic setup

  1. verify there's an "audio" group and the user is in it. Jump to Step 2. Otherwise, create the group "audio" and add the user
    # groupadd audio
    # usermod -a -G audio user
  2. modify PAM memory permissions to group "audio" in /etc/security/limits.conf, for real-time audio processing.
    # nano /etc/security/limits.conf
    @audio - rtprio 95
    @audio - memlock unlimited
    Verify: logout, log back in, and then...
    $ ulimit -r
    ...should see "95"
  3. determine location of $ qjackctl called on command line.
    $ strace qjackctl
    You might have to save it to a file since so much crap will scroll.
    $ strace qjackctl 2>&1 | tee file.txt
    We only care about the first line in the tens of thousands of lines in the file.
    execve("/usr/bin/qjackctl", ["qjackctl"]....
  4. give audio group permissions to qjackctl and jackd2 and make it group executable (750).
    # chgrp audio /usr/bin/qjackctl
    chmod 750 /usr/bin/qjackctl
    chgrp audio /usr/bin/jackd
    chmod 750 /usr/bin/jackd

first verification - playback only (card 1)

$ jackd -d alsa -d hw:1
jackdmp 1.9.20
Copyright 2001-2005 Paul Davis and others.
Copyright 2004-2016 Grame.
Copyright 2016-2021 Filipe Coelho.
jackdmp comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details
jack_get_descriptor : dll
jack_get_descriptor returns null for 'jack_internal_metro.so'
no message buffer overruns
no message buffer overruns
jack_get_descriptor : dll
jack_get_descriptor returns null for 'jack_inprocess.so'
jack_get_descriptor : dll
jack_get_descriptor returns null for 'jack_intime.so'
no message buffer overruns
JACK server starting in realtime mode with priority 10
self-connect-mode is "Don't restrict self connect requests"
audio_reservation_init
Acquire audio card Audio1
creating alsa driver ... hw:1|hw:1|1024|2|48000|0|0|nomon|swmeter|-|32bit
ALSA: Cannot open PCM device alsa_pcm for capture. Falling back to playback-only mode
configuring for 48000Hz, period = 1024 frames (21.3 ms), buffer = 2 periods
ALSA: final selected sample format for playback: 32bit integer little-endian
ALSA: use 2 periods for playback

So JACK starts for playback, albeit with some probable PulseAudio garbage errors. However, the error message, "Cannot open PCM device alsa_pcm for capture" will cause a fatal error when attempting to capture, using Card0 next paragraph. What is alsa_pcm and where do we configure alsa_pcm to open for capture? These are likley to be tweaks inside of /usr/share/alsa/alsa.conf. If so, not trivial.

initial capture attempt (card 0)

We need to capture microphone, which can only be done on Card 0.
$ jackd -d alsa -d hw:0
jackdmp 1.9.20
[snip]
Acquire audio card Audio0
creating alsa driver ... hw:0|hw:0|1024|2|48000|0|0|nomon|swmeter|-|32bit
ALSA: Cannot open PCM device alsa_pcm for playback. Falling back to capture-only mode
Released audio card Audio0
audio_reservation_finish
Cannot initialize driver
JackServer::Open failed with -1
Failed to open server

Fail. PCM device alsa_pcm has no playback -- no problem, we don't need playback with Card 0. However, we also receive a capture-only mode failure. Jackd exits. This is large problem: we need Card 0 for mic input capture. So two things are different, we're on Card 0 and we need capture.

alsa.conf

Card 1 was detected, possibly because Card 1 is the default card inside alsa.conf. We want to leave the default configuration on Card 1 (needed for HDMI output), but specify Card 0 for JACK detection, capture only. Here is the relevant Card 1 information for HDMI/ELD detection.

defaults.ctl.card 1
defaults.pcm.card 1
defaults.pcm.device 9
defaults.pcm.subdevice -1
defaults.pcm.nonblock 1
### start - custom for JACK pcm.jack1 { type hw card 0 device 0 } pcm.jack2 { type hw card 0 device 2 } ### end - custom for JACK
pcm.plug0 {
type plug
slave {pcm "jack" }
}
}
pcm.jack {
type jack
slave { pcm "jack" }
playback_ports {
0 alsa_pcm:playback_1
1 alsa_pcm:playback_2
}
capture_ports {
0 alsa_pcm:capture_1
1 alsa_pcm:capture_2
}

Monday, February 14, 2022

stream and record - obs and ffmpeg 1

Links: OBS site w/forums

A high-speed internet connection is foundational for streaming, but what are some other considerations? Some live stream sites (YouTube, Discord, Glimesh) will need an OBS type app on the user's system to format a stream to transmit to their site. Other sites (Zoom) have a proprietary streaming app, but the app experience can sometimes be enhanced by routing it through an OBS-type app. A third issue is the various streaming protocols and site authentications. A fourth issue is hardware problems which can be specific to a streaming app. All this complexity allows for multiple problems and solutions.

Note: a fifth issue is that OBS is natively setup for the notorious Nvidia hardware and the PulseAudio software. Detection of audio is particularly difficult without PulseAudio, eg requiring JACK config.

protocols and authentication

RTMP streaming providers typically require a cell number via the "security" (forensic record) requirement of 2FA requiring a cell. This is an immense safety issue. Who knows how these providers tie cell numbers to credit reports, "trusted 3rd parties", etc? The answer is consumers are expected to understand a multi-page "privacy" policy filled with legalistic language and equivocations, which regularly changes, and which varies from site to site. Way to protect us Congress, lol. Accordingly, since I essentially have no idea what they're doing with my cell, I try to avoid streaming services which require a cell.

 

Although they require a cell*, YouTube's advantage is streaming directly from a desktop/laptop with nothing beyond a browser. Discord can do similarly with limited functionality, and they have a discord app which adds features. Glimesh works well with OBS -- it provides a stream key for OBS, or whatever a person is using.

*YouTube requires "account verification" at https://www.youtube.com/verify prior to streaming. The verification is 2FA to a cell.

obs

Those not intending to use OBS can still find utility in its attempts to stream or record. A great deal will be revealed about one's system. OBS logs are also valuable to identify/troubleshoot problems, eg the infamous 'ftl_output' not found issue -- you'll find it in the logs (~/.config/obs-studio/logs). OBS can encounter a couple of problems.

obs hardware issue: nvidia graphics card

Obviously, no one wants NVidia hardware: the associated bloatware is almost unbearable. However, its use is so common that many users have it in their system(s). OBS therefore makes Nvidia the default. This setting spawns errors for systems with AMD Radeons. Change the "NV12" (or 15 by now) circled below to an option which works for one's hardware.

1. obs audio problem - alsa and jack

Most desktops unfortunately have two audio systems: an MB chip, and a graphics card chip. Difficulty can arise when one source is needed for mic input, and the the other source is needed for playback (eg, for HDMI). This is bad enough. However there's an additional problem with OBS -- it doesn't detect ALSA. Your options are PulseAudio (gag), or JACK (some config work, depending). I end up using a modified PulseAudio. More about that here.

1. obs local configuration and usage: to MP4

Fffmpeg works great for screen and input captures, but OBS can be preferable for more mixing in during live. In OBS terminology "scenes" and "sources" are important words. Scenes is a collection of inputs (sources). OBS is good at hardware detection, but files can be played, websites shown, hardware (cams, mics), images (eg for watermarks) other videos, and so on. For making MP4's "Display Capture" is obviously an important source.

Scenes and Sources (8:08) Hammer Dance, 2021. How to add the scenes and sources to them.

V4L2 issues

1. loopback issue

Unimportant, though you might find it in the OBS logs

v4l2loopback not installed, virtual camera disabled.

The solution steps are here.

  • v4l2loopback-dkms: pacman. basic loopback. This makes a module, so you need to do, pacman -S linux-headers prior to the loopback. install.
  • v4l2loopback-dc-dkms: AUR. haven't tried this one. apparently allows connecting an Android device and using it as a webcam via wifi

We're not done because the loopback device will takeover /dev/video0, denying use of our camera. So we need to configure our loopback to run on /dev/video1. This has to be specified by putting a load-order file into /etc/modules-load.d/ .

Install the loopback, if desired.

# pacman -S v4l2loopback-dkms

2. ftl_output issue

This is one is important.

$ lsmod |grep video
uvcvideo 114688 1
videobuf2_vmalloc 20480 1 uvcvideo
videobuf2_memops 20480 1 videobuf2_vmalloc
videobuf2_v4l2 36864 1 uvcvideo
videobuf2_common 65536 2 videobuf2_v4l2,uvcvideo
videodev 282624 4 videobuf2_v4l2,uvcvideo,videobuf2_common
video 53248 3 dell_wmi,dell_laptop,i915
mc 65536 4 videodev,videobuf2_v4l2,uvcvideo,videobuf2_common

If we haven't installed loopback, then video0 is the default. Note this is verified by the lack of any settings or capabilities returned on video1.

$ v4l2-ctl --list-devices
Integrated_Webcam_HD: Integrate (usb-0000:00:14.0-2):
/dev/video0
/dev/video1
/dev/media0
$ v4l2-ctl -l -d 0
brightness 0x00980900 (int) : min=-64 max=64 step=1 default=0 value=0 contrast 0x00980901 (int) : min=0 max=95 step=1 default=0 value=0 saturation 0x00980902 (int) : min=0 max=100 step=1 default=64 value=64 hue 0x00980903 (int) : min=-2000 max=2000 step=1 default=0 value=0 white_balance_temperature_auto 0x0098090c (bool) : default=1 value=1 gamma 0x00980910 (int) : min=100 max=300 step=1 default=100 value=100 gain 0x00980913 (int) : min=1 max=8 step=1 default=1 value=1 power_line_frequency 0x00980918 (menu) : min=0 max=2 default=2 value=2 white_balance_temperature 0x0098091a (int) : min=2800 max=6500 step=1 default=4600 value=4600 flags=inactive sharpness 0x0098091b (int) : min=1 max=7 step=1 default=2 value=2 backlight_compensation 0x0098091c (int) : min=0 max=3 step=1 default=3 value=3 exposure_auto 0x009a0901 (menu) : min=0 max=3 default=3 value=3 exposure_absolute 0x009a0902 (int) : min=10 max=626 step=1 default=156 value=156 flags=inactive
$ v4l2-ctl -l -d 1
[nothing]

However, even with this default correct, there is a ftl_output error remaining which prevents an output video stream.

$ yay -S ftl-sdk

plug-ins

OBS has plugins, for example one that shows keystrokes and mouse clicks.

Streaming and Recording(11:08) Gaming Careers, 2019. OBS based tutorial, using the computer, not a capture card.
GoPro to WiFi(page) Action Gadgets, 2019. Used GoPros can work as well as newer cams.

settings - device

repurposed cams

attendance

  • meet: only in highly paid plans beginning about $12 per month (2023). The higher level educator plans also.
  • zoom: only in paid plans
  • teams: only in paid plans - teames is part of microsoft360 business suite
  • webex: webex is inherently pay-only

Streaming and Recording(11:08) Gaming Careers, 2019. OBS based tutorial, using the computer, not a capture card.

Friday, February 11, 2022

python snippets

basics

Outside of going to Banas' comprehensive knowledge videos, this is the best I've seen for a comprehensive method of learning.

3 day methodology (7:38) PyCon Canada, 2013. Daniel Moniz went from Java to Python.

Name is special variable (8:42)
def main():
pass

if __name__ == "__main__":
main()

another sample video edit (screencast) w/B-roll

In April of 2020, I wrote a Picture in Picture blogpost, using ffplay to show everything on a desktop and then a ffmpeg screen capture to get all of them. We can do these more simply if just capturing one at a time. The video below from Luke Smith, is a good review of the commands, even though 2017.

Simple screencast (12:05) Luke Smith, 2017. Linux based. Simple ways to capture both webcams and screens (get their names from /dev ) and to-the-point.

In addition,I like to do cutaways to B-roll while keeping the audio going, so the best way is usually for me to make the entire video and overlay a narration after complete.

1. Video

screen usually :0.0

Active window can't be captured -- have to do the whole screen or do a bunch of offset information for some window. I don't bother. For capture, use the -f tag instead of the usual "i", because it's not a file, it's a format, x11grab. The input file will be the default tty, :0.0, set the size the usual "-s" way -- I typically leave off the bottom 30 pixels to keep off my taskbar. Get the size from xrandr, here lets say it was 1366x768...

$ ffmpeg -s 1366x738 -f x11grab -i :0.0 somefile.mp4

webcam usually /dev/video0

With the webcam, I add a bitrate -- start around 2M -- if it looks a little teary.

$ ffmpeg -i /dev/video0 -b:v 2M somefile.mp4

USB cam usually /dev/video2

Not always /dev/video1, and it's hard to find a reliable device list command. I usually try video1 and 2 -- a USB is often "2". The problem with ffmpeg -devices or (if you hate that big banner) ffmpeg -hide-banner -devices, is that only lists the programs that run them, not the hardware

$ ffmpeg -i /dev/video2 -b:v 2M somefile.mp4

2. Audio added (usually 0,0)

Note: I like to adjust mic volumes in alsamixer to get them just right. However, since we know that PulseAudio is a kludge, I sometimes must fall back to "Input Devices" in pavucontrol. Something like the setting below typically works without clipping.

This command give a huge list, some might find helpful.

$ pactl list sources

audio and screen

After reading this page, I find that simply adding it to the screen is awesome. So here was the basic command from above...

$ ffmpeg -s 1366x738 -f x11grab -i :0.0 somefile.mp4

...and then add the hw device from aplay -l, typically 0,0, and whatever codec/bitrate shit...

$ ffmpeg -s 1366x738 -f x11grab -i :0.0+0,0 -f alsa -ac 2 -i pulse -acodec aac -b:a 192k somefile.mp4

This above is a gold standard, and also in some cases mic 0,1 is available. Pick whichever one is better. There's also a way to make this simpler, which works in some cases...

$ ffmpeg -s 1366x738 -f x11grab -i :0.0 -f pulse -ac 2 -i default -acodec aac -b:a 192k somefile.mp4

audio and webcam

With the webcam, it also works fine

$ ffmpeg -i /dev/video0 -f pulse -ac 2 -i default -b:a 192k -b:v 2M somefile.mp4

audio sink

To real-time mux application sounds and microphone is slightly annoying: it appears users are forced to create a virtual microphone. Further, re-establishing the virtual mic is required after reboot or update. Also the order related apps are used appears to be important to sync audio and video.

$ pactl list sinks short

3. b-roll

There are multiple problems and solutions. The largest problem: maintain sync of narrator's mouth-2-speech, when cutting back and forth from b-roll. There are three ffmpeg solutions for me; sometimes I pull from all three:

  • overlay b-roll onto completed videos: Complete video with narration. Overlay video-only clips (so doesn't silence the narration) with 100% opacity.
  • complete all video without human speaking shots. Overlay narration final step: this works especially well if narrator need not be seen, so no syncing to mough movements. It's easy to overlay a consistent human, or AI (eg. Speechelo), track over the video.
  • chunk it: create several clips with narrator at start of chunk, ending chunk with b roll and narrators voice-over. Be sure to use same mic settings talking over b-roll. Compile all these clips into one longer video. Appears as if going back and forth from narrator to b-roll.

Luke Smith has a video that hints at some of these solutions, and then the second link gets at it a little more difrectly

some ffmpeg features (7:42) Luke Smith, 2021. Stabilizing, horizontal display, syncing scripts.
overlaying videos ffmpeg (page), 2019.

Tuesday, February 8, 2022

statistics -- simplistic error catching in studies

Note: I've also included some statistics-relevant information from my 2020 Maths post within a "resources" section at the bottom of this post.

This list so far only includes traditional "p-value" errors, and not Bayesian style errors. But when we look at published papers in Nature or at the NCIB, what are some rule-of-thumb errors we can look for?

short list

  • correct test for the hypothesis
    Look for a hypothesis to be clearly stated and that the null has been rejected. That said, having pre-determined hypothesis and the requirement for rejection of null is an outdated method to some: a more modern approach is to crunch an immense amount of data through arrays and let the data itself identify anomalies from which to draw conclusions. However, this method is still used in many studies required by, eg. the FDA and many scientific papers.

    Types of tests (19:53) Amour Learning, 2019. Generally t tests make less presumptions than Z tests and are better. 12 main types of tests and when to use for which hypothesis.
    Selecting the correct test (12:31) Erich Goldstein, 2015. What type of data (categorical or quantitative)

  • a priori standards
    Is the alpha value determined prior to the study and clearly stated? A typical alpha value of 0.05, looks for a 1 in 20 chance the results would happen by chance, and obviously an alpha value of 0.10 that 1 in 10. NCBI:nih.gov
    Counter: the most common reduction is for a third variable. I'd like to propose another: studies designed with an a priori alpha presuppose the a priori hypothesis on which is reliable. However, data gathered in the study may reveal other information. There may be some statistical significance for although it's not clinical.
  • publication bias
    My friend Bart notes
    If ten people examine a question and none of them do any datamining and only the people who happen to get a positive result submit or publish, then the stats seem ten times as strong as they are.
  • randomization problems
    Front-end randomization is a thing, but there are other error possibilities later in the study also, well-described here.
  • control group
    Perhaps too obvious to include, but included anyway

resources

p value/alpha value

Only Bayesian statistics can prove theories, but P value stuff can prove data. It's a lower standard than Bayesian but useful, of course.

What's a P value (20:30) Daniel Lakens, 2019. some accent -- good at 0.75x. Good backgrounder. No math. Notes Bayesian necessary on theories. 8:45, otherwise all we can do is rule out something (using P).
Baye's theorem (15:10) 3Blue1Brown, 2019. new information, and how to use in research. Graphically illustrated.

12 main types of hypothesis tests

As noted above, they must be matched to the hypothesis, but what are they?

concept instruction

The clearest statistics instruction videos for my time are from Brandon Foltz. "Only" an M.Ed (probably now a Phd), found ways to create clean graphics, and years before clean graphics were common. Another excellent early adopter, although only in an overlapping sense with statistics, is Derek Banas. One of his best might be his more recent comprehensive portolio using Python. I believe Derek had a job with Apple when he was 16.

spreadsheets, Python, R, SPSS

Most people cannot afford SPSS, ergo PSPP is a a good option. If using Linux, most repo's have it. In Arch, it's in the AUR. There's plenty of PSPP videos on YT, as well as SPSS videos that a person can adapt.

This guy's series is *incalculably* helpful, har har. He as MSoft AF, Vstudio, Excel, Jupyter Notebook, but it's just as easy to do all of his stuff in Google Colab with Google Sheets as-is, or download them as CSV's first and then merge them.

Pandas Merge (Excel) (9:08) Alan Hettinger, 2022. Similar to a SQL join. When we want to put things together from various tables into a combined output.
Pandas Merge (Sheets) (10:48) Tobias Willman, 2020. Adapt the Jupyter above using this guy's vid.

Wednesday, February 2, 2022

ffmpeg - zoom, ticker, xfade transitions, python

1. Tech videos often use a terminal screen, zoom in or out on some element, and then slide-transition to the speaker

2. Tech videos often cutaway from the narrator to a terminal (or other B-roll). However, how to keep voice synced when return to narrator?

1. zoom

This video has a slower, more dramatic, zoom. But we can decrease the number of seconds to "1" for a better effect.

zoom and pan example (5:10) The FFMPEG guy, 2021. Moves in directly, but also does corners.

2. ticker

The first question is how much text we need to scroll. If we want a ticker smoothly scrolling throughout a video, it seems we'd want to include a ticker filter only on the final edit: we don't want to have to match-up the ticker with the next clip's ticker. However, the ffmpeg command to add the ticker includes the text in the CLI -- the amount of text to scroll for an entire video might be 30 or 40 lines. So we'll want ffmpeg to call to a text file containing our ticker text, unless we've only got a very short ticker.

The second question is if we need our ticker to loop or only run once.

ticker example (3:09) The FFMPEG guy, 2021. Starts simple and progresses through polished effects.

3. transitions

The transitions in this post use the amazing xfade filter. But for a complete list of the filters in one's ffmpeg installation:

$ ffmpeg -filters |grep xfade

xfade points

  • OTT verse list with 5 second clips of each.
  • jitter solved for a zoom around 2:16 the solution in the zoom jitter is to add a scale flag that varies with the video resolution.
    scale=12800x7200
    ... this number match the video resolution later in the same command...
    s=1280x720

4. slow audio and video

This would halve both the audio and video speeds, as seen in the video beneath it. In this one, I also happened to convert the container to MP4.

$ ffmpeg -y -i normalspeed.mkv -filter_complex "[0:v]setpts=2.0*PTS[v];[0:a]atempo=0.5[a]" -map "[v]" -map "[a]" halfspeed.mp4

half-speed example (3:28) The FFMPEG guy, 2021. Does audio, video, then both audio and video. Reveals filter complex mapping.

I have a couple other posts that touch on ffmpeg transitions, but more needed to be done. The filters are complex and you just can't learn them all fast enough. A post is needed to gather

two prior posts

These were made when I attempted to do Picture in Picture (PIP) videos.

1. PIP screencast 1 (2020) Begins with PIP comands but moves into some ffmpeg
2. PIP screencast 2 (2020) Post is mostly all ffmpeg commands.

clip organization

In order to be efficient with editing, a set of columns for figuring the time offsets on the transitions and audio is helpful. I've used Google Sheeets for the 6 columns, and the result looks useful for a large project with a hundred clips, or for a neat looking business setup. But it's overkill for a hommade 10 minute video with 5-10 clips. It takes longer to enter spreadsheet data than paper, pen and a calculator. The back of an old envelope is fine or, if attempting to keep track of edits, Day-Timer has the Teacher's Planner. The pages are similar to this: 

I write all of the clips on the left, then as I concatenate them into larger clips, I put them more to the right. The movement is from left to right. I can parenthesis and put music at far right. Transitions are noted between each clip.

mixed media

Some clips are complex. For example, for a 5 second intro, I might need JPG's that fade into something with moving text, and with music and other audio mixed in. There also might be animation. If there's panning in the JPG's, then that needs to be noted in my clip editor also. A Teacher's Planner will keep these organized, and I can scan in the pages if I prefer a record. For the graphical text, Viddyoze is fairly cost effective, and for narration Speechelo (blastersuite) is cost effective, although they do attempt to upsell.

python

ticker example (20:14) PyGotham2014, 2014. Old, out of sync, but conceptually penetrating.