# ffmpeg x11grab and v4l2-ctl



## cytopia (Dec 19, 2015)

Hi everybody,

I am trying to port https://github.com/cytopia/ffscreencast over to FreeBSD.

As I am kind of a newbie to FreeBSD on a desktop I am looking for some FreeBSD equivalents to the following Linux tools.

* ffmpeg with x11grab to capture the desktop
* v4l2-ctl to list all attached camera devices
* arecord to list all sound devices
* xdpyinfo to list all connected monitors

Maybe some tools like xdpyinfo are available on FreeBSD anyway, but I am also looking for the best native solutions that can do the above jobs.

Could you guys and girls provide me with some input here.

Thank you


----------



## scottro (Dec 19, 2015)

https://forums.freebsd.org/threads/screencasting-with-ffmpeg-tutorial.23826/  talks about x11grab, so I'm assuming it's there.  

https://www.freebsd.org/doc/handbook/sound-setup.html  talks about sound, including the command `cat /dev/sndstat`

I don't know how much you've searched on your own, but much of this may be easy to find.


----------



## cytopia (Dec 19, 2015)

From your first link I see they include sound like this
`ffmpeg -f oss -i /dev/dsp0.0`

Unfortunately I do not have any /dev/dsp* devices. dev/sndstat however seems to recognize list my sound cards.


```
$ cat /dev/sndstat
Installed devices:
pcm0: <NVIDIA GT21x (HDMI/DP 8ch)> (play)
pcm1: <NVIDIA GT21x (HDMI/DP 8ch)> (play)
pcm2: <NVIDIA GT21x (HDMI/DP 8ch)> (play)
pcm3: <NVIDIA GT21x (HDMI/DP 8ch)> (play)
pcm4: <Realtek ALC889 (Rear Analog 7.1/2.0)> (play/rec) default
pcm5: <Realtek ALC889 (Front Analog)> (play/rec)
pcm6: <Realtek ALC889 (Rear Digital)> (play)
pcm7: <Realtek ALC889 (Onboard Digital)> (play)
```


----------



## scottro (Dec 19, 2015)

Yeah, that throws people off.  If you look further down it mentions that /dev/dsp doesn't get created till it's used.   In other words, you won't see a /dev/dsp anything, but if you then cat anything to it (doesn't even have to be an audio file) you will see that it's appeared.   There's an old post of mine on these forums somewhere asking about that, where someone explained it to me.


----------



## protocelt (Dec 19, 2015)

cytopia said:


> Hi everybody,
> 
> I am trying to port https://github.com/cytopia/ffscreencast over to FreeBSD.
> 
> ...


The following ports should cover your list of requirements:

multimedia/ffmpeg
x11/xgrab
multimedia/libv4l
multimedia/v4l-utils
x11/xdpyinfo
To get a listing of all the available sound devices on the system, as you've already done, you can run `cat /dev/sndstat`.

scottro is correct. The /dev/dsp* device nodes are created by the kernel on demand the when a sound device is accessed. Until then, they won't exist. The device nodes will persist until the system is rebooted in which case there will be no existing device nodes again until a sound device is accessed.


----------



## cytopia (Dec 19, 2015)

Thanks for the list that covers all sofware.

There is still one question remaining with the appropriate sound recording device:


```
$ cat /dev/sndstat | grep '(play/rec)'
pcm4: <Realtek ALC889 (Rear Analog 7.1/2.0)> (play/rec) default
pcm5: <Realtek ALC889 (Front Analog)> (play/rec)
```

Now how do I know to which dsp device pcm4 and pcm5 belong?


----------



## protocelt (Dec 19, 2015)

