vlc can do the recording and conversion directly if given the proper command line options (that however is not trivial but reasonably well documented).
Also there is the library libvlc that you can use to do anything that vlc does; I only used it for playback but I suppose that capturing and saving to file should be not too difficult.
You didn't tell your platform, but both vlc and libvlc are windows/linux/osx and so that shouldn't be a big problem.
This is for example a vlc command line I use to start recording from my webcam
vlc v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=320 :v4l2-height=240
--sout "#transcode{vcodec=x264,acodec=mpga,vb=800,ab=128}
:standard{access=file,dst=capture.avi}"