Wednesday, April 17, 2013

Using avconv (previously ffmpeg) to record the desktop

So I was trying to figure out how to record a video of the screen. I didn't have much use for recording the microphone though. All the instructions I could find would always describe how to record a video using the microphone for audio. Here's that command for that just in case that's what you are wanting:

avconv -f alsa -i hw:0,0 -f x11grab -s 1600x900 -r 25 -i :0.0 -vcodec libx264 -acodec libmp3lame vid_file.mp4

Of course, since I didn't need microphone and I actually wanted the program's audio output, that command didn't work for me. I tried many different variations on the alsa device (hw:0,0) to no avail. Finally I found the answer somewhere was to change from using alsa to pulse, then directing to the device, eventually coming up with the command:

avconv -f pulse -i alsa_output.pci-0000_00_1b.0.analog-stereo.monitor -f x11grab -s 1600x900 -r 25 -i :2.0 -vcodec libx264 -acodec libmp3lame vid_file.mp4

The pulse device name (mine is shown as alsa_output.pci-0000_00_1b.0.analog-stereo.monitor) can by found with the command:

pactl list sources|less

Listed next to "Name:"

I'd also like to break down the command I used as best I can because nothing else I found explained much about what was going on or how the command worked and/or could be changed.
avconv is the name of the program
I believe -f is to add a new stream to the video/file so,
-f alsa/pulse
adds a new audio stream, then -i designates a device.
-f alsa -i hw:0,0 
then adds alsa device hw:0,0.

then we use -f to add a video stream(no sound) with:
-f x11grab
-s for size which on my laptop is 1600x900.
-r I believe is the framerate.
-i then adds the device/display in this instance. Almost all the examples I saw used the display :0.0, after playing with it a bit I found that on my laptop it needed to be changed and was actually :2.0

so far we have:
avconv -f alsa -i hw:0,0 -f x11grab -s 1600x900 -r 25 -i :2.0
That takes care of where we get the input.
The rest of it is the output
-vcodec libx264 tells it to use x264 as the video codec (on of the most common and is used for mp4 files)
-acodec libmp3lame tells it to use mp3 encoding for the audio
vid_file.mp4 is the filename. (The extension tells it to save in an mp4 container)

1 comment: