linux下使用ffmpeg指令从摄像头中录取视频

Capture and stream video and audio

Now, on machine with camera, open Terminal/command prompt and run following command to start capturing video and audio and generating live stream to another computer

Windows

ffmpeg -f dshow -i video="Integrated Webcam":audio="Microphone (Realtek Audio)" -profile:v high -pix_fmt yuvj420p -level:v 4.1 -preset ultrafast -tune zerolatency -vcodec libx264 -r 10 -b:v 512k -s 640x360 -acodec aac -ac 2 -ab 32k -ar 44100 -f mpegts -flush_packets 0 udp://192.168.1.4:5000?pkt_size=1316

Linux

On linux, instead of dshow (DirectShow), we need to use 2 different drivers for video and audio:

ffmpeg -f v4l2 -i video="Integrated Webcam" -f alsa -i hw:0 -profile:v high -pix_fmt yuvj420p -level:v 4.1 -preset ultrafast -tune zerolatency -vcodec libx264 -r 10 -b:v 512k -s 640x360 -acodec aac -strict -2 -ac 2 -ab 32k -ar 44100 -f mpegts -flush_packets 0 udp://192.168.1.4:5000?pkt_size=1316

Do not forget to replace video and audio devices names and destination IP address with previously discovered values.

Options demystified

Lets reformat previous command so that we can see used options better

ffmpeg -f dshow \
-i video="Integrated Webcam":audio="Microphone (Realtek Audio)" \
-profile:v high -pix_fmt yuvj420p -level:v 4.1 -preset ultrafast -tune zerolatency \
-vcodec libx264 -r 10 -b:v 512k -s 640x360 \
-acodec aac -ac 2 -ab 32k -ar 44100 \
-f mpegts -flush_packets 0 udp://192.168.1.4:5000?pkt_size=1316
  • -f fshow - windows system drivers for capturing video and audio
  • -f v4l2 - linux system drivers for capturing video
  • -f alsa - linux system drivers for capturing audio
  • -i - ffmpeg option that defines input
  • -vcodec libx264 - raw video from camera will be encoded using H264 video codec
  • -r 10 - video FPS (frames per second)
  • -b:v 512k - video bitrate Kb/s (kilo bits per second)
  • -s 640x360 - video width and height
  • -acodec aac - raw audio from microphone will be encoded using AAC audio codec
  • -ac 2 - 2 audio channels (stereo)
  • -ab 32k - audio bitrate in Kb/s
  • -ar 44100 - audio sampling rate 44.1 KHz
  • -f mpegts - video and audio will be packed into MPEG transport stream (MPEG TS)
  • udp://192.168.1.4:5000 - MPEG transport stream is sent via UDP protocol to computer with IP address 192.168.1.4 on IP port 5000.

Play camera stream

Windows/Linux

On destination computer stream can be watched using VLC player

  • go to menu Media->Open Network Stream...
  • in URL field type udp://@0.0.0.0:5000 and press Play

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值