Skip to main content

FFmpeg

Stream live 1080p @ 30fps video to YouTube

FFmpeg tool can be used to stream live video to youtube, recipe command is below. Also add silent audio with proper encoding.

ffmpeg -re \
-f v4l2 \
-framerate 30 \
-video_size 1920x1080 \
-i /dev/video1 \
-ar 44100 \
-ac 2 \
-acodec pcm_s16le \
-f s16le \
-ac 2 \
-i /dev/zero \
-codec:a aac \
-ab 64k \
-strict experimental \
-vcodec copy \
-pix_fmt yuv420p \
-f flv "rtmp://a.rtmp.youtube.com/live2/[STREAM_ID]"

YouTube studio preview

youtube_stream.png

Record h.264 stream in Windows

List connected devices ffmpeg -hide_banner -list_devices true -f dshow -i dummy

[dshow @ 03e80ee0] DirectShow video devices (some may be both video and audio devices)
[dshow @ 03e80ee0]  "C2 RVN-3Q4WH"
[dshow @ 03e80ee0]     Alternative name "@device_pnp_\\?\usb#vid_16d0&pid_0ed4&mi_00#9&216b562&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
[dshow @ 03e80ee0] DirectShow audio devices
[dshow @ 03e80ee0]  "Input (M-Track)"
[dshow @ 03e80ee0]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{B212B620-6CA9-46A0-ACB6-F7379A77ADCC}"
[dshow @ 03e80ee0]  "Microphone (C2)"
[dshow @ 03e80ee0]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{65AA28A6-DECF-4DE1-9116-8D4F8B360AC2}"
dummy: Immediate exit requested

Check device compression options ffmpeg -hide_banner -f dshow -list_options true -i video="C2 RVN-3Q4WH"

Do not forget to replace camera name.

[dshow @ 001a0f00] DirectShow video device options (from video devices)
[dshow @ 001a0f00]  Pin "Capture" (alternative pin name "0")
[dshow @ 001a0f00]   vcodec=mjpeg  min s=1920x1080 fps=15 max s=1920x1080 fps=30
[dshow @ 001a0f00]   vcodec=mjpeg  min s=1920x1080 fps=15 max s=1920x1080 fps=30
[dshow @ 001a0f00]   vcodec=mjpeg  min s=1280x1024 fps=15 max s=1280x1024 fps=30
[dshow @ 001a0f00]   vcodec=mjpeg  min s=1280x1024 fps=15 max s=1280x1024 fps=30
[dshow @ 001a0f00]   vcodec=mjpeg  min s=1280x720 fps=15 max s=1280x720 fps=30
[dshow @ 001a0f00]   vcodec=mjpeg  min s=1280x720 fps=15 max s=1280x720 fps=30
[dshow @ 001a0f00]   vcodec=mjpeg  min s=720x576 fps=5 max s=720x576 fps=30
[dshow @ 001a0f00]   vcodec=mjpeg  min s=720x576 fps=5 max s=720x576 fps=30
[dshow @ 001a0f00]   vcodec=mjpeg  min s=720x480 fps=5 max s=720x480 fps=30
[dshow @ 001a0f00]   vcodec=mjpeg  min s=720x480 fps=5 max s=720x480 fps=30
[dshow @ 001a0f00]   vcodec=mjpeg  min s=640x480 fps=15 max s=640x480 fps=30
[dshow @ 001a0f00]   vcodec=mjpeg  min s=640x480 fps=15 max s=640x480 fps=30
[dshow @ 001a0f00]   vcodec=mjpeg  min s=1920x1080 fps=15 max s=1920x1080 fps=30
[dshow @ 001a0f00]   vcodec=mjpeg  min s=1920x1080 fps=15 max s=1920x1080 fps=30
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=1920x1080 fps=5 max s=1920x1080 fps=5
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=1920x1080 fps=5 max s=1920x1080 fps=5
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=1280x1024 fps=5 max s=1280x1024 fps=5
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=1280x1024 fps=5 max s=1280x1024 fps=5
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=1280x720 fps=5 max s=1280x720 fps=10
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=1280x720 fps=5 max s=1280x720 fps=10
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=800x600 fps=5 max s=800x600 fps=10
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=800x600 fps=5 max s=800x600 fps=10
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=720x576 fps=5 max s=720x576 fps=10
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=720x576 fps=5 max s=720x576 fps=10
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=720x480 fps=5 max s=720x480 fps=20
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=720x480 fps=5 max s=720x480 fps=20
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=640x480 fps=5 max s=640x480 fps=30
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=640x480 fps=5 max s=640x480 fps=30
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=1920x1080 fps=5 max s=1920x1080 fps=5
[dshow @ 001a0f00]   pixel_format=yuyv422  min s=1920x1080 fps=5 max s=1920x1080 fps=5
[dshow @ 001a0f00]  Pin "Capture" (alternative pin name "1")
[dshow @ 001a0f00]   vcodec=h264  min s=1920x1080 fps=5 max s=1920x1080 fps=30
[dshow @ 001a0f00]   vcodec=h264  min s=1920x1080 fps=5 max s=1920x1080 fps=30
[dshow @ 001a0f00]   vcodec=h264  min s=1280x1024 fps=5 max s=1280x1024 fps=30
[dshow @ 001a0f00]   vcodec=h264  min s=1280x1024 fps=5 max s=1280x1024 fps=30
[dshow @ 001a0f00]   vcodec=h264  min s=1280x720 fps=5 max s=1280x720 fps=30
[dshow @ 001a0f00]   vcodec=h264  min s=1280x720 fps=5 max s=1280x720 fps=30
[dshow @ 001a0f00]   vcodec=h264  min s=720x576 fps=5 max s=720x576 fps=30
[dshow @ 001a0f00]   vcodec=h264  min s=720x576 fps=5 max s=720x576 fps=30
[dshow @ 001a0f00]   vcodec=h264  min s=720x480 fps=5 max s=720x480 fps=30
[dshow @ 001a0f00]   vcodec=h264  min s=720x480 fps=5 max s=720x480 fps=30
[dshow @ 001a0f00]   vcodec=h264  min s=640x480 fps=5 max s=640x480 fps=30
[dshow @ 001a0f00]   vcodec=h264  min s=640x480 fps=5 max s=640x480 fps=30
[dshow @ 001a0f00]   vcodec=h264  min s=1920x1080 fps=5 max s=1920x1080 fps=30
[dshow @ 001a0f00]   vcodec=h264  min s=1920x1080 fps=5 max s=1920x1080 fps=30
video=C2 RVN-3Q4WH: Immediate exit requested

