Showing posts with label webcam. Show all posts
Showing posts with label webcam. Show all posts

Thursday, October 8, 2020

old cell phones for webcams (usb, wifi)

Links: Android Partitions :: Arch Android tools :: xda F3Q
xda xiaomi redmi2 :: xiaomi community :: more flashboot commands

NB: check out updated 2022 version


Overview

Two main layers of software function:

  • system video is of course displayed on a laptop or screen. Several layers of internal software must accomodate webcams.
    1. The kernel should detect the video source
    2. software like V4L2 should be able to transport detected video.
    3. software like ffplay or OBS with ftl can then display transported video.
  • phone configuration software, typically fastboot, usually has many poorly documented model-specific functions. Still, it's a necessary step because the phone webcam is not a stand-alone camera, but functioning within phone firmware.

The handshake is the trickier, more time-consuming project. Yet the handshake tends to be low maintenance, once established. When configured properly, the phone cam should be detected like any other cam by the kernel. We'll start with USB access into the phone to configure it; following configuration, the phone cam can connect via WiFi or via USB.

phone powerup

Rooting a phone typically compromises its camera commands and degrades resolution. To avoid rooting the phone, we want to set Android into developer mode with USB bugging turned-on. Then we can connect via USB and authorize an ADB program. Once that's in, we can get to the phone's cam.

Most Androids can initialize in several modes. We want them in either ADB mode or Fastboot mode. Another site about this. The F3 and one of the F3Q's powered into fastboot mode (more fastboot commands), and still did not boot after a hardware reset. Good article here and it's important to know the Android partion names.

Even with correct fastboot syntatx....

# pacman -Syu android-tools
# fastboot oem unlock
OKAY [ 0.291s]
Finished. Total time: 0.291s
# fastboot erase boot
Erasing 'boot' FAILED (remote: 'failed to erase partition')
fastboot: error: Command failed
# fastboot format boot
fastboot: error: Formatting is not supported for file system with type ''.

It was a weekend long process to simply boot one of these phones into operation as a webcam

Note also that the adb commands were inoperative with all the phones, eg # adb devices produced nothing. Eventually, adb kill-server was run. Back to flashboot and determining the proper flags for it.

xioami tools

All three devices have Xiaomi inside. There's a good Xiaomi tool, xiaomi-adb-fastboot-tools, in the AUR. It runs on Java and needs the JRE...

$ yay -S xiaomi-adb-fastboot-tools

Sometimes this worked, but it failed to compile on boxes with the newest version of Java. On systems which it did compile, I couldn't find the executable.

$ which xioami*

...returned nothing. A Redditor helped me out...

$ pacman -Qql "$pkg_name" | while read fn; do [[ -x $fn && -f $fn ]] && echo "$fn"; done

...which returned...


Phones

One LG F3 and two LG F3Q's were available. All 3 were Jellybean (4.12), with 5MP cameras.

BTW, no idea why these 2 fastbooted, I hadn't tried to root or tamper with the devices. The 3rd phone booted normally, but since I had moved my SIM into my active phone, I could only connect by WiFi without Google Play store. How then to download webcam apps? Ultimately, without being able to boot the phone nor get access to Google Play, the unfortunate reality seemed rooting the two unbootables. They may also have had some sort of Factory Reset Protection (FRP), not sure.

Xiaomi sidenote

Xiaomi is the phone's cell xponder manf. It's actually a Qualcomm SnapDragon 410E. The phones I used were all Redmi 2, presumably with wt88047 hardware. When a phone powers into fastboot, lsusb provides the phone's internal manufacturer ID instead of the LG phone ID. For example, below you'll see the bootable F3Q displayed a charging identifier, but the F3Q that powered into fastboot displayed the 18d1:d00d Xiaomi Redmi 2 hardware identifier. Xiaomi itself produces some ROM's; their site is worthy of research also.

LG Optimus F3Q D520 (lg-d520)

$ lsusb
1004:6300 LG Electronics, Inc. G2/Optimus Android Phone [Charge mode]
1004:632c LG Electronics, Inc. LGE Android Phone [MTP files]
1004:631e LG Electronics, Inc. LM-X420xxx/G2/Optimus Android Phone (PTP/camera mode)
18d1:d00d Google Inc. Xiaomi Mi/Redmi 2 (fastboot)

5MP HDMI autofocus, Snapdragon 400, Android 4.12 (Jellybean). Only 1.3GB internal but takes a 32GB microSD

