Contents
Resources
-
This article in the Register about Linux video editors has a general overview of what’s out there at the end of 2015.
-
This article helpfully goes into depth about the various encoding parameters that are important to frame rates. Actually this person’s entire videoblerg is extraordinarily competent.
v4l2 and Video Devices
Before dealing with any actual video, you often have to deal with
some kind of video devices like a camera. Use the v4l2-ctl
command
(from package v4l-utils
) to find out what kind of streams v4l
handles from that (unknown?) device.
$ v4l2-ctl -d /dev/video0 --list-formats
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'YUYV'
Name : YUYV 4:2:2
Index : 1
Type : Video Capture
Pixel Format: 'H264' (compressed)
Name : H.264
Index : 2
Type : Video Capture
Pixel Format: 'MJPG' (compressed)
Name : Motion-JPEG
And here’s another helpful diagnostic. This is shown reporting on a PlayStation Eye camera.
$ v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'YUYV'
Name : YUYV 4:2:2
Size: Discrete 320x240
Interval: Discrete 0.005s (187.000 fps)
Interval: Discrete 0.007s (150.000 fps)
Interval: Discrete 0.007s (137.000 fps)
Interval: Discrete 0.008s (125.000 fps)
Interval: Discrete 0.010s (100.000 fps)
Interval: Discrete 0.013s (75.000 fps)
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.020s (50.000 fps)
Interval: Discrete 0.027s (37.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 640x480
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.020s (50.000 fps)
Interval: Discrete 0.025s (40.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Here’s a helpful one showing general details about the EasyCap.
$ v4l2-ctl -d 0 --all
Driver Info:
Driver name : uvcvideo
Card type : AV TO USB2.0
Bus info : usb-0000:00:1d.0-1.2
Driver version : 4.19.28
Capabilities : 0x84a00001
Video Capture
Metadata Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04200001
Video Capture
Streaming
Extended Pix Format
Media Driver Info:
Driver name : uvcvideo
Model : AV TO USB2.0
Serial :
Bus info : 1.2
Media version : 4.19.28
Hardware revision: 0x00000121 (289)
Driver version : 4.19.28
Interface Info:
ID : 0x03000002
Type : V4L Video
Entity Info:
ID : 0x00000001 (1)
Name : AV TO USB2.0
Function : V4L2 I/O
Flags : default
Pad 0x01000007 : 0: Sink
Link 0x0200000d: from remote pad 0x100000a of entity 'Processing 2': Data, Enabled, Immutable
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
Width/Height : 720/480
Pixel Format : 'YUYV' (YUYV 4:2:2)
Field : None
Bytes per Line : 1440
Size Image : 691200
Colorspace : Default
Transfer Function : Default (maps to Rec. 709)
YCbCr/HSV Encoding: Default (maps to ITU-R 601)
Quantization : Default (maps to Limited Range)
Flags :
Crop Capability Video Capture:
Bounds : Left 0, Top 0, Width 720, Height 480
Default : Left 0, Top 0, Width 720, Height 480
Pixel Aspect: 1/1
Selection: crop_default, Left 0, Top 0, Width 720, Height 480, Flags:
Selection: crop_bounds, Left 0, Top 0, Width 720, Height 480, Flags:
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 30.000 (30/1)
Read buffers : 0
brightness 0x00980900 (int) : min=0 max=255 step=1 default=25 value=32
contrast 0x00980901 (int) : min=0 max=255 step=1 default=127 value=128
saturation 0x00980902 (int) : min=0 max=255 step=1 default=127 value=128
hue 0x00980903 (int) : min=0 max=127 step=1 default=0 value=0
gamma 0x00980910 (int) : min=0 max=50 step=1 default=0 value=0
Note that UVC stands for USB video device class.
A simple script to find the EasyCap device and play it with mplayer.
#!/bin/bash # Find the (first) easycap video device. V=0 while ! v4l2-ctl -d /dev/video${V} --info |grep "AV TO USB2.0">/dev/null ; do : $((V++)); done # Normal orientation. #mplayer tv:// -tv driver=v4l2:width=640:height=480:outfmt=uyvy:device=/dev/video${V} # Up side down mplayer tv:// -vf flip,mirror -tv driver=v4l2:width=640:height=480:outfmt=uyvy:device=/dev/video${V}
What is it? Video Identification
Often it is helpful to know what your starting point is. If you have a video with unknown characteristics, you can find out more about it by doing something like this.
mplayer -identify -vo null -ao null -frames 0 video.avi
This should tell you things like the codecs, bitrates, and the resolution.
You can use this with something fancier. Here is how to find out how many frames a video contains.
mplayer -identify -vo null -ao null -frames 0 mysteryvid.mp4 \
| awk 'BEGIN{FS="="} \
/ID_VIDEO_FPS/{rate=$2} /ID_LENGTH/{time=$2} \
END{print int(rate*time)-1}'
If the video is on a DVD, use acidrip
and select the "copy" options
for video and audio codecs. This will give you the video off the disc
with unmodified characteristics. Query those with the command above
and see what’s really there.
Also consider this which is probably the best option now.
ffprobe video.avi
Device ID
If you need to get a much better understanding of the capabilities of
a camera or webcam or something like that, check out the vrl2-ctl
command. This did a super job of hunting down camera capabilities.
v4l2-ctl -d /dev/video1 --all
YouTube Recommendations
Taken from here. They prefer 16:9 but will deal with other aspect ratios.
-
Container: MP4
-
Audio codec: AAC-LC
-
Stereo or Stereo+5.1
-
Sample rate 96khz or 48khz
-
Audio bitrates for uploads:
-
Mono |
128 kbps |
Stereo |
384 kbps |
5.1 |
512 kbps |
-
video codec: H.264
-
Progressive scan (no interlacing)
-
High Profile
-
2 consecutive B frames
-
Closed GOP. GOP of half the frame rate.
-
CABAC
-
Variable bitrate. No bitrate limit required, though we offer recommended bit rates below for reference
-
Chroma subsampling: 4:2:0
-
-
Frame rate: 24,25,30,48,50,60 (others ok too), not-interlaced (i.e. not 1080i60)
-
Bit rate: Table lists in Mbps for various frame rates (columns).
-
SDR=Standard Dynamic Range, HDR=High Dynamic Range
-
Resolution |
SDR |
SDR-High |
HDR |
HDR-High |
|
24,25,30 |
48,50,60 |
24,25,30 |
48,50,60 |
||
2160p(4k) |
35-45 |
53-68 |
44-56 |
66-85 |
3840x2160 |
1440p(2k) |
16 |
24 |
20 |
30 |
2560x1440 |
1080p |
8 |
12 |
10 |
15 |
1920x1080 |
720p |
5 |
7.5 |
6.5 |
9.5 |
1280x720 |
480p |
2.5 |
4 |
NA |
NA |
854x480 |
360p |
1 |
1.5 |
NA |
NA |
640x360 |
240p |
? |
? |
? |
? |
426x240 |
For more on bitrate this article is very helpful.
CRF = Constant Rate Factor (more info here), x264, 0-51 with good values 18-28, and default of 23. For x265 default CRF is 28. For libvpx 31 is recommended (lacks a default). Yet more good info here.
QP = Quantization Parameter - how much information is discarded to yet maintain a minimum level of quality.
How To Turn Off Comments On YouTube Hosted Videos
Fuck comments. If people want to communicate with me, they can send me an email. I don’t need some asshat stealing half of my video’s mental space by making it compete with one lone comment that says something stupid.
So accomplishing this simple thing is bewildering and subject to constant change. But basically, you need to be in the studio.youtube.com which will say "Studio" next to a red YouTube icon. The sub item on the left menu you want is Content. Every time you upload, you must come here and select the newly added video by checking it. Then "Edit from the black bar menu. Look for Comments. Then select Disable Comments. Next comes the unnerving part where you have to commit the changes or something. I did this and it seemed fine; I get the feeling that if you don’t do this, the comments will still be enabled, so double check that you completed the mission!
Comments Disable Comments.
Video Editing
Pitivi is an ambitious little editor that seems to stitch together some powerful command line utilities into a GUI. However, though I had some success with it, I also easily discovered its limitations.
For serious editing, and I mean serious, use Blender. The only disadvantage to Blender is it is easy to get overwhelmed in the massive feature set. I abused Blender on underpowered machines and never had it blink—rock solid. It is perhaps the most surprisingly stable software I’ve ever used. See my full notes on Blender.
Still Images From Webcam With fswebcam
Sometimes you just want your web cam to take a snapshot of what it’s looking at. In the past I’ve used this messy technique.
mplayer -frames 1 -vo jpeg:outdir=/home/xed/capturedir/ tv://
And that worked so well, that I needed this script to actually get what I needed.
#!/bin/bash # Need to capture several frames since the first couple are duds. mplayer -quiet -nosound \ -tv device=/dev/video0 \ -ss 143 -frames 3 -vo jpeg:outdir=. tv:// \ 2>/dev/null >/dev/null # Pick out last one. mv $(ls 0000[0-9]*.jpg|tail -n1) webcam-$(date '+%Y-%m-%d_%H%M%S').jpg # Delete the duds. Careful! This isn't very cautious. rm 0000[0-9]*.jpg
But there is a much better way if you can apt install fswebcam
. It
will take sensible simple shots of what the webcam sees.
fswebcam -r 640x480 --jpeg 85 -D 1 -F 10 snapshot.jpg
MPlayer
You might consider vlc if mplayer is problematic.
The OSD (on screen display) can show the elapsed time which can be super helpful for finding frames of interest of a video. The option is not easy to hunt down.
mplayer -osdlevel 2 myvid.mp4
Finding Excerpts To Extract From Larger Video
Often you record all kinds of junk and the cool thing you really wanted is buried in there. Thanks to mplayer or some other clever player with on screen display ("o" in mplayer), you know where exactly you want your excerpted video to begin and end.
This worked for me to find the correct subset clip. This was done on another machine so I could control mplayer from a different location than where it was running full screen.
DISPLAY=:0.0 mplayer -ss 372 -endpos 25 -fs Encode_1080P_4.mp4
The 372 is the starting position in seconds and the 25 is the duration of the clip.
mplayer with the webcam
If your webcam puts a feed in an obvious place, mplayer can probably do nice things with it. Here are some examples.
First if you need to specify which webcam you’d like to be using try something like this.
mplayer tv:// -tv driver=v4l2:device=/dev/video1
Watch the camera and specify where it is.
mplayer -tv device=/dev/video tv://
Is your camera upside down? This is common with a USB microscope. This might help.
mplayer -vf flip,mirror -tv device=/dev/video0 tv://
Don’t like pixels? Have no fear! Use ASCII using libcaca.
mplayer -vo caca tv://
Or if you need to see a video and you only have a console without any graphics.
CACA_GEOMETRY=$(stty size|awk '{print $2"x"$1}') mplayer -quiet -vo caca tv:/
MEncoder
Mencoder seems to be related to mplayer but Debian seems to have stopped carrying it. What a mess! Oh wait… 2019, it’s back!
Adding And Removing Sound Track
Provide your own sound track:
mencoder -vf rotate=1 -oac copy -audiofile st.mp3 -o out90.avi -ovc lavc in.avi
Mute
Or mute the thing entirely:
mencoder -v -nosound -o outvid.avi -ovc lavc invid.mp4
Here is the ffmpeg way to remove the sound (note the -an
option
which disables audio).
ffmpeg -i invid.avi -vcodec copy -an outvid.avi
Strip out the audio tracks for all files named FILE????.MOV
renaming
to lower case file????.mov
.
for F in *.MOV; do echo $F ; ffmpeg -i ${F} -vcodec copy -an ${F,,} ; done
This rotates and cuts off the first 3 seconds and nulls the sound track:
mencoder -vf rotate=2 -ss 3 -ovc xvid -oac copy -audiofile /dev/null \
-o t_xed.avi -xvidencopts bitrate=300:pass=2 MVI_1393.AVI
Note that -endpos
can be used for clipping the end off video.
Sometimes the -ss
option doesn’t really work when I think it should.
Here is a way to cut off the beginning of a video. This cuts off the
first half a second.
mencoder -v -ss 00:00:20 -nosound -o outvid.avi -ovc lavc invid.mp4
Side By Side Viewing
Sometimes you’re doing analysis of bit rates or codecs or maybe you’re doing some kind of filtering and you want to watch two videos side by side. Or maybe you want an inset picture of a 2nd video. This worked for me on a 4k monitor to show two HD clips.
bash -c "sleep .3 && mplayer -quiet -geometry 1920x1080+0+500 a.mp4 &" && mplayer -geometry 1920x1080+1920+500 b.mp4
vlc
vlc
is yet another comprehensive media player. It has tons of
tricks. The documentation really seems to depend on what’s compiled
into the binary and the developers therefore have a sensible man page
that basically directs you to get detailed option help with this.
vlc --longhelp --advanced | less
To play the normal video device (perhaps a webcam).
cvlc v4l2:///dev/video0
Note the cvlc
which is presumably for "command line". It’s just an
alias for this.
vlc -Idummy v4l2:///dev/video0
This works too for the default video device.
vlc -Idummy v4l2://
I’ve had luck with internet cameras using something like this.
cvlc rtsp://192.168.1.237:554
This could be useful.
cvlc -vvv v4l2:///dev/video0:width=1920:height=1080
In theory you can use screen://
for screen capture.
Here’s how to record something from a camera.
cvlc --rtsp-user root --rtsp-pwd ${P} \
rtsp://192.168.1.248/live.sdp \
--sout=file/ps:/tmp/videocapturetest.mpg
Options that could be useful.
-
-f
= full screen. -
--width
= video width. -
--height
= video height. -
--crop
= apparently you can crop which could be handy to filter out the opposite of regions of interest. -
--sub-file
= seems to have a lot of features related to subtitles. -
--rtsp-user root
and--rtsp-pwd ${P}
ffmpeg
ffmpeg is a great tool for converting video from something to something else. See the ffmpeg documentation.
Install
If you need to download FFmpeg from source here’s the official web site.
If you’re using Debian or Ubuntu and really need FFmpeg (for OpenCV for example), you may need to compile it from scratch. It’s pretty polite and behaves as you’d expect. You do need to put some prerequisites in place first. Here’s a look at how it’s done.
Find the latest version at: https://ffmpeg.org/download.html Acquire using one of these.
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
wget http://ffmpeg.org/releases/ffmpeg-3.2.4.tar.bz2
Compile
apt-get install yasm pkg-config
./configure
make
sudo make install # Puts things in `/usr/local/` by default.
This should give you ffmpeg
, ffprobe
, ffserver
.
Problems with video in OpenCV? That can be related to FFmpeg.
sudo apt-get install libopencv-dev python-opencv
If you’re using a system that has ffmpeg properly provisioned you might be able to just install it with the package manager. Here are some packages I have needed to consider to get things working properly.
sudo apt-get install libavcodec-dev libavcodec-extra-52 libavcodec-unstripped-52
GUI
Check out FFmpeg Little Helper for a web based GUI that generates the correct command line.
Common Usage Tips
The -y
option will skip overwrite warnings; this can be helpful when
iterating to find a command line that produces the results you’re
looking for.
When specifying filters, you can use either of these equivalent syntaxes.
ffmpeg -i in.mp4 -filter:v "crop=200:100:50:50" out.mp4
ffmpeg -i in.mp4 -vf "crop=200:100:50:50" out.mp4
To combine multiple filters, do something like this.
ffmpeg -y -i in.mp4 -vf "crop=1720:1080:200:0,select='not(mod(n,30))',setpts=N/FRAME_RATE/TB" -vsync vfr out.mp4
To get a stream, perhaps with a password, this syntax has been known to work.
ffmpeg -i 'http://root:mypAss@192.168.1.2/axis-cgi/mjpg/video.cgi?camera=2' output.mp4
Applications
Repackage
Sometimes it’s the container that is bad. Maybe there is an audio track but it is muted or the file size was preallocated but really requires a small fraction of that. This script simply copies the video stream untouched while stripping out the audio.
#!/bin/bash for N in *.MOV; do echo $N; time ffmpeg -i $N -an -vcodec copy ${N,,} ; done # Check that all is well and then... # rm *MOV
This can achieve 25% space savings for a typical preallocated (all videos are 3.7GB, no matter how brief!) video from one of my dashcam’s footage with no loss of quality.
Speed Up Or Slow Down
I have successfully used the technique described here. For example, this takes a long boring video and makes it a smaller (size) and shorter (time) video.
ffmpeg -i in.mp4 -an -filter:v "setpts=0.5*PTS" -s 320x240 out.mp4
This saves an enormous amount of storage space.
Encode
Sometimes you get video data in the form of something like a raw H264 stream. To encode that into a proper mp4 codec is pretty simple with ffmpeg. Here is video captured from a Raspbery Pi camera being converted to a playable format.
ffmpeg -i tmp.Cs8TLRKcWE/pivid-001.h264 -an -vcodec copy normalvideo.mp4
Sometimes you make a nice video and the stupid browser complains: Video can’t be played because the file is corrupt. This may happen even if you can play it from the command line just fine. How to fix? Well, I don’t really understand the details of the problem (an always moving target), but this encoding process cleared it up for me.
ffmpeg -i fine.mp4 -pix_fmt yuv420p -c:v libx264 -movflags +faststart -filter:v crop='600:600' good.mp4
Note that there are rumors that it has to be a square aspect ratio. That’s a bit mental but whatever - in my case, it coincidentally worked out but something to keep in mind.
Cropping
Instead of rescaling you can change the output size by cropping the frames, perhaps removing something stupid, e.g. a FLIR logo.
ffmpeg -i test.mp4 -vf "crop=200:100:50:50" out.mp4
The crop variable is the width, height followed by the x and y offsets; left is 0 and top is 0.
Rotating - Correcting The Error Of Portrait Video
The epic stupidity of telephone cameras means that it is almost the rule rather than the exception that video taken with them will be upside down or in the incorrect mode. Which is portrait mode — the incorrect mode for video is portrait. Portrait mode is an abomination made more painful by the surprisingly complex process required to correct it.
A good resource on this (is not StackExchange!) can be found here.
To fix this, it seems you have to re-encode it. Not only that but you often need a two step process to first correct the metadata and then the re-encode to dimensions that are actually accurate. Super annoying.
First make sure you can get a handle on what you’ve got. You can use
ffprobe
or exiftool
to have a look at what you need to know. I
find that ffprobe
works fine and without surprises, but exiftool
is very clear. For example running it on a video shot with a telephone
held the wrong way yields this.
exiftool -Rotation -ImageWidth -ImageHeight sideways.mp4
Rotation : 90
Image Width : 1920
Image Height : 1080
If it’s really a vertically oriented shot with, say, a person’s head at the top and feet at the bottom, how would the "width" be bigger than the "height"? So it’s like the camera is fixed with its horizontal axis as the long one and it’s just being held sideways and that’s noted in the rotation metadata.
Step one is to fix that metadata. This should work.
ffmpeg -i sideways.mp4 -c copy -metadata:s:v:0 rotate=0 temp.mp4
Perhaps check it again to see if that worked. But now you have a video
with no spurious "rotation" metadata, (which mplayer
ignores). How
do you re-encode it so that it’s actually 1080 wide and 1920 high?
This seems to work.
ffmpeg -i temp.mp4 -vf "transpose=1" -crf 23 -c:a copy rotated.mp4
Note that the transpose settings are rather cryptic and though I haven’t verified this, here is a plausible explanation I have encountered.
0 |
|
90 deg counterclockwise and vertical flip (default) |
1 |
|
90 deg clockwise |
2 |
|
90 deg counterclockwise |
3 |
|
90 deg clockwise and vertical flip |
The following seemed to work for a completely upside down video.
ffmpeg -i upsidedn.mp4 -vf "transpose=1,transpose=1" -codec:v libx264 -codec:a copy ok.mp4
I think that a 90 degree rotation can be achieved by removing one of the "transpose=1" statements. When running this I got a ton of "Past duration too large" warnings which I ignored.
Also consider this if your camera is mounted up side down.
ffmpeg -i upsidedown.mp4 -vf "vflip,hflip" ok.mp4
And for lack of a better place to note it, if you have still images
from a "telephone" "camera", they too are no doubt tagged with an
incorrect orientation. To dump all the exif data an image is tagged
with, just use exiftool image.jpg
. That command I believe can fix
orientation problems but an easier way may be to use
exifautotran image.jpg
.
Extracting subset
Here is roughly the technique needed to get this working.
ffmpeg -ss 00:06:00 -i wholegame.mp4 -t 00:00:30 -acodec copy -vcodec copy -async 1 dunk.mp4
Note here that the resulting video is only 30s long (6 min to 6.5 min from the original source). Also note that it seems important that the -ss come before the -i option.
Is the video silent? Do something like this and it definitely will be.
ffmpeg -ss 00:02:10 -i vid_002.mov -t 00:03:27 -an -vcodec copy -async 1 kayak1.mp4
This one will split a video into two files at a breakpoint 30 seconds into the video.
ffmpeg -i in.mp4 -t 00:00:30 -c copy 1st30s.mp4 -ss 00:00:30 -codec copy therest.mp4
Here is another look at doing this.
ffmpeg -i SK8.mp4 -ss 00:08:10.0 -vframes 5100 -acodec copy -vcodec copy -async 1 OSK8-test.mp4
Here is another trick if you’re tying to get a short clip from a bigger video because you want to share it on some web platform like Slack or Discord. Note the libvpx codec. This file is only 6MB for 20 seconds, so pretty light.
ffmpeg -i GH040327.MP4 -ss 00:07:05 -t 00:00:20 -vcodec libvpx -s 640x480 -f avi -an goproclip.mp4
Note that ffmpeg
has a -t
option to set the duration time of the
video, but I’ve have had problems getting it to work and have seen
reports of others with the same problem. But -vframes
does seem to
cut off the video at the right place. It’s annoying they don’t just
have start time and stop time which would make sense. To get the
correct vframes value you have to figure out the duration in seconds
you want and then multiply by the frame rate (often 30). To get frame
rate, play the video with mplayer and watch its console output for
"FPS".
Concatenating Videos
Official documentation for concatenation might be useful.
If you have multiple fragments that you need to join, include their
paths in a text file. The file formerly could be a simple ls
but
now it seems to want some fancier format. This worked for me.
ls /tmp/*.mp4 | sed "s/^\(.*\)$/file '\1'/" > mylist.txt
Once you have the file list created this should work.
ffmpeg -f concat -safe 0 -i mylist.txt -c copy out.mp4
Some discussion about this topic.
Note that the extremely irritating "safe" nonsense relates to a bunch of cryptic things discussed here.
Scaling/Resizing Videos
Very good official documentation about all aspects of video scaling can be found here. A good way to shrink videos from the Canon A590 to send to fb:
ffmpeg -i mvi_0378.avi -f avi -vcodec mpeg4 -s 320x240 -r 20 -ar 22050 -b 1000000 ski2.mpg
Another application to shrink videos to save space (factor of 5 without noticeable quality loss):
ffmpeg -i inputfile.avi -ar 32000 -s 480x360 -b 1252.4k outputfile.avi
The -s
is the new size. The -ar
is the audio bitrate.
Here is the ffmpeg way to resize. This shrinks the geometry with -s
and removes the audio with -an
. This size is quarter HD and used in
some driving videos I’ve worked with.
ffmpeg -i dashcamHD.mov -s 960x540 -an dashcam_qHD.mp4
Often you want to share something in a bandwidth economical way — this often can be best achieved by scaling and extracting only relevant parts. Here I’m taking a 3.7GB dashcam video and creating a new (re-encoded) video of only the action between 1:45 and 2:45.
ffmpeg -ss 00:01:45 -i VID_003.MOV -t 00:01:00 -an -vcodec mpeg4 -s 320x240 sunrise.mp4
The resulting file is 1.7MB and is sufficient to properly understand what’s going on.
Image To Video
The following technique is useful for making stop motion animation videos and videos of slide shows. It takes a list of image files and converts them into a video format.
ffmpeg -i hm%04d.png -r 25 prototype.mp4 # mplayer works; VLC fails.
ffmpeg -i hm%04d.png -pix_fmt yuv420p -r 25 -an prototype.mp4 # VLC works; mplayer fails.
ffmpeg -i hm%04d.png -c:v libx265 -pix_fmt yuv420p -r 25 -an prototype.mp4 # VLC and mplayer work.
Note that without the -pix_fmt yuv420p
option, you might get
something that plays in mplayer
but will crash in vlc
.
The -r is the framerate, here 120 frames per second (30 is common).
These particular settings were to extract video from a GoPro. Note
that with this starting offset (-ss
) the program can sit there
apparently doing not much of anything for quite a while until it gets
to the relevant section; I think it must calculate the previous frames
since many codecs are basically diffs.
Note
|
There may be other ways of doing this, but the easiest is to
name all the jpegs to use 001.jpg, 002.jpg, etc. If the sequence is
broken, ffmpeg will stop encoding. So make sure the names are in
order. (Look into using Chris'
numbfile program. Try
numbfile -z3 -s.jpg *jpg if less than 1000 images). |
Note
|
If you need an animated png, mplayer seems to do that too. Look in the man page for the png video output setting. |
This used to work for PNG:
ffmpeg -r 10 -b 64k -qscale 2 -i torcs-0001-0000%04d.png snakeoil.mp4
Now I’ve had better luck with this.
ffmpeg -i torcs-0001-0000%04d.png -r 25 -qscale:v 2 kurinjimala.mp4
This makes a large but high quality video. I’ll let YouTube sort out the details.
Sometimes you have a big collection of jpegs from something like
motion
and they have messy timestamps in their names. How do you
make all the images into a format for something like a technique that
needs a numeric printf pattern?
C=0 ;ls /var/lib/motion/*jpg | \
while read F; do echo $F ; cp -v $F $(printf "/tmp/%05d.jpg" $C); : $((C++)); done
Or check out this method that can use globs directly.
ffmpeg -framerate 1 -pattern_type glob -i '*.png' -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
It seems like globbing isn’t always present in ffmpeg and that’s a pain.
Video To Image
Just like the other way around, you can pull still images out of video. Some official documentation describes this technique which looks good.
time ffmpeg -i A.mp4 -ss 00:00:15.000 -vframes 1 Aat15sec.png
Wow… I just learned something very important. The order of arguments matters!! A lot! I have a long video I need to get 100 frames from at specific points. If I do this it could take half an hour.
ffmpeg -i ../big.webm -ss 02:29:26 still.png
If I do this it takes half a second.
ffmpeg -ss 02:29:26 -i ../big.webm still.png
Note the order is the only difference. The order in this case changes it from accurate seeking mode to fast seeking mode. More is said about this here.
Here’s another example. This one takes a still every second (fps=1
). The
qscale:v
is a quality specifier. Apparently 2 is the highest.
ffmpeg -i in.mp4 -qscale:v 2 -vf fps=1 stills%04d.jpg
Note that stuff like fps=1/2
for an image every two seconds.
It’s worth double checking the quality of the images if that is
important. I found that the -qscale
technique could have quality
issues despite 2 being the ostensible "best".
Some people believe that using -qmin 1 -qscale:v 1
will make things
good. I didn’t try that but worth checking. Watch file sizes.
This works ok. Not perfect but ok.
ffmpeg -i input.mp4 -bsf:v mjpeg2jpeg -vf fps=1 %05d.jpg
In theory you need to have a particular cooperative codec. In practice it helped a lot.
Also note that if you extract to PNG it may not be lossless (and jpg
certainly loses information). A strategy that avoids this problem is
to extract to uncompressed .bmp
files. These might be quicker
to produce. After reviewing the images to your satisfaction, you can
use ImageMagick’s convert
to change them to lossless PNG with the
PNG24:
filename prefix.
#!/bin/bash # A script to interactively pull frames out of a bigger video. The # idea is you watch the video and take notes about the shots you want. # Then run this using that notes file. The script will show you the # frame and if it's ok, quit the viewer ("q") and press "y" to accept # this frame. If the frame should be later, type in an offset in # seconds (keep the resolution at .1s). If you need a slightly earlier # frame, type a negative number. You can keep trying until you get # exactly the frame you want. This is how you can take rough notes, # but still get the exact shot you wanted to save. # # The basic extraction from the video is done with something like this. # ffmpeg -y -ss 01:23:45.6 -i /data/somevideofromYT.webm -frames 1012345.6-label1.png # # The notes look like this (HMMSS_label - ): #00357_label1 - Some description can go here. #00520_label2 - Descriptions are ignored by this process. #00542_label3 - #00550_label4 - Or leave it blank. VID="/data/somevideofromYT.webm" NOTES="/home/xed/X/project/notesfile.txt" function adjust_val { set -o noglob H=$1 M=$2 S=$3 D=$4 NEWSECS=$(echo "$H * 3600 + $M * 60 + $S + $D" | bc) NEWH=0$(echo "$NEWSECS / 3600" | bc) NEWM=$(echo "($NEWSECS - ($NEWH" '*' " 3600)) / 60" | bc) if [ ${NEWM} -lt 10 ]; then NEWM=0${NEWM} ; fi NEWS=$(echo "($NEWSECS - ($NEWH" '*' " 3600) - ($NEWM" '*' " 60))" | bc) if [ ${NEWS%.*} -lt 10 ]; then NEWS=0${NEWS} ; fi echo "${NEWH}:${NEWM}:${NEWS}" } # End function adjust_val function collect_ss { H=$1 M=$2 S=$3 N=$4 while read -p "Command or OFFSET: " UI; do case ${UI} in s|S|w|W|y|Y) break;; # Ok, happy with it - save it and write and next one. n|N) return;; # Skip to next one - no writing. q|Q) exit;; # Quit entire process immediately. "") echo "Enter some offset number in seconds.";; esac echo "Refining: ${H}:${M}:${S} ${N}" D=${UI:-0} echo "Adjusting by: ${D}" NEWVAL=$(adjust_val ${H} ${M} ${S} ${D}) echo NEWVAL: ${NEWVAL} echo "========= ffmpeg -y -ss "${NEWVAL}" -i ${VID} -frames 1 /tmp/${N}.png" ffmpeg -y -ss "${NEWVAL}" -i ${VID} -frames 1 /tmp/${N}.png 2> /dev/null echo "========== feh /tmp/${N}.png" feh /tmp/${N}.png done echo mv /tmp/${N}.png /home/xed/X/project/$(sed 's/://g' <<<${NEWVAL})-${N#*_}.png mv /tmp/${N}.png /home/xed/X/project/$(sed 's/://g' <<<${NEWVAL})-${N#*_}.png } # End function collect_ss # Lines in the notes file to iterate over to get information from. BEG=1 END=$(wc -l ${NOTES} | cut -d' ' -f1) for N in $(seq ${BEG} ${END}); do echo "==================== LINE ${N} ====================" ARGS=$( sed -n ${N}'{p;q}' ${NOTES} \ | awk '{print $1}' \ | sed 's@\(\([0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)_\(.*\)\)$@0\2 \3 \4.0 \1@' ) echo ${ARGS} collect_ss ${ARGS} done
Video to MP3
Extract mp3 track of the video to sound files with:
ffmpeg -i SomeSongVideo.flv -acodec copy SomeSong.mp3
This assumes that the video has an mp3 encoded sound track. YouTube appears to do this. Here’s a more complicated way to do this that might be necessary:
ffmpeg -y -i INPUT.flv -acodec libmp3lame -ar 22050 -ab 128000 OUTPUT.mp3
Here’s a function that can turn Youtube videos into mp3 files on the fly:
function ripme {
youtube-dl -q -o - "$1" | \
ffmpeg -y -i - -acodec libmp3lame -ar 22050 -ab 128000 "$2.mp3"
} # End function ripme.
# Call like so:
ripme http://www.youtube.com/watch?v=CknuCTRAW_I Dire_Straits-Walk_Of_Life
To check what streams, audio and video, are in a video file:
ffmpeg -i inputvideo.flv
To actually convert some other audio stream:
ffmpeg -i inpuvvideofile.flv -ab 128k outputaudiofile.mp3
Where -ab specifies the audio bitrate.
To extract a subset of video to a new video:
mencoder -ss 2693.0 -endpos 1350.0 All_Four_Episodes.avi -ovc copy -oac copy -idx -o Episode_Three.avi
Not that the -ss is the start always in seconds. The -endpos is more ambiguous. If an -ss is used, it means seconds running time of the subset. If -ss isn’t used, it means the same thing and it actually corresponds to endposition (time of subset from zero). This is why in the example, the "end position" is less than the -ss, starting position.
General ripping:
/usr/bin/mencoder dvd:// -dvd-device /dev/sr0 -ovc xvid -xvidencopts pass=2:bitrate=1000 -ni -alang en -oac mp3lame -lameopts vbr=3 -o moviename.avi
Animated GIFs
Check animated GIFs by loading them from a browser
(file:///tmp/mymeme.gif
) or this.
gifview -a mymeme.gif
Install that with apt install gifsicle
.
ffmpeg And ImageMagick
I was able to create an animated gif with just this.
ffmpeg -i example.mpeg -r 30 -s 160x120 out.gif
This didn’t preserve color and probably degrades things. This takes longer, but retains color and makes a nicer final product.
ffmpeg -i example.mpeg -r 30 -s 160x120 /tmp/tiff/out%04d.tiff
Then take the decomposed images and combine them with ImageMagick (which has pretty excellent documentation about animated gifs).
convert -delay 1x30 -layers Optimize /tmp/tiff/* -loop 1 example.gif
A loop
setting of 0 will endlessly repeat.
Animated GIFs In Gimp
The way to make the highest quality optimized animated gifs in my experience is to use Gimp. First get all your source frames out of Blender or ffmpeg as pngs in some directory. In Gimp go to "File → Open As Layers…", which is [C][A]-o, and select all the frame images. I find that this tends to load numbered image sets in the wrong order. It is easier to cure this problem with "Layer → Stack → Reverse Layer Order" than to conclusively determine you have this problem; if your animation is ultimately backwards, you know what to do. Start with the first frames at the bottom and end frames at the top of the layer stack. Once the layers are present and in the right order automatically cut out any unnecessary material using "Filters → Animation → Optimize (for GIF)". For many low color count applications, this will slash the file size. Note that if you really want to slash file size, shrinking the image size (with [A]-i,s) is very effective but note that if you’ve already done optimizing, the optimized frames do not scale cleanly — you’ll have to load them again. Finally, export with [C][S]-e as GIF by naming it something ".gif". Make sure you select the "As animation" checkbox. Choose loop or not depending on the situation — usually on is fine.
You can set the timing of all frames in the export dialog. Or if you
have complex timings, you can set different intervals per frame by
including (TIMEms)
in the layer name in the layer name, usually at
the end. Replace the text "TIME" with the number of milliseconds, so
(1250ms)
for 1.25 seconds, (42ms)
for about 24fps, (33ms)
for about
30fps, etc. You can also include the special tags "(replace)" or
"(combine)" in the layer name to specify whether that frame is added
on top of the previous frame or replaces it completely. I think
something like this is valid Layer 3 (80ms) (replace)
.
gifsicle
Seems simple enough. Install normally.
`sudo apt install gifsicle`
Simple cases are simple — note that output is piped out by default.
gifsicle pic1.gif pic2.gif pic3.gif > animation.gif
Also the --info
or -I
flag can tell you about an animated gif
which can be helpful.
Animated GIFs From Screen Capture
Making tutorials or trying to post on BlenderSE? Want fancy illustrative gifs of what you see on your screen? Check this answer for hints about how to do that.
I had good luck with apt install byzanz
, a CLI animated GIF recorder
for Linux. I got it working fine as expected with this (see also the
sensible man page).
byzanz-record -h 400 -w 650 -x 1264 -y 1500 -c -d 15 --delay=3 /tmp/byz-test.gif
The -d
is the duration of the whole clip. The --delay=3
is there
to help you get into position and is equivalent to sleep 3 &&
byzanz-record ...
. The -c
makes sure to include the mouse cursor.
Tip: Figuring out what the coordinates are can be a pain but a good
trick is to open a terminal and then resize it to exactly cover the
screen region you want to capture. Then run xwininfo
and click that
terminal window. Now move that terminal somewhere else and use the
width, height, X, Y information collected to fill in the values and
the capture should come out correct.
Also peek looks promising.
For posting purposes the following is recommended.
-
Keep things under 2mb.
-
15fps is a good starting point.
-
650x400 seems traditional.
Animated GIFs As Blender Clips
It’s extremely weird that Blender doesn’t know how to deconstruct animated gifs and import them as clips into the VSE. The best technique I’ve found is to convert them to a lossless output video and import the clips as a movie. Here’s a technique that is way more involved than you might have hoped, but it does seem to work perfectly and it seems to preserve quality well.
First convert to a lossless video.
ffmpeg -i ./my_gif_strip.gif -c:v ffv1 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -r 25 output_lossless.avi
Then to a video Blender likes.
ffmpeg -i output_lossless.avi -c:v libx264 -crf 18 -pix_fmt yuv420p \
-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" my_gif_strip.mp4
Time-Lapse
Some proper documentation details about speeding up (and slowing down) video (including audio) can be found here.
This mostly works.
ffmpeg -i test.mp4 -vf "select='not(mod(n,5))',setpts=N/FRAME_RATE/TB" -vsync vfr out.mp4
This technique is supposed to drop 19 of 20 frames by playing with the frame rates.
ffmpeg -i in.mp4 -vf "setpts=(PTS-STARTPTS)/20,fps=20" out.mp4
ffmpeg -i in.mp4 -vf "setpts=(PTS-STARTPTS)/20" -r 20 out.mp4
Sometimes I’ve had problems where video playback does not end. I
play the video and it looks fine but when it finishes, it sits there
and waits a long time. This is often when I’ve been altering the speed
of things or making time lapse from normal video. What I have figured
out is that this can be caused by some latent, perhaps silent audio
track that didn’t get the same kind of time dilation and it’s
finishing its (silent) playback. I found that by throwing in a -an
the problem was fixed.
ffmpeg -y -i in.mp4 -an -vf "select='not(mod(n,30))',setpts=N/FRAME_RATE/TB" -vsync vfr out.mp4
Recording Live Screen Actions
If you’re trying to make a video showing someone how you do a computer
thing you’ll want to live capture your screen. The x11grab
format
specification can do the job. Here is the full command to record 10s
of screen action from roughly the upper left HD quadrant of a display.
ffmpeg -y -f x11grab -video_size 1920x1080 -framerate 24 -i :0+20,20 \
-thread_queue_size 512 -f alsa -ac 2 -channel_layout stereo -i hw:0,0 \
-c:a mp3 -vbr on -compression_level 8 -t 10 /tmp/captured.mp4
I’ll break down what everything does.
ffmpeg -y
The y is to agree to overwrite any pre-existing file.
-f x11grab -video_size 1920x1080 -framerate 24 -i :0+20,20
The video grabbing format and the input device is similar to -i
${DISPLAY}+${X}+{Y}
where X and Y are the coordinates from upper left
to start the subregion from. The size completes the specification.
Some people believe framerates of 30 make sense, but I would think
even lower is ok if space is important.
Now the audio.
-thread_queue_size 512 -f alsa -ac 2 -channel_layout stereo -i hw:0,0 \
-c:a mp3 -vbr on -compression_level 8
I’m not sure if the thread_queue_size is important. The ac means two
channel - this also may be wrong. The input device seems to be the
default mic and can be looked into with arecord -l
; the numbers come
from the card 0:
and device 0:
I think.
-t 10 /tmp/captured.mp4
Finally specify how long you want the capture to last and the file name. I would recommend specifying a fixed time even if you don’t know how long you’ll ramble on. By cutting off the recording (with Ctrl-C BTW) you may leave the recorded file in a confused state. It might be better to have a longer file that you can then truncate later.
To make sure the region you want to record is exactly correct, it can
be helpful to use wmctrl
like this.
wmctrl -r "Blender" -e 0,0,0,1920,1080
This puts the Blender
window in the upper left corner of the display
in the right place and size to be captured. Another way for Blender
specifically is this.
blender --window-geometry 0 1080 1920 1080
Note the first two numbers are x and y of the lower left point.
Here’s a way to keep a running countdown to keep an eye on how much time you have left. This will print a countdown (presumably to the end of your fixed length video) and print in red for the last 10 seconds.
for S in {65..0}; do if [ $S -gt 10 ] ; then \
echo $S; else printf "\e[01;31m${S}\n" ; \\
fi; sleep 1; done
I show 65 so that you can start this and when it gets to 60, start your 1 minute video.
avconv
This article sums up the Real Housewives of libav/ffmpeg quite well.
…it was actually pretty funny to see them acting like children, even though the situation was kind of serious…The main problem is that external projects who want to support both FFmpeg and Libav are just fucked…
Ya, so this is tricky. It sounds like the ffmpeg lead maintainer was being a bit of an imperious wanker and then the avconv guys forked it (or something), started up with their own management style problems, and proved why he needed to be a wanker.
Previously I had needed to give avconv its own section because it was showing up as the primary option on Debian and there were enough irritating differences. These days I think that the Libav project is struggling now that it has lost its ace card of being bundled with Ubuntu.
Here is Wikipedia on the current state of affairs as of March 2019.
The maintainer of the FFmpeg packages for Debian and Ubuntu, being one of the group of developers who forked FFmpeg, switched the packages to this fork in 2011. Hence, most software on these systems that depended on FFmpeg automatically switched to Libav. In July 8, 2015, Debian announced it would return to FFmpeg for various, technical reasons. Several arguments justified this step. Firstly, FFmpeg had a better record of responding to vulnerabilities than Libav. Secondly, … a security-oriented developer at Google, argued that all issues he found in FFmpeg were fixed in a timely manner, while Libav was still affected by various bugs. Finally, FFmpeg supported a far wider variety of codecs and containers than Libav.
It has been suggested to merge the two projects back into each other but this has not happened. With Debian and Ubuntu no longer using Libav, its future might be compromised and its development may no longer be sustainable.
There seems to have been something of a vague reconciliation. Now it looks
like there may be an ffmpeg
package that is the real thing again,
now no longer forked. Whew! The active ffmpeg web
site seems like it’s still going strong. Doing a Debian apt-get
install libav-tools
in Feb 2017 produced a working avconv
and no
ffmpeg
. Here is
a
discussion of this situation.
I am personally going to pick sides here and go with ffmpeg as my first choice.
-
I don’t like how libav/avconv made a lot of confusing name decisions.
-
I don’t like how they injected themselves into the Debian ecosystem essentially breaking ffmpeg. Feel free to fork and establish a new thing, but don’t silently replace.
-
I don’t like how they silently replaced but with slightly different syntax. Super frustrating.
-
Quite a lot of bollocks needed to legally harass ffmpeg over using their own logo because libav had stolen it.
-
History is written by the victor and avconv seems to have lost. If you want to invade turf like avconv tried to do, you must clearly prevail.
So I’m going to focus only on ffmpeg in the future.
youtube-dl
Also use youtube-dl to get videos from YouTube:
youtube-dl -o SomeSongVideo.flv http://www.youtube.com/watch?v=SoMeSoNg321
Sometimes you get the annoying webm format that mplayer is not so good with (maybe that will get fixed). So it’s sometimes good to try and get a "better" file format, where better doesn’t necessarily mean image quality.
First you need to see what’s available:
youtube-dl --all-formats --get-filename http://www.youtube.com/watch?v=SoMeSoNg321
SoMeSoNg321-43.webm
SoMeSoNg321-35.flv
SoMeSoNg321-34.flv
SoMeSoNg321-18.mp4
SoMeSoNg321-5.flv
Then you need to download the one that makes sense:
youtube-dl -f 35 http://www.youtube.com/watch?v=SoMeSoNg321
Another useful option is -t
which names the file after the title of
the video instead of the messy (to us) hashed name.
Make sure you have
sudo apt-get install ffmpeg libavcodec-extra-53
Also, this can take a Youtube URL and make an mp3 out of it. Very handy.
youtube-dl -t --extract-audio --audio-format=mp3 'http://www.youtube.com/watch?v=SoMeSoNg321'
If youtube-dl
is not working out, you can look into forks like
yt-dlp.
Avidemux
After having way too much trouble doing simple track substitutions with the command line tools, I installed this:
sudo apt-get install avidemux
And it was able to put an mp3 over a video no problem. I didn’t figure out 1% of what this thing did but it seemed to work for that task pretty easily.
Raspberry Pi
This guy has a a very good summary of what is needed.
Let’s say you just want to monitor the camera feed on the HDMI screen for some reason (maybe you’re aligning the camera) here are some crazy ways to do it.
raspistill -t 10000000000000 # Or something like that.
raspivid -fps 20 -t 99999999 -o - | mplayer -fps 20 -cache 1024 -
Or according to this article you can install this module.
sudo modprobe bcm2835-v4l2
After that is done, you should have a working /dev/video0
.
Unfortunately I found that it didn’t work with things like guvcview
or mplayer
and it was super slow with cheese
.
Here is a good list of things to consider when getting the Pi camera to work with OpenCV.
This is something that is good to do.
sudo apt-get install python-opencv
Webcam Tricks
Note
|
Some webcam problems can be traced to the BIOS. Obvious, but easily overlooked is whether the web cam is enabled in the BIOS. This also is a hint at how to do quite a bit to ensure web cam privacy (i.e. disable it). Also sometimes BIOS updating can be required for Linux to properly see a webcam, especially from a new laptop. |
DLSR As Web Cam
This explains specifically how I got a Canon EOS M50 MarkII to be a Linux web cam. Much of this was expedited by this helpful guide.
First you’ll want to install anything that is lacking.
sudo apt install gphoto2 v4l2loopback-utils v4l2loopback-dkms
Then you have to load the right kernel modules.
sudo modprobe v4l2loopback
Then you want to check if the camera is detected and known by the camera interfacer, gphoto2. If it isn’t done already, now would be a good time to turn on your camera.
gphoto2 --auto-detect
Mine looks like this.
Model Port
----------------------------------------------------------
USB PTP Class Camera usb:001,005
Also the following command is helpfully informative about what features you can expect.
gphoto2 --summary
gphoto2 --abilities
The next option will do a remote trigger, good for setup testing and maybe a document scanner setup.
gphoto2 --capture-image-and-download
Finally you need to have the camera interfacer tell the camera to start streaming video. Then you need to pipe this video from the interfacer to the Linux standard video hook ups. Whatever weird format the camera sends its video, ffmpeg can take that as input and make any conversions to what the Linux video subsystem likes to see and then write it in the loop back video device. Loop back just means you send something in and it can send that thing right back out when asked to spill its contents; helpfully this can be another process.
gphoto2 --stdout --capture-movie | \
ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video1
You can now run vlc to check the stream.
vlc v4l2:///dev/video1
If that all seem like it’s working, you’re ready to use the stream.
Finally in Discord Voice & Video settings, there should be Dummy
video device (0x0000)
which will be this camera. (I also have a USB
camera which is why /dev/video0 is taken in these examples. If you
don’t have another camera, assume /dev/video0 is the best place to
start looking.)
Offloading From DLSR
Getting sick of removing the SD card from the camera and mounting it on a proper computer every time? Use gphoto2! Obviously make sure the camera is turned on and detected.
gphoto2 --abilities # Make sure it can do what you want.
gphoto2 -L # Aka --list-files.
gphoto2 -l # Aka --list-folders.
gphoto2 -P # Aka --get-all-files.
chmod 644 IMG_*JPG # Idiotic DOS file system. Blah.
gphoto2 -r /store_00020001/DCIM/100CANON # Aka --rmdir, and this seems to be the one to clear.
This all works pretty well. Note that caja .
to look at the current
directory’s photos is pretty handy though sometimes if the files are
bigger than 10MB — which is a regular situation with a fine camera — then thumbnails are not generated unless you go to Preferences and
raise the limit.
Cheese
sudo apt-get install cheese
This program is a nice GUI client to the webcam and an easy way to test to see if it’s working properly. Also it can take still snapshots which turns your laptop with a camera into a digital camera. There are "effects" that are helpful when the camera needs to be reversed or turned upside down, etc.
The Program Called "motion"
motion
(that is its command line name) is a very excellent program
that will turn on your camera and save what it sees only if there is
something changing (if it sees "motion"). This is excellent for
security cameras. Fairly easy to use on Ubuntu.
sudo apt-get install motion
sudo vi /etc/motion/motion.conf
sudo /etc/init.d/motion start
ls /tmp/motion # Find output here.
Of course you need to set some sensible settings in the configuration
file. But it is well documented with comments and isn’t stupidly
designed. Maybe also look in /var/lib/motion/
for the output. Don’t
forget to make sure you have plenty of fast writing space to use (e.g.
not a USB drive).
Guvcview
Cheese is nice and has an easier to remember name, but guvcview is
very good about hooking up GUI controls to all of your camera’s
potential settings. Good for troubleshooting.
sudo apt install guvcview
RecordMyDesktop
The utility recordmydesktop is for making screencasts of graphical sessions on Linux systems.
To install this on Ubuntu systems:
sudo apt-get install recordmydesktop
sudo apt-get install gtk-recordmydesktop
Since I was interested in recording the full screen, I found the best way to use this program was as follows.
First I enter the command to record following a sleep
command. This
gives me a chance to kick off the thing that I really want to be on
the screen (perhaps a slide show or a game).
$ sleep 5; recordmydesktop --no-cursor --fps=5 --display=:0 \
--stop-shortcut=Control+s --s_quality=10 --output=myscreencasttest.ogv
Then before hitting enter, in another terminal (or with the previous command suitably in the background) I do this:
$ feh -FZ ~/slideshow/*png
Then before hitting enter here, I switch to the first terminal, hit enter, and then within my sleep time switch back here and hit enter and 5 seconds after starting the first command, it’s recording what I want.
Note
|
The man page seems to indicate that long options can be specified
without an = . But I’m not so sure this is correct. The = does seem
to work. |
Warning
|
Before getting too excited about recordmydesktop you should
test it out. I found that it sort of worked and perhaps would have
been fine for some kinds of demos, however, I wanted to record a slide
show at a specific irregular pace and some slides were missing and the
audio sync was generally bad using feh or eog as the viewer. |
Converting To A YouTube Acceptable Format
Use PiTiVi to "render" the ogv file into something YouTube will accept. The following settings might do the job.
Container: MP4Muxer [mp4mux]
Audio Codec: Ffmpeg ALAC (Apple lossless Audio Encoder) encoder [ffenc_alac]
Video Codec: Ffmpeg MPEG-4 part 2 encoder [ffenc_mpeg4]
Video codec bit rate: 10300000
Backing Up Stubborn DVDs
Some DVDs really piss me off. It’s important that you use a DVD player that is not so fussy about disks and will just follow your instructions to read all the 1s and 0s off the accursed disk. Here’s what you do:
ddrescue -n -b 2048 /dev/dvd output_raw.iso
dvdbackup -M -i output.iso -o dvd_structure
mkisofs -dvd-video -o clean_dvd.iso dvd_structure
Been liking acidrip
lately. Good GUI for all the complex mess.
Here’s a project that might be helpful: k9copy
EasyCap Device
Here are some old (originally from 2010-12-30) notes on how I was able to get an EasyCap USB video capture device to work on Linux. Here is a plausible Amazon link for a device with an Easycap chip.
Setting Up The Driver
The following worked for me. First get the source for the driver:
$ svn co https://syntekdriver.svn.sourceforge.net/svnroot/syntekdriver/trunk/driver syntekdriver ; cd syntekdriver
There are some dependencies to get sorted out:
$ sudo apt-get ctags
There might be another, but it’s obvious Then compile it:
$ make -f Makefile.standalone
Load the this video driver if it’s not loaded already:
$ sudo modprobe videodev
Now try loading the module you just compiled:
$ insmod stk11xx.ko
Ideally dmesg
should show something like:
[ 9309.880242] stk11xx: Syntek USB2.0 Capture device is ready
[ 9309.880353] stk11xx: Syntek USB2.0 Camera is now controlling video device /dev/video0
Using EasyCap For Video Input
Plugged a VCR’s video cable (RCA to RCA) into the yellow jack and did this:
$ mplayer tv://
Worked fine with no other parameters however someone reports success with:
mplayer tv:// -tv driver=v4l2:width=720:height=576:outfmt=uyvy:device=/dev/video0
I have also used this to do extensive capturing.
ffmpeg -f v4l2 -framerate 15 -video_size 640x480 -i /dev/video0 myfile.mp4
If your camera is upside down, you can throw in: -vf vflip,hflip
Adding Sound
The video driver works but the sound input doesn’t seem to easily. It might be registered as a different device, but I didn’t notice that and it’s definitely not integrated into the video device.
The solution was to just use the mic input and an RC to 3mm stereo male from a digital camera junk. This way, the analog video source (VCR, Wii, etc) sends video to the EasyCap, but audio goes to a more traditional audio capture and is managed in the normal way, volume controls work as normal.
Here is a suggested command approach to capture dsp as audio which might be useful when dubbing things from the analog signal (ripping VHS tapes, etc).:
$ mencoder tv:// -tv driver=v4l:width=640:height=480:device=/dev/video0:forceaudio:adevice=/dev/dsp:outfmt=uyvy:fps=30 -ovc lavc -oac mp3lame -o video.avi
PowerLead Helmet Cam
Here is the link to the helmet camera I bought in August 2017. The exact name of it according to Amazon is PowerLead Caue PL-05 Mini Sports Camera 1080P Full HD Action Waterproof Sport Helmet Bike Helmet Video Camera DVR AVI. On the box it also says "MINI F9 DVR". The manual is probably excellent if you can read Chinese. The English side left a lot to be desired. The USB manufacturer identifier according to the Linux kernel is "Polaroid Cube" and a SCSI bus message of "LeiSure SportDV" also comes up.
Features
-
Works with Linux just fine.
-
Comes with a lot of physical mounting options.
-
Takes about 2 hrs to charge. Lights go out when it’s fully charged.
-
Uses MicroSD cards. They say 4GB or greater and class 4 or greater.
-
It does seem to be mountable as a USB2.0 mass storage device.
-
It takes rough stills in 1080p(1920x1080) mode. The manual hints that it does not work in 720p but this is false; it does take 720p (1280x720) photos. Look for photos in
DCIM/100PHOTO/FILE####.JPG
. -
Video is either 1080p(1920x1080)@30fps or 720p(1280x720)@60fps. Look for videos in
DCIM/100VIDEO/FILE####.MOV
. Codec seems to beyuv420p
. -
Records sound pretty well. Audio codec seems to be: aac 2ch 1600Hz.
Usage
TL;DR: fore button=on/off, aft button=start/stop; long press=on/off/stop, short press=start.
-
Connecting to USB - The seam on the connector’s ground shield faces up, closest to the SD card. If plugged into a running computer it will be a mountable mass storage device.
-
Prepare For Video - On back panel, set bottom slider to video icon (slider left). Set top slider to mode 1080p@30 (slider left) or 720p@60 (slider right).
-
Power On - Hold fore (lens end) button 2 seconds. The lit top fore blue LED and 3 buzzes indicate success.
-
Start Video Recording - Short press of aft top button. Red LED lit and 3 buzzes indicate success, i.e. video is recording.
-
Stop Video Recording - Long press of aft top button. Blue LED stays lit, red LED goes out, and one buzz indicates success.
-
Power off - Long press of fore top button. One buzz and all LEDs out indicates success.
-
Prepare For Still Camera - On back panel, set bottom slider to camera icon (right). Set top slider to mode 1080p@30 (left) or 720p@60 (slider right).
-
Take Still Photo - Short press of aft top button in correct mode. Red LED lit briefly indicates success.
-
Volume - Strangely the volume setting was at 7 when it seems to indicate that the valid values are 0-2. Changing it seemed to have no effect.
Clock Setting
The clock is used to time stamp the files (video and photo mode) and also to display the current time on the recordings (video only). The clock needs to be set to UTC as that is assumed.
-
Mount the device itself or an SD card which has already been used in the device.
-
In the top level directory of the device, look for a file called
SportDV.txt
. -
Edit this file with something that can handle stupid DOS line endings.
-
Look for this field and change it from
N
toY
.UPDATE:N
When the camera system powers up, it will perform the update and then reset this back to
N
automatically. -
Look for the following fields and set them with the correct time a short while in the future.
year:2017 month:8 day:27 hour:13 minute:15 second:0
-
Unmount the camera, make sure it is off and wait for the time you set. At that time turn it on. Keep in mind it takes a couple of seconds of holding the power on button for it to come on. (A smart camera would know how to adjust for that; I didn’t check it.)
To completely turn off the time display embedded in the video, go
through the same procedure as for setting the clock. Edit the
SportDV.txt
file. In addition to adjusting the time components,
change the real time clock display setting, RTCDisplay
, from 1 (show
time) to 0 (don’t show time). Change UPDATE
to Y
to make changes
take effect.