Record h.264 compressed video directly from the camera ffmpeg -hide_banner -f dshow -s 1920x1080 -r 30 -vcodec h264 -i video="C2 RVN-3Q4WH" output.mp4

Input #0, dshow, from 'video=C2 RVN-3Q4WH':
  Duration: N/A, start: 3447069.727000, bitrate: N/A
    Stream #0:0: Video: h264 (Main) (H264 / 0x34363248), yuv420p, 1920x1080, 30 fps, 30 tbr, 10000k tbn, 20000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 06507020] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 06507020] profile High, level 4.0
[libx264 @ 06507020] 264 - core 152 r2851 ba24899 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=34 lookahead_threads=5 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf57.71.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1920x1080, q=-1--1, 30 fps, 15360 tbn, 30 tbc
    Metadata:
      encoder         : Lavc57.89.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=  121 fps= 27 q=-1.0 Lsize=     973kB time=00:00:03.93 bitrate=2026.3kbits/s speed=0.871x

### PRess CTRL + X to stop recording

video:971kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.226249%
[libx264 @ 06507020] frame I:1     Avg QP:17.49  size: 43500
[libx264 @ 06507020] frame P:36    Avg QP:21.70  size: 15985
[libx264 @ 06507020] frame B:84    Avg QP:23.32  size:  4457
[libx264 @ 06507020] consecutive B-frames:  7.4%  0.0%  0.0% 92.6%
[libx264 @ 06507020] mb I  I16..4: 46.6% 47.6%  5.8%
[libx264 @ 06507020] mb P  I16..4:  3.3%  1.4%  0.0%  P16..4: 50.3%  3.0%  5.3%  0.0%  0.0%    skip:36.6%
[libx264 @ 06507020] mb B  I16..4:  0.1%  0.0%  0.0%  B16..8: 25.5%  0.1%  0.0%  direct: 5.3%  skip:68.9%  L0:42.0% L1:57.8% BI: 0.2%
[libx264 @ 06507020] 8x8 transform intra:34.9% inter:90.6%
[libx264 @ 06507020] coded y,uvDC,uvAC intra: 23.5% 56.0% 10.3% inter: 4.6% 27.7% 0.6%
[libx264 @ 06507020] i16 v,h,dc,p: 22% 19% 12% 47%
[libx264 @ 06507020] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 19% 42%  2%  3%  3%  3%  3%  3%
[libx264 @ 06507020] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 30% 18%  5%  4%  3%  5%  2%  6%
[libx264 @ 06507020] i8c dc,h,v,p: 55% 20% 19%  6%
[libx264 @ 06507020] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 06507020] ref P L0: 59.4%  3.3% 25.4% 11.9%
[libx264 @ 06507020] ref B L0: 87.0%  9.8%  3.3%
[libx264 @ 06507020] ref B L1: 93.7%  6.3%
[libx264 @ 06507020] kb/s:1970.28
Exiting normally, received signal 2.