files
stock for the F3Q (d520) D52010c_00.kdzfactory firmware (ZIP or KDZ), flashed to "boot". aka ROM.
stock for the F3 (p659) P65910b_05.kdzfactory firmware (ZIP or KDZ), flashed to "boot". aka ROM.
structure/workflowfactory image (always IMG) for the device
color balanceapplication (always APK) to root
crossfadeslideshow complex! use a GUI app
de-interlacewatermark
gif

LG Optimus F3 (lg-p659)

$ lsusb
18d1:d00d Google Inc. Xiaomi Mi/Redmi 2 (fastboot)

5MP HDMI autofocus, Snapdragon 400, Android 4.12 (Jellybean). Only 1.3GB internal but takes a 32GB microSD

Fastboot Process

YES

fastboot oem device-info
fastboot getvar product
    product: FX3Q_TMO_US
    product: FX3_TMUS
fastboot continue

NOPE

fastboot erase boot
fastboot flashing unlock_critical

failed f3q hard reset

The first pass at restoring factory failed with the message...

Secure booting error!
Cause: boot certificate verify

errors

  • partion table doesn't exist :: command: fastboot erase data Valuable response also helping with directory names.
  • Error2: Failure sending erase group start command to the card (RCA:2) :: command: fastboot erase recovery

Card RCA:2

This card was nearly continually in failures

# fastboot continue
[phone] Error No. 2: Failure sending read command to the Card (RCA:2)

One site had a theory about why recovery writes fail having to do with multiple bootloader slots. My phones though....

# fastboot --set-active=a
fastboot: error: Device does not support slots
# fastboot getvar slot-count
slot-count:

ADB Process

ADB mode is less important than Fastboot mode, but problems in Fastboot can sometimes be solved by having a proper ADB capability. So it can be worth it. The commands are different from Fastboot. Also, you might even have to manually make Plugdev rules for the damned thing. If you can see it in lsusb, you have a chance.

YES

adb start-server
adb kill-server
adb logcat
adb devices
fastboot continue

NOPE

fastboot erase boot
fastboot flashing unlock_critical

failed f3q hard reset

The first pass at restoring factory failed with the message...

Secure booting error!
Cause: boot certificate verify

errors

  • partion table doesn't exist :: command: fastboot erase data Valuable response also helping with directory names.
  • Error2: Failure sending erase group start command to the card (RCA:2) :: command: fastboot erase recovery

plugdev group

I want to add a system group

# groupadd -r plugdev
, add myself to it, and then also of course make a rule...
# nano /etc/udev/rules.d/51-android.rules
. The rule is described well here.

SD/USB boot

Site describes how to unbrick using the EMMC method, special software. It appears however this method requires also converting the KDZ file into BIN files for the software. A pain.

A33 Unbrick with SD Card (8:09) Kiko Dog, 2015. Requires special program to burn the OS onto the SD card.

Sunday, April 26, 2020

class :: distance

During the COVID fiasco, we've had to adapt. By far, the first break-out concerns are 1) hardware and 2) internet connection. There's a couple Zoom/Meet tips for class organizers at the bottom.

If you can organize databases and an email server, you're ahead of the program.

MySQL configuration (14:26) Engineer Man, 2019. MySQL, but can adapt to Posgres.

  • connection reliable FiOs is the only way to underwrite live streaming and large webinars without problems. IME, 80% of students have connections that can manage this format since 5G. During 4G, reliable connections or data plans would average 30% participation.
  • hardware a laptop from 2016 minimally: eg, Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor with minimum 8GB RAM. Linux, Mac, Windows, makes no difference but has to be able to encode/decode in real time. Additionally, one or both of:
    • a digital tablet to write equations (connect with USB, switch in Zoom).
    • a document camera (connect with USB, switch in Zoom).
  • paper doing Zooms (or any contact with students, admin, or parents), I have 1) a plain spiral notebook, 2) teachers planner, and 3) printed copies of my rosters on a clipboard. I can take notes and keep-up with checking off having spoken with everyone, objectives, attendance, and so on.  
    These paper planners are old school, but it's a cheap investment in sanity, IME.
  • space room for comfortable seating and cross lighting

second best

anything less than above. The main difference is how contact is made. For example, suppose there is no Zoom capability with the students? I will have to make videos, and I will have to make phone calls, both very time consuming. Of course, I have a Google Voice number available, but there is extensive logging and sometimes a tickler required -- it's casework. Tier 2 means reaching-out since Zoom rooms are unavailable for students and parents to visit themselves. The point is I can be just as successful in Tier 1 or 2, they just look slightly different in how I spend my time, and how much time.

