God’s Blessings on January 13, 2017

God’s blessings on this the thirteenth day of January in the year of our Lord’s incarnation 2017.

I apologize for not posting yesterday. I don’t mean to let that become a habit.

So I discovered that the method I had been using to record video of me talking for my youtube channel fails after a few minutes. It’s actually an nondeterministic amount of time, but the problem is that if the camera skips any frames, guvcview doesn’t know about it and so the video and the audio go out of sync. I’m pretty sure that the video I have where this happened is just lost, because it’s not a gradual problem which can be cured by speeding up the audio; it’s that just something the time between the two permanently changes. On the plus side, I can always record it again.

But not with guvcview. And cheese is out too. (I use ubuntu, and these are all Linux software.) A friend recommended using ffmpeg, which is a command line utility. I’ve been a linux user for about 20 years now, so that’s not scary, but it does mean a ton of command line options to get ffmpeg to do what I want (because it’s an incredibly flexible piece of software). On the plus side, I’ve downloaded the source and compiled it, so I’ve got it working with nvenc which lets it do video encoding on my video card. So after a bunch of playing around, I got it to work. If anyone got to this blog post because they’re searching for a decent way to reliably capture a webcam in Linux, this is the command line I ended up using:

ffmpeg -f v4l2 -input_format mjpeg -video_size 1280×720 -framerate 30 -i /dev/video0 \
-f pulse -sample_rate 48000 -channels 1 -i default \
-c:v h264_nvenc -preset slow -profile:v high -rc vbr -cq 18 \
-c:a flac \
-copytb 1 \
$OUTPUT

I put it in a shell script (so I wouldn’t have to type that out all the time), so $OUTPUT is the name of the file to store the video in (whatever.mkv). This is for capturing video from my Logitech C920 and audio from whatever I’ve configured as the input source in pulse audio (which is to say, in the default sound configuration utility). Normally I use a shotgun mic, but of course one can also use the microphone built into the webcam. Using mjpeg (motion jpeg) from the webcam seems to produce higher quality output then getting h264 from it, and since I’m recompressing it anyway, I might as well use mjpeg as the source. Btw, you’ll need to use the apeture priority mode for the automatic exposure control in order to achieve 30 frames per second, otherwise there’s a good chance the camera won’t have enough light to achieve that framerate and it will go to a lower framerate, which looks awful.

Video is a surprisingly tricky thing. Video codecs are kind of amazing, when you get down to it. Using inter-frame compression, they’re able achieve huge levels of compression. But the tradeoff is that they’re very complex things, and complexity and reliability are usually enemies. And so it is with video standards; they are very complex things, which enables them to be implemented widely in both expensive and inexpensive devices, but the downside is that implementations vary and not all implementations work with each other. And what I’m finding is a common thing: it’s often best to go with the most popular solution because it will be best debugged. That’s not strictly true, though, because I still use guvcview to manipulate the camera’s settings. For example, I’ve turned off automatic focus because I stay in one place and this way the camera doesn’t try to re-focus if I lift my hands up.

Anyway, I’m also considering investing in a decent camcorder, like this. The solution I have works, but a camcorder produces much better video because it has a much larger lens and sensor. That means far less noise in the pixels. And it’s got thoroughly tested software on board to make sure that it never drops frames and that the audio and video are perfectly synced up. It also has a zoom mode which means I could set the camera up further away from me, which would make my face look more normal. Cameras close to their subjects distort faces because they exaggerate roundness. That’s why portrait artists often use 100mm lenses from 10-12 feet away. (100mm is about a 2x magnification, if you’re comparing it to binocular magnification.) It makes the face look more natural to have some distance between you and the face. The magnification is irrelevant except to get quality because in portraiture you want the face, not the background. It’s all about the change in angle between the surface and the camera sensor; the further away one is, the smaller the change in angularity.

But, while that’s not very expensive, it’s not cheap either, so I’m going to see if I can get decent results using my current setup, at least for a while.

Glory to God in the highest.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.