Your output lists pcm4 as the rear analog sound device and pcm5 as the front analog sound device with the rear analog device as the default device. So the sound card ports on the back of the computer are for the rear analog(default) device or pcm4, and the sound ports in the front(sometimes top depending on the computer's case design) are for the the front analog sound device or pcm5.

Oops! I read your post wrong. Sorry about that. The dsp* device nodes start with a numbering of 0 as do the corresponding pcm* devices.


----------



## cytopia (Dec 19, 2015)

So that means that pcm*X* will always be /dev/dsp*X*.0 or /dev/dsp0.*X*?
And what is the difference between dsp0.0 and dsp0.*1* or dsp*1*.0 or dsp*1*.*1*?


----------



## scottro (Dec 19, 2015)

By the way (I just happened to notice this while upgrading multimedia/ffmepg the screen grab is an option--I'm not sure if it's off or on by default.  You may want to look through the options.  For example, libass support is off by default, not sure about libx264 and libx265. (I was looking at a config file that I made some time ago, so I'm not sure what the original defaults were.)

Depending upon your needs, the defaults may be fine, but you might want to be sure that nothing you need  is off by default.  To check, you can just cd into /usr/ports/multimedia/ffmpeg and type `make config`.  That opens up a curses based dialog, where you can see what is included. 

(You might know all of this already, in which case, I apologize for wasting your time, but I do remember, for example, being somewhat annoyed when when I need to burn subtitles into something and getting the error subtitles: no such filter, or similar.)


----------



## protocelt (Dec 19, 2015)

cytopia said:


> So that means that pcm*X* will always be /dev/dsp*X*.0 or /dev/dsp0.*X*?


pcm%n = dsp%n.v% where %n is the device number and %v is a virtual channel.


cytopia said:


> And what is the difference between dsp0.0 and dsp0.*1* or dsp*1*.0 or dsp*1*.*1*?


FreeBSD's sound system includes in-kernel virtual mixing support for sound devices. Some higher end sound cards do this in the hardware but most lower end consumer sound cards and onboard audio do not. This allows a device to input and output from multiple sources at the same time. If your familiar with Linux, it's similar to what dmix does for ALSA sound devices or more recently PulseAudio.

Say for example you have a sound device. We'll label it pcm0. The corresponding dsp device would then be dsp0.0 which would be created when the device is accessed for the first time after the system starts. Let's now say your playing a music file, but you want to also play a video in another program at the same time that would output sound to the same(default) device. Once the program you open to play video accesses the sound card dsp0.1 will be created. Each time a new sound source accesses the sound card a new virtual channel will be created. This is automatically handled by the kernel so any sound source only needs to point to dsp0 as the virtual channels will be handled automatically. This also prevents the sound device from being locked to one input or output source at a time.


----------



## cytopia (Dec 19, 2015)

Sounds well-thought in FreeBSD. Thanks for the help everybody.


----------



## scottro (Dec 19, 2015)

One other thing I'll mention, though I have no idea if it  will be important to you.   Casual tests show that Linux re-encodes a bit faster than FreeBD  As I said, these were casual, along the lines of l
`ffmpeg -i myfile.mp4 -c:v  libx265 out.mp4`.  Doing that (making an x264 file into x265, which drastically decreases the size, took about 5 minutes longer in FreeBSD for a file of about 265 MB and 24 minutes runtime.   However, FreeBSD did a better job of decreasing size, though not drastically, say, 99 MB for FreeBSD vs. 111 MB for Linux.  The output indicated that Linux was doing more fps, say, 30-35 vs. FreeBSD's 20-25

I mention this in case it matters, though from your description of what you are planning, it's probably irrelevant.


----------



## cytopia (Dec 19, 2015)

Definitely not irrelevant. I am always looking for information regarding ffmpeg to make the final command as performant as possible. This is specifically the case once sound and/or camera are included.


----------



## cytopia (Dec 20, 2015)

I have just seen that v4l2-ctl has been removed from multimedia/v4l-utils: https://forums.freebsd.org/threads/v4l-utils-missing-v4l2-ctl.52038/

Is there any other possibility to get camera information on FreeBSD


----------



## User7 (Dec 20, 2015)

> ffmpeg with x11grab to capture the desktop



I recommend /multimedia/vlc Very usefull tools. But sometimes lagging.


----------



## cytopia (Dec 20, 2015)

User7 I am intending to port ffscreencast over to FreeBSD. Please read first post


----------



## scottro (Dec 20, 2015)

I don't want to waste your time with guesses, but using the program ports-mgmt/psearch  and running `psearch webcam` brings up a few responses, including multimedia/pwcbsd and multimedia/pwcview.  If you look  at their respective pkg-plist and Makefiles, does it suggest anything useful?  (I should point out that I'm not a programmer, but assume as these work with webcams, I'm guessing, or at least hoping, that they may be able to get you information on an existing webcam)


----------



## rabfulton (Dec 21, 2015)

cytopia said:


> Hi everybody,
> 
> I am trying to port https://github.com/cytopia/ffscreencast over to FreeBSD.
> 
> ...



This website may be of use to you:

http://www.rockafunk.org/


----------



## cytopia (Dec 21, 2015)

Thanks so far for all the input.

I guess this will be a longer ongoing progress.
I had to do some major code rewriting, so I can get FreeBSD support in step by step.

I will do screenrecording with sound first and once thats stable continue with the camera overlay


----------