common strategy

Eighty percent of what I do is the same whether or not I'm in Tier 1 or 2. Accordingly, most of this post is taken with what the two tiers have in common. At the bottom are notes on strategies specific to each.

admin

Apart from academics, one has to provide their own admin layer.
  • time-keeping spreadsheet, daily entries, semester long. I have categories (columns) for each day and just put in my hours, let the spreadsheet total it. The first page has this, then I have a second page specifically tracking Zoom/webinar hours. This has served me well to provide to others. If cost were no option, I would want a complete database available with custom reports, but the risk is spending more time entering data than doing work, so a spreadsheet manages this OK.
  • personal calendar I use old-fashioned paper on this. oil changes, MD appts, all of this. Time-keeping I run in a spreadsheet, hours worked with categories, all appointments are done in a separate calendar

solo

An ever lesser approach than Tier 2 is to have no support, working on one's own. At this level, a person's largest problem becomes grade, testing, and assignment turn-ins. Without any organizational support use a free Schoology account, Zoom, one's Google account (email, voice, drive), and then post occasional YouTube videos that link to one's Schoology. Since you can post grades and attendance in Schoology, you run it as the LMS. Engrade usded to be able to handle this but no longer exists.

  • connection you more or less are going to need FiOs speed connection to hangle large Zooms or streaming. Without it, you're down to posting videos, and then answering emails.
  • hardware

school supported

During the COVID, I knew a teacher that worked for a school using Aeries for grade tracking, Illuminate for attendance tracking (Aeries was used while in classroom), staff emails on Microsoft Outlook, and communicated with students in Google Suite, with work assigned via Khan Academy, and staff meeetings in Zoom. Teachers had to track their own hours in a spreadsheet.

video-conferencing

type note
MeetFree inside G-Suite. You'll want Google Extensions and/or tactiq.
Zoomeducational accounts have dropped time restrictions.
BigMarkerjava-based, takes plugins for, eg RStudio
Skype1-1, MicroSoft data collection for the US Govt

editing

I'll list editors below, but ffmpeg is the only reliable way to edit, sadly. The only way to edit video reliably in Linux is via CLI with a time sheet, clips, and ffmpeg.

scheduling

type note
CalendarIn G-Suite, has an appointments slot
Zoomweb-integrated Python, designed to display output in a browser.
BigMarkerjava-based, takes plugins for, eg RStudio
Skype1-1, MicroSoft data collection for the US Govt

equipment

type note
CalendarIn G-Suite, has an appointments slot
Zoomweb-integrated Python, designed to display output in a browser.
BigMarkerjava-based, takes plugins for, eg RStudio
Skype1-1, MicroSoft data collection for the US Govt
WebcamsOld cell phones are cheapest with USB connection and proper software.

Zoom

The settings screen appears as seen below; there are probably too many, perhaps 50 settings. 


  • attendance$$$ (Pro Version or higher) 1) OFF: Allow participants to rename themselves (In Meeting (Basic)), 2) ON: Attention tracking (In Meeting (Advanced)) 3) Go into Reports -> Usage after meeting. NB: renaming is turned off to prevent students from checking in as their friends.

Attendance via focus (2:33) Dr. Veronica Paz (IUP), 2020. How

  • attendance (Poor version) 1) OFF: Allow participants to rename themselves (In Meeting (Basic)), 2) A chat transcript automatically appears in the recording folder but you will have to grep or do some kind of script to pull all the names from the file.

Extraction from a file (25:20) theurbanpenguin, 2013. Thorough treatment of data extraction from a file.

Moodle/LMS

Moodle is a good LMS option for the LMS layer, as is Canvas. Can build your own server, or launch Moodle via a Bitnami vendor in Google Cloud for about $5 per months. I have a separate post on Moodle. Moodle works to be compliant with LRS/xAPI connections, since it is content based, not an LRS server. For exams, you'll want to complete SCORM versions, also another post.

Moodle exam contiguration (12:11) Centre for Professional and Part Time Learning, 2019. Exam configuration for an institution, but a lot of good information for anyone's settings.

LRS

In the newer xAPI realm using HP5, and different reporting

Monday, April 20, 2020

PiP screencast pt 1

contents
capture organizing the screen, opening PiP, capture commandsspeed changes slow motion, speed ramps
cutsscripting
precision cutsaudio and sync
other effects fade, text, saturationsubtitles/captions

NB: Try to make all cuts at I-frame keyframes, if possible.


Links: 1) PiP Pt II 2) capture commands 3) settings

Editing video in Linux becomes a mental health issue after a decade or more of teeth grinding with Linux GUI video editors. There are basically two backends:ffmpeg and MLT. After a lost 10 years, some users like me resign themselves to command line editing with ffmpeg and melt (the MLT CLI editor).

This post deconstructs a simple PiP screencast, perhaps 6 minutes long. A small project like this exposes nearly all the Linux editing problems which appear in a production length film. This is the additional irony of Linux video editing -- having to become practically an expert just to do the simplest things; all or nothing.

At least five steps are involved, even for a 3.5 minute video.

  1. get the content together and laid out, an impromptu storyboard. What order do I want to provide information?
  2. verify the video inputs work
  3. present and screencapture - ffplay, ffmpeg CLI
  4. cut clips w/out render - ffmpeg CLI
  5. assemble clips with transitions - ffmpeg CLI

capturing the raw video

The command-line PiP video setup requires 3 terminals to be open, 1) for the PiP, 2) for the document cam, 3) for the screen capture. Each terminal has a command. 1) ffplay, 2) ffplay, 3) ffmpeg.

1. ffplay :: PiP (always on top)

The inset window of the host narrating is a PiP that should always be on top. Open a terminal and get this running first. The source is typically the built in webcam, trained on one's face.
$ ffplay -i /dev/video0 -alwaysontop -video_size 320x240

The window always seems to open at 640x480, but then resized down to 160x120 and moved anywhere on the desktop. And then to dress it up with more brightness, some color sat, and mirror flipped...

ffplay -i /dev/video0 -vf eq=brightness=0.09:saturation=1.3,hflip -alwaysontop -video_size 320x240

2. ffplay :: document cam

I start this secondly, and make it nearly full sized, so I can use it interchangeably with any footage of the web browser.
$ ffplay -i /dev/video2 -video_size 640x480

3. ffmpeg :: screen and sound capture

Get your screensize with xrandr, eg 1366x768, then eliminate the bottom 30pixels (20 on some systems) to omit the toolbar. If the toolbar isn't shown, it can be used during recording to switch windows. Syntax: put the 3 flags in this order:

-video_size 1366x738 -f x11grab -i :0
...else you'll probably get only a small left corner picture or errors. Then come all your typical bitrate and framerate commands
$ ffmpeg -video_size 1366x738 -f x11grab -i :0 -r 30 output.mp4

This will encode a cleanly discernable screen at a cost of about 5M every 10 minutes. The native encoding is h264. If a person wanted to instead be "old-skool" with MPEG2 (codec:v mpeg2video), the price for the same quality is about 36 times larger: about 180M for the same 10 minutes. For MPEG2, we set a bitrate around 3M per second (b:v 3M), to capture similarly to h264 at 90K.

Stopping the screen capture is CTRL-C. However: A) be certain CTRL-C is entered only once. The hard part is, it doesn't indicate any change for over a minute so a person is tempted to CTRL-C a second time. Don't do that (else untrunc). Click the mouse on the blinking terminal cursor to be sure the terminal is focused, and then CTRL-C one time. It could be a minute or two and the file size will continue to increase, but wait. B) Before closing the terminal, be certain ffmpeg has exited.

If you CTRL-C twice, or you close the terminal before ffmpeg exits, you're gonna get the dreaded "missing moov atom" error. 1) install untrunc, 2) make another file about as long as the first but which exits normally, and 3) run untrunc against it.

Explicitly setting the screencast bitrate (eg, b:v 1M b:a 192k) typically spawns fatal errors, so I only set the frame rate.

Adding sound...well you're stuck with PulseAudio if you installed Zoom, so just add -f pulse -ac 2 -i default...I've never been able to capture sound in a Zoom meeting however.

$ ffmpeg -video_size 1366x738 -f x11grab -i :0 -r 30 -f pulse -ac 2 -i default output.mp4

manage sound sources

If a person has a Zoom going and attempts to record it locally, without benefit of the Zoom app, they typically only hear sound from their own microphone. Users must switch to the sound source of Zoom itself to capture the conversation. This is the same with any VOIP, of course. This can create problems -- a person needs to make a choice.

