Work path for Mac Screen recording with VLC  screen recording per command line to a Social Platform via FFmpeg. The task: I’m looking for is to capture the screen with VLC Command line and stream the result with FFmpeg as video RTSP live stream to Facebook youtube or any other Platform without the need of additional expensive or complicated software. Some Examples can be found for Linux but not so much for MAC, it should work for El Capitan. This is mostly a work log . Here I will document what worked for me and what problems occur. Later on allow those snippets to create a bash script to auto stream on an interval to facebook for example a Birdsnest, Weather camera, or any IPTV Camera . Even some simple  Video Effect Switcher like CAmTwist can be used to stream and manage video sources for the Facebook Lifestream.

The idea behind is that sometimes you need to stream some short piece of video where a full Stream software like Wirecast or OBS is an Overkill . One core reason Live stream is very CPU process intensive the less additional software you run the more you have to process and stream your Video.It makes streaming with the desktop so simple once the procedure is ready.

Video Screen Recording on mac

Full-Screen Recording as Mp4

vlc screen:// -I rc --screen-fps 25 ":sout=#transcode{vcodec=h264}:std{access=file,dst=metaoutput.mp4"}

With Cropped Mac Screen Video Capture

We use a minimum screen-top of 50 to hide the chromee browserr navigation and some mac offset
vlc screen:// -I rc --screen-fps 25 --screen-index 1 --screen-width 500 --screen-height 500 --screen-top 50 --screen-left 0  ":sout=#transcode{vcodec=h264}:std{access=file,dst=metaCropout3.mp4"}

This will add the Recording into the virtual playlist Que of our VLC CLI , to start capturing we need the command play  and quit to stop the stream .

VLC CLI Parameter

To limit the area being captured we add parameter to the screen
Video crop (right,left,top,bottom) Number of pixels to crop at the right of the video.

--screen-index 1 --screen-width 500 --screen-height 500 --screen-top 95 --screen-left 0
One example we will capture a screen at 25 fps – cropping 500 x 500 the top, left ZERO , a window at the top left of our screen where we can place what we whant to show without the Chrome & mac window boarders.
The output video is encoded into mp4 video as file “metaout.mp4” into the same dir you CD in the Terminal .

vlc screen:// -I rc --screen-fps 25 --screen-index 1 --screen-width 500 --screen-height 500 --screen-top 95 --screen-left 0 ":sout=#transcode{vcodec=h264}:std{access=file,dst=metaout.mp4"}

FFMpeg live Stream to Facebook Live with Terminal

Here are some snippets to live stream your previous screen recording to Facebook .

FFmpeg Stream to Facebook Live


ffmpeg -re -i metaout.mp4 -acodec libmp3lame -ar 44100 -b:a 128k -pix_fmt yuv420p -profile:v baseline -s 426x240 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -vcodec libx264 -preset veryfast -g 30 -r 30 -f flv "rtmp://rtmp-api.facebook.com:80/rtmp/XXXXXXXXXX?ds=1&s_l=1&a=XXXXXXXXXXXX"

Lets change the Input source we would like to stream the desktop instead for that we use the little Free Tool called Camtwist
Avfoundation show us all available input sources
OSX ffmpeg -f avfoundation -list_devices true -i ""
WIN ffmpeg -y -f vfwcap -i list

This example will produce framerate not supported
ffmpeg -f avfoundation -i "CamTwist" ffmpegout.mpg

Facebook Life Stream from Camtwist (experimental )
ffmpeg -f avfoundation -r 30 -i "CamTwist" -pix_fmt yuv420p -profile:v baseline -s 320x240 -bufsize 2048k -vb 400k -maxrate 800k -deinterlace -vcodec libx264 -x264opts "keyint=48:min-keyint=48:no-scenecut" -preset ultrafast -r 30 -f flv "rtmp://rtmp-api.facebook.com:80/rtmp/11111111111111111=1&a=2222222222222222"
-f avfoundation -r 30 -i “CamTwist”     Input source the CamTwist Virtual Camera must fit . 

-pix_fmt yuv420p            Pixel Format of the input source this will fall back if not suported

-profile:v baseline -s 320×240 -bufsize 2048k -vb 400k -maxrate 800k -deinterlace     We chose a Low Profile and smal size for testing 320×240 Set this in ther Camtwist settings 

-vcodec libx264      Video Codec 

-x264opts “keyint=48:min-keyint=48:no-scenecut”     Producer Keyframes every 2 second  g- ist not related for RTMP

 

Looping FFmpeg Stream for Facebook Live
for streams like the endless stream option we would like to use this case
ffmpeg -re -stream_loop -1 -i metaout.mp4 -acodec libmp3lame -ar 44100 -b:a 128k -pix_fmt yuv420p -profile:v baseline -s 426x240 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -vcodec libx264 -preset veryfast -g 30 -r 30 -f flv "rtmp://rtmp-api.facebook.com:80/rtmp/XXXXXXXX?ds=1&s_l=1&a=XXXXXXXXXXXX"

Optional Loop many Videos Files to Facebook like a Set of Timeline Videos

