GitHub 源码地址:
https://github.com/rockchip-linux/ffmpeg
安装依赖:sudo apt-get install yasm libx264-dev
解压源码进入目录编译
./configure --prefix=/usr/local/ffmpeg-2.3.6/ --enable-shared --disable-static --enable-gpl --enable-libx264
sudo make clean && make && sudo make install
添加 ffmpeg 库的链接 sudo vi /etc/ld.so.conf,在最后添加一行: /usr/local/ffmpeg/lib,保存退出后 sudo ldconfig
添加 bin 路径sudo vi /etc/profile,找到export行,在下面一行添加export PATH=/usr/local/ffmpeg/bin/:$PATH
保存后执行 source /etc/profile
调用本地摄像头录视频命令
ffmpeg -s 640x480 -i /dev/video0 -vcodec libx264 -b:v 400K -r 15 out.mp4
注意:如果是ffmpeg-2.3.6比较老的版本 ffmpeg -f v4l2 -s 640x480 -i /dev/video0 -vcodec libx264 -b:v 400K -r 15 out.mp4
另一种方式
=================================================================
ffmpeg -f v4l2 -video_size 1280x720 -framerate 25 -i /dev/video0 -vcodec libx264 -b:v 400K out.mp4
=================================================================
-t 10 录制 10 秒
-s 640x480 设定分辨率
-r 30 设定帧率
-b:v 设定视频比特率
-vcodec libx264 设定视频编码器
https://trac.ffmpeg.org/wiki/Capture/Webcam
https://ffmpeg.org/ffmpeg-all.html#video4linux2_002c-v4l2
$ v4l2-ctl --all
Driver Info (not using libv4l2):
Driver name : uvcvideo
Card type : P500S: P500S
Bus info : usb-0000:03:00.0-4.1
Driver version: 5.3.18
Capabilities : 0x84A00001
Video Capture
Metadata Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04200001
Video Capture
Streaming
Extended Pix Format
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
Width/Height : 640/480
Pixel Format : 'YUYV'
Field : None
Bytes per Line : 1280
Size Image : 614400
Colorspace : sRGB
Transfer Function : Default (maps to sRGB)
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 640, Height 480
Default : Left 0, Top 0, Width 640, Height 480
Pixel Aspect: 1/1
Selection: crop_default, Left 0, Top 0, Width 640, Height 480
Selection: crop_bounds, Left 0, Top 0, Width 640, Height 480
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 30.000 (30/1)
Read buffers : 0
brightness 0x00980900 (int) : min=-255 max=255 step=1 default=0 value=0
contrast 0x00980901 (int) : min=0 max=255 step=1 default=40 value=40
saturation 0x00980902 (int) : min=0 max=255 step=1 default=64 value=64
hue 0x00980903 (int) : min=-255 max=255 step=1 default=0 value=0
To list available formats (supported pixel formats, video formats, and frame sizes) for a particular input device:
$ ffmpeg -f v4l2 -list_formats all -i /dev/video0
[video4linux2,v4l2 @ 0x5587af1d1960] Compressed: mjpeg : Motion-JPEG : 2048x1536 2592x1944 1920x1080 1600x1200 640x480
[video4linux2,v4l2 @ 0x5587af1d1960] Raw : yuyv422 : YUYV 4:2:2 : 2048x1536 2592x1944 1280x1024 1600x1200 640x480
Example to encode video from /dev/video0:
$ ffmpeg -t 10 -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0 output.mkv