Other people will say that old school audio will be 200mV (0.002), p-p (peak-to-peak). Unless all these signals are changed to digital, gain needs to be set differently. One first needs to know the name of the devices. Note that strange video tells more about computer mic input at than I've seen anywhere.

basic edits, separation, and render

Link: Cuts on keyframes :: immense amounts of information on cut and keyframe syntax


Ffmpeg can make non-destructive, non-rerendered cuts, but they may not occur on an I-frame (esp. keyframe) unless seek syntax and additional flags are used. I first run $ ffprobe foo.mp4 or $ ffmpeg -i foo.mp4on the source file: bitrate, frame rate, audio sampling rates, etc. Typical source video might be 310Kb h264(high), with 128 kb/s, stereo, 48000 Hz aac audio. Time permitting, one might also want to obtain the video's I-frame (keyframe) timestamps, and send them to a text file to reference during editing...

$ ffprobe -loglevel error -skip_frame nokey -select_streams v:0 -show_entries frame=pkt_pts_time -of csv=print_section=0 foo.mp4 >fooframesinfo.txt 2>&1
  • no recoding, save tail, delete leading 20 seconds. this method places seeking before the input and it will go to the closest keyframe to 20 seconds.
    $ ffmpeg -ss 0:20 -i foo.mp4 -c copy output.mp4
  • no recoding, save beginning, delete tailing 20 seconds. In this case, seeking comes after the input. Suppose the example video is 4 minutes duration, but I want it to be 3:40 duration.
    $ ffmpeg -i foo.mp4 -t 3:40 -c copy output.mp4
    Do not forget "-c copy" or it will render. Obviously, some circumstances require this level of precision, and a person has little choice but to render.
    $ ffmpeg -i foo.mp4 -t 3:40 -strict 2 output.mp4
    This gives cleaner transitions.
  • save an interior 25 second clip, beginning 3:00 minutes into a source video
    $ ffmpeg -ss 3:00 -i foo.mp4 -t 25 -c copy output.m4
...split-out audio and video
$ ffmpeg -i foo.mp4 -vn -ar 44100 -ac 2 sound.wav
$ ffmpeg -i foo.mp4 -c copy -an video.mp4
...recombine (requires render) with mp3 for sound, raised slightly above neutral "300", for transcoding loss
$ ffmpeg -i video.mp4 -i sound.wav -acodec libmp3lame -ar 44100 -ab 192k -ac 2 -vol 330 -vcodec copy recombined.mp4

precision cuts (+1 render)

Ffmpeg doesn't allow for frame number cutting. If you set a time without recoding, it will rough cut to a number of seconds and a decimal. This works poorly for transitions. So what you'll have to do is recode it and enforce strict time limits, then take it time the number of frames. You can always bring the clip into Blender to see the exact number of frames. Even though Blender is backended with Python and ffmpeg, it somehow counts frames a la MLT.

other effects (+1 render)

Try to keep the number of renders as low as possible, since each is lossy.

fade in/out

...2 second fade-in. It's covered directly here, however, it requires the "fade" and "afade" filters which don't come standardly compiled in Arch, AND, it must re-render the video for this.
$ ffmpeg -i foo.mp4 -vf "fade=type=in:duration=2" -c:a copy output.mp4

For the fade-out, the location must be made in seconds, most recommend using ffmprobe, then just enter the information 2 seconds before you want it. This video was 7:07.95, or 427.95 seconds. Here it is embedded with some other filters I was color balancing and de-interlacing with.

$ ffmpeg -i foo.mp4 -max_muxing_queue_size 999 -vf "fade=type=out:st=426:d=2,bwdif=1,colorbalance=rs=-0.1,colorbalance=bm=-0.1" -an foofinal.mp4

text labeling +1 render

A thorough video 2017,(18:35) exists on the process. Essentially a filter and a text file, but font files must be specified. If you install a font manager like gnome-tweaks, the virus called PulseAudio must be installed, so it's better to get a list of fonts from the command line
$ fc-list
...and from this pick the font you want in your video. The filter flag will include it.
-vf "[in]drawtext=fontfile=/usr/share/fonts/cantarell/Cantarell-Regular.otf:fontsize=40:fontcolor=white:x=100:y=100:enable='between(t,10,35)':text='this is cantarell'[out]"
... which you will want to drop into the regular command
$ ffmpeg -i foo.mp4 -vf "[stuff from above]" -c:v copy -c:a copy output.mp4