VLC Mixing Audio and Silent Video
Now we add a Audio source in this case a test.mp3 to our silent metaout.mp4 video , outputing the result to the GUI Player with macosx important is the -noaudio parameter it will abort if not present ,defining Audio codec acodec=mp3 with the audio specs we like.

vlc -vvv -I macosx metaout.mp4 --noaudio --input-slave=test.mp3 --audio-track=1 --sout="#transcode{vcodec=mp4v,vb=800,acodec=mp3,ab=128,channels=2,samplerate=44100}:duplicate{dst=display}"

Same just save the final new mixed File we use h264 codec

vlc -vvv -I macosx test2.mp4 --noaudio --input-slave=test.mp3 --audio-track=1 --sout="#transcode{vcodec=h264,vb=1024,acodec=mp3,ab=128,channels=2,samplerate=44100}:duplicate{dst=std{access=file,mux=mp4,dst="test1outsound.mp4"},dst=display}"

Useful VLC CLI commands:

Build Alias for VLC Command to bash

echo "alias vlc='/Applications/VLC.app/Contents/MacOS/VLC -I rc'" >> ~/.bash_profile

Restart Terminal after execution

Enable Logging

Log in same Folder the log file vlc-META.log

vlc --extraintf=logger --verbose=2 --logfile=vlc-META.log --logmode=text --file-logging
or
vlc -I http --extraintf logger --log-verbose=2 --verbose-objects=+all -vvv --fullscreen

Where is the log file ? Mac will name the file vlc-log.txt and place your logfile in USERS/YOURMAC/Library/logs/vlc-log.txt

VLC Stream Audio Input on Mac list the devices

Usage: qtsound://"Built-In Input" or qtsound://"iMic USB audio system"
vlc -vvv qtsound:// 

vlc -vvv qtsound://”AppleHDAEngineInput:8,0,1,0:1″

For windows


vlc dshow:// :dshow-vdev="None" :dshow-adev="Your Audio-Device"  
 Open a VLC telnet connection :

vlc -I telnet -vvv --telnet-password password --telnet-host 198.168.0.x:4212

Play a Youtube Video
vlc --preferred-resolution 720 https://www.youtube.com/watch?v=m2Oo4kBHBNU
Qualitys preferred-resolution :
-1 : default,best available
1080 :Full HD: 1080p
720 :HD: 720p
576 :SD 576 or 480 lines
360 :Low: 360 lines)
240 :Very Low: 240 lines

VLC Streaming How To Final to Facebook

We Learned how to Capture with VLC , we tested how to Stream with FFmpeg to Facebook . Now lets make the final step the super easy just one tool fast stream my desktop version .

VLC Streams a File to our Fanpage

vlc metaout.mp4 --sout '#transcode{vcodec=h264,vb=300,fps=25,scale=1,acodec=mp4a,ab=64,channels=2}:std{access=rtmp,mux=ffmpeg{mux=flv},dst=rtmp://rtmp-api.facebook.com:80/rtmp/XXXXXXXXXXXX=1&s_l=XXXXXXXXXXX}'

Now Streaming our Desctop like described above this example is full Desctop
vlc -I rc screen:// --sout '#transcode{vcodec=h264,vb=300,fps=25,scale=1,acodec=mp4a,ab=64,channels=2}:std{access=rtmp,mux=ffmpeg{mux=flv},dst=rtmp://rtmp-api.facebook.com:80/rtmp/XXXXXXXXXXXXXXX?ds=1&s_l=1&XXXXXXXXXXXXXXXXX}'

 

Still need Sound added to the VLC Recording here Some Experimental Snippet

vlc -vvv -I rc screen:// --input-slave qtsound://AppleHDAEngineInput:1B,0,1,0:1 --sout '#transcode{vcodec=h264,vb=1024,fps=25,scale=2,acodec=mp4a,ab=44,channels=1}:std{access=rtmp,mux=ffmpeg{mux=flv},dst=rtmp://rtmp-api.facebook.com:80/rtmp/XXXXXXXXXXXXX&s_l=1&a=XXXXXXXXXXXXXX}'

Facebook Stream FAQ

Can we have multiple live streams on one page ?  yes, its possible if you don’t terminate them you can even continue with the same key on the stream.

Can we interrupt a Livestream and continue later on ? Yes that’s possible as the last test show in the Video overview the Videos stay Live even if there is no more stream (probably a bug or concept for future functions)

Should we stream over Wifi or Lan ?  It’s all time better to stream over Lan as on wifi you will generate more packet errors in your stream

What is the lowest Frame rate we can stream to Facebook ?  FB recommend 30 Frames (for US NTSC ) 25 Frames is standard in Europe PAL Norm . For lower Frame Rates we need some more experiments. It reduce your bandwidth usage and left space for quality. Facebook Live Event log will complain if Framerate drops below 16 frames , but still stream

How to find coordinates of screen in Mac OS X and crop position to Capture ? Press CTR SHIFT 4 to pixel exact position and Screen capture size for the VLC crop settings. It’s the same shortcut you use for a single screen capture to disk. The Crosshair shows the pixel position and window size