...however this cannot be done because streamcopying cannot be accomplished after a filter has been added -- the video must be re-encoded. Accordingly, you'll need to drop it into something like...

$ ffmpeg -i foo.mp4 -vf "[stuff from above]" -output.mp4

Ffmpeg will copy most of the settings, but I do often specify the bit rate, since ffmpeg occasionally doubles it unnecessarily. This would just be "q:v "(variable), or "b:v "(constant). It's possible to also run multiple filters; put a comma between each filter statement.

$ ffmpeg -i foo.mp4 -vf "filter1","filter2" -c:a copy output.mp4

saturation

This great video (1:08), 2020, describes color saturation.

$ ffmpeg -i foo.mp4 -vf "eq=saturation=1.5" -c:a copy output.mp4

speed changes

1. slow entire, or either end of clip (+1 render)

The same video shows slow motion.

$ ffmpeg -i foo.mp4 -filter:v "setpts=2.0*PTS" -c:a output.mp4
OR
$ ffmpeg -i foo.mp4 -vf "setpts=2.0*PTS" output.mp4

Sometimes the bitrate is too low on recode. Eg, ffmpeg is likely to choose around 2,000Kb if the user doesn't specify a bitrate. Yet if there's water in the video, it will likely appear jerky below a 5,000Kb bitrate...

$ ffmpeg -i foo.mp4 -vf "setpts=2.0*PTS" -b 5M output.mp4

2. slowing a portion inside a clip (+2 render)

Complicated. If we want to slow a 2 second portion of a 3 minute normal-speed clip, but those two seconds are not at either end of the clip, then ffmpeg must slice-out the portion, slow the portion (+1 render), then concatenate the pieces again (+1 render). Also, since the single clip temporarily becomes more than one clip, a filter statement with a labeling scheme is required. It's covered here. It can be covered in a single command, but it's a big one.

Suppose we slow-mo a section from 10 through 12 seconds in this clip. The slow down adds a few seconds to the output video.

$ ffmpeg -i foo.mp4 -filter_complex "[0:v]trim=0:10,setpts=PTS-STARTPTS[v1];[0:v]trim=10:12,setpts=2*(PTS-STARTPTS)[v2];[0:v]trim=12,setpts=PTS-STARTPTS[v3];[v1][v2][v3] concat=n=3:v=1" output.mp4

supporting documents

Because of the large number of command flags and commands necessary for even a short edit, we can benefit from making a text file holding all the commands for the edit, or all the text we are going to add to the screen, or the script for TTS we are going to add, and a list of sounds, etc. With these three documents we end up sort of storyboarding our text. Finally, we might want to automate the edit with a Python file that runs through all of our commands and calls to TTS and labels.

basic concatenation txt

Without filters, file lists (~17 into video) are the way to do this with jump cuts.

python automation

Python ffmpeg scripts are a large topic requiring a separate post; just a few notes here. A relatively basic video 2015,(2:48) describing Python basics inside text editors. The IDE discussion can be lengthy also, and one might want to watch this2020, (14:06), although if you want to avoid running a server (typically Anaconda), you might want to run a simpler IDE (Eric, IDLE,), PyCharm, or even avoid IDE's2019,(6:50). Automating ffmpeg commands with Python doesn't require Jupyter since the operations just occur on one's desktop OS, not inside a browser.

considerations

We want to have a small screen of us talking about a larger document or some such and not just during recording
  • we want the small screen PiP to always be on top :: use -alwaysontop flag
  • we'd like to be able to move it
  • we'd like to make it smaller than 320x240
link: ffplay :: more settings

small screen

$ ffplay -f video4linux2 -i /dev/video0 -video_size 320x240
OR
$ ffplay -i /dev/video0 -alwaysontop -video_size 320x240
...then to keep it always on top

commands

The CLI commands run long. This is because ffmpeg defaults run high. Without limitations inside the commands, ffmpeg pulls 60fps, h264(high), at something like 127K bitrate. Insanely huge files. For a screencast, we're just fine with
  • 30fps
  • h264(medium)
  • 1K bitrate
flag note
 b:v4Kb if movement in the PiP is too much, up this
 fx11grab must be followed immediately with a second option "i", and eg, "desktop" this will also bring h264 codec
 framerate30. Some would drop it to 25, but I keep with YouTube customs even when making these things. Production level would be 60fps
 b:v1M if movement in the PiP is too much, up this
Skype1-1, MicroSoft data collection for the US Govt

video4linux2

This is indespensable for playing one's webcam on the desktop, but it tends to default to highest possible framerates (14,000Kbs), and to a 640x480 window-size though the latter is resizeable. The thing is, it's unclear whether this is due to the vidoe4linux2 codec settings, or upon the ffplay which uses it. So is there a solid configuration file to reset these? This site does show a file to do this.

scripting

You might want to run a series of commands.The key issue is figuring the chaining. Do you want to start 3 programs at once, one after the other, one after the other as each one finishes, one after the other with the input of the prior program as the input for the next?

Bash Scripting (59:11) Derek Banas, 2016. Full tutorial on Bash scripting.
Linking commands in a script (Website) Ways to link commands.

$ nano pauseandtalk.sh (don't need sh, btw)
#!/bin/bash

There are several types of scripts. You might want a file that sequentially runs a series of ffmpeg commands, or you might want to just have a list of files for ffmpeg to look at to do a concatanation, etc.

Sample Video Editing Workflow using FFmpeg (19:33) Rick Makes, 2019. Covers de-interlacing to get rid of lines, cropping, and so on.
Video Editing Comparison: Final Cut Pro vs. FFmpeg (4:44) Rick Makes, 2019. Compares editing on the two interfaces, using scripts for FFmpeg

audio and narration/voiceover

Text-to-speech has been covered in another post, however there are commonly times when a person wants to talk over some silent video. $ yay -S audio-recorder. How to pause the video and speak at a point, and still be able to concatenate.

inputs

If you've got a desktop with HDMI output, a 3.5mm hands-free mic won't go into the video card, use the RED 3.5mm mic input, then filter out the 60hz hum. There are ideal mics with phantom power supplies, but even a decent USB mic is $50.

For syncing, you're going to want to have your audio editor running and Xplayer running same desktop. This is because it's easier to edit the audio than the video, there's no rendering to edit audio.

Using only Free Software (12:42) Chris Titus Tech, 2020. Plenty of good audio information (including Auphonic starting at 4:20; mics (don't use the Yeti - 10:42) and how to sync (9:40) at .4 speed.
Best for less than $50 (9:52) GearedInc, 2019. FifinePNP, Blue Snowball. Points out that once we get to $60, it's an "XLR" situation with preamps and so forth to mitigate background noise.
Top 5 Mics under $50 (7:41) Obey Jc, 2020. Neewer NW-7000Compares editing on the two interfaces, using scripts for FFmpeg

find the microphone - 3.5mm

Suppose we know we're using card 0

$ amixer -c0
$ aplay -l
These give us plenty of information. However, it's still likely in an HDMI setup to hit the following problem
$ arecord -Ddefault test-mic.wav
ALSA lib pcm_dsnoop.c:641:(snd_pcm_dsnoop_open) unable to open slave
arecord: main:830: audio open error: No such file or directory

This means there is no "default" configured in ~./asoundrc. There would be other errors too, if not specified. The minimum command specifies the card, coding, number of channels, and rate.

$ arecord -D hw:0,0 -f S16_LE -c 2 -r 44100 test-mic.wav

subtitles/captions

Saturday, January 16, 2010

linux - cheapo usb camera/webcam

links
Video: use and settings (not good for compile instructions)
Blog: making it work with Flash


getting started (FAIL)

# udevmonitor

the program '/bin/bash' called 'udevmonitor', it should use 'udevadm monitor ', this will stop working in a future release monitor will print the received events for:
UDEV the event which udev sends out after rule processing
UEVENT the kernel uevent
UEVENT[1263672227.910603] add /class/usb_device/usbdev1.2 (usb_device)
UEVENT[1263672227.910786] add /class/usb_endpoint/usbdev1.2_ep00 (usb_endpoint)


# lsusb

Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 093a:010e Pixart Imaging, Inc. Digital camera, CD302N/Elta Medi@ digi-cam/HE-501A
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub


So the kernel sees the camera. We have a $2 Pixart CD302N/HE-501A (ID 093a:010e) camera. How do we capture from this piece of junk?

Software
A simple command line interface for the camera will be spcagui ,once the camera is initialized, if the camera uses the gspca module to drive the camera. How do I determine the right module for my CD302N/HE-501A (ID 093a:010e) camera?

Navigated to Linux Kernel driver database and found that the 093a:010e camera uses gspca module. Checking the kernel to see if it's activated:
# modprobe gspca
FATAL: Module gspca not found.

So, it's not installed. Would the Kernel allow it, if we had it?
# cd /etc
# grep -rn "CONFIG_USB" *
udev/rules.d/30-scanners.rules:25:# For Linux >= 2.6.22 without CONFIG_USB_DEVICE_CLASS=y

So, it appears I won't have to modify the kernel, but I will have to build a module (in Windowspeak, a "driver") to load into the kernel. If I'd had to change the kernel from "n" to "y", I would go here and accomplish all this. But I don't have to change the kernel.

The documentation above noted the GSPCA module relies on libv4l, so it must also be checked:
# netpkg libv4l
[I][l] Found installed libv4l-0.5.8-i486-60.1.tgz on the repository
what should I do ?
1) reinstall
2) download
3) skip
There and installed. So only the source and patch for the GSPCA module needs to be found somewhere.
  • At this site appears gspcav1-20071224.tar.gz is the most recent version.

  • At this site appears gspcapatch.gz is a 2009 version.