How long is the delay to the Livestream ?

How long is the live stream Key Valid ? ? ?

Record Periscope Livestream with FFMpeg

ffmpeg -i HLS_URL out.mp4

Control the VLC from the Command Line.

After we executed the command line we can start and stop the recording from the CLI with play and quit . The command stop would not work as expected as the stream can’t be continued . To see the Playlist Elements you can use playlist there shoud be your cli command visible .

playlist  : to get the playlist position

start

help

vlc -l  Use --list or --list-verbose to list available modules.
vlc -p [module_name] --advanced  display help for each module

Mac Terminal Commands

Show which processes are listening to which ports Sockets
lsof -i | grep LISTEN

VLC Terminal Errors to clear out

the Lua interface gave us some errors when we start Screen capturing and when we quite the process but it don’t affect our recording , probably the CLI and HTTP interface don’t work together as they should , so we don’t see our CLI executed commands on the web interface . We can live with that for now.

[http] core interface error: socket bind error: Permission denied  

vlc is trying to use is always 8080, if you have something other running it will result in a error .Dosent matter what port you define for VLC

[http] lua interface error: Error loading script /Applications/VLC.app/Contents/MacOS/share/lua/intf/http.luac

intf/http.lua:336: Failed to create HTTP host

MODUL Error

Main Error Es_out_set_ Group Pcr Is Called Too Late  

Facebook Event Log Error

Some events logged  , so we need to add keyframes and a stable frame rate .

Too low video key frame rate 0.038965

Too low video frame rate 5.844763

VLC CLI Parameter 

-I macosx  Output Preview in the GUI Player
--http-password <your password here

-vvv  "Verbose verbose verbose". Verbose output

VLC CLI Parameter for FFMepg

--input-slave qtsound    add sound to the stream 
--input-slave timecode:// --timecode-fps 30/1001

vb  option  to set  transcoded video stream, in kbit/s

ab  option  to set  transcoded Audio stream, in kbit/s

scale   ratio from which the video should be rescaled while being transcoded ,to reduce stream Bandwith

keyint=<number of frames>

mux encapsulation method used to send the stream

hurry-up  allow the encoder to decrease the quality if processor can’t handle 

dst    location where the video streams should be sent

VBR Mode x264 Does a better job at keeping the media around the desired bitrate takes longer encoding time x264 –pass 1 –bitrate 1500 -o <output> <input>  # ABR Mode   x264 –pass 2 –bitrate 1500 -o <output> <input>  # VBR Mode This is called 2-pass mode, not VBR mode. ABR is a form of VBR.
VLC Streaming to Chromecast Only for Windows Version VLC 3.0

References and additional resources & Developer 

VLC CLI command wiki 
Joergens Blog Livecasting 

GoPro Live streaming Hero3 Hero4 with VLC

Wowza Ffmpeg  Examples

VLC Forum 

VLC RTSP Streaming

Streaming How To 

VLM How To

Advanced Streaming Parameter VLC FFmpeg

VLC GIT Important changes New CLI commands and more OSXMAc related

Additional Extras 

CefWithSyphon  Chrome Browser with Syphon Interface , capturing web content GIT

Screengif GIT
CTstreamOutput  XCode Projekt for Camtwist to stream directly with FFmpeg (not tested compiled)

VLC Streaming Windows related

As an Input source we can use on Windows vlc dshow://    what is equivalent Direct Show input

Detect all recording sources Cameras with ffmpeg

To discover all potential camera sources for our live stream we can list them in the Terminal with following commands

avfoundation lib is used for MAC
ffmpeg -f avfoundation -list_devices true -i ""
DirectX  the command directshow  equivalent for windows
ffmpeg -y -f dshow -i list

Additional Input Sources for VLC Capture & Stream

Version 3.0

Support DVB-T2  [Windows] [Austria]  !

Version 2.2

QTKit  Quicktime API  Audio & Video

Linear Systems (HD-)SDI cards input support  [LINUX]

Blackmagic DeckLink SDI cards input support [LINUX]

DVB-S scanning support [Unix]

DVB-C scanning [Unix]

VLC & Versions Info installed

VLC 2.1.2 (working Screen Capture)
VLC 2.2.4 Weatherwax (newest Public Build) Web Interface outdated broken – Rewriting new Flowplayer v.6
VLC 3.o.o (nighty testing Chromecast)
FFmpeg : ffmpeg version 3.1.5
Web Interface : http://localhost:8080/
Video Player MPEG Streamclip SQUARED  still the best video player and converter

Facebook Live Broadcasting Parameter

  • Video Resolution: max 720p (1280 x 720), PAL 25 frames, NTSC  30 frames per second
  • Key-Frame Interval of 1 every 2 seconds ,every 50   PAL , 60 Frames NTSC
  • Max bit rate 4000Kbps
  • Rate control: CBR (see above desc.)
  • 240 minute or 4 hour max on a default stream
  • Audio Sample Rate: 22KHz | 44.1 kHz
  • Audio Bitrate: 64-128 Kbps

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Code Cowboy Recent comment authors
  Subscribe  
newest oldest most voted
Notify of