Unzip them both into the same folder, then patch
$ patch<.gspcapatch
Following the patch, root-up and run their excellent compilation script
# ./gspca_build
The module will be created. Then just modprobe it and check to see if it loaded
# modprobe gspca
# lsmod
gspca          601572  0
videodev       23680   1   gspca
v4l1_compat   9732   1   videodev

So, all are loaded. I plugged-in the camera, and checked in /dev, and found that there was no /dev/video0, and so there was no way to find the camera. This is a well known bug, but the standard fixes, such as reloading the module, haven't worked.

A HA!
# modinfo gspca
filename: /lib/modules/2.6.28.7/kernel/drivers/usb/media/gspca.ko
license: GPL
description: GSPCA/SPCA5XX USB Camera Driver
author: Michel Xhaard
--HUGE OUTPUT--

# modinfo gspca |grep 93A
alias: usb:v093Ap2463d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2472d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap260Fd*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap260Ed*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2608d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2603d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2601d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2600d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2470d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2460d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2471d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2468d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap050Fd*dc*dsc*dp*ic*isc*ip*
Notice that there is no 093a:010e in the list of these Pixart cameras. So, we are definitely going to need to add another module or patch the current one further. The OS needs to create the node/dev/video0 or else software that shows images can't interact with the camera.

mr97310a.c
Mr97310a.c, may be the patch. It's described at the Linux Database. Scrolling down, the site seems to indicate that the 093a:010e Pixart Imaging, Inc. Digital camera, CD302N/Elta Medi@ digi-cam/HE-501A requires this "C" module to be patched into the gspca module when compiling it, however this patch cannot be downloaded or copied and pasted. Alternatively, perhaps it will be a module named gspca_mr97310a. I can't figure out how to build this from the documentation.

Since I don't want, or don't have the information, to go to that trouble, I'm going to handcode what the module source will need to find the hardware, and then recompile the module:

In gspa.mod.c, added:
MODULE_ALIAS("usb:v093Ap010Ed*dc*dsc*dp*ic*isc*ip*");

In gspa_core.c, added line 413:
{PAC7310},
added Line 613:
{PAC7310, "Pixart Kaibo 7310"},
added Line 628:
{USB_DEVICE(0x093a, 0x010e)}, /* Pixart Kaibo 7310 */
added Lines @ 4120:
case 0x010e:
spca50x->desc = PAC7310;
spca50x->bridge = BRIDGE_PAC7311;
spca50x->sensor = SENSOR_PAC7311;
break;

Then, took out the old module and recompiled and installed:
# modprobe -r gspca videodev v4l1_compat
# rm /lib/modules/2.6.28.7/kernel/drivers/usb/media/gspca.ko
# cd /home/foo/Download/gspcav1-20071224
# ./gspca_build

So, after these steps, and a # modprobe gspca and plugging in the camera, we get:
[dev]# find . -name "video*"
./video0
./v4l/video0
./.udev/names/video0

Great! The system is seeing the camera, and creating the /dev/video0 and associated nodes. Let's see if we can get a picture. No. It may be that the 7311 bridge is not going to work properly with a 7310 camera:
$ spcagui
SpcaGui version: 0.3.5 date: 18 September 2005
video device /dev/video0
ERROR opening V4L interface
: Input/output error

Reinstalling the driver, with modprobe yields the same result. It appears I'm very close, but that the bridge for the 7311 is not going to work with the 7310. Not sure what to do without that 7310 bridge, but at least the process is confirmed for compiling the driver and recognizing the camera. More to come.