• Stars
    star
    177
  • Rank 215,985 (Top 5 %)
  • Language
    Shell
  • Created over 6 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Provide guidance to test live streaming (mpeg-dash or hls) or vod from your desktop

Live stream from your desktop

It provides guidance to test live streaming (mostly RTMP, mpeg-dash or hls) or vod from your own desktop using FFmpeg, it's pretty useful for testing and learning purposes.

MacOS

Tested with:

  • MacOS High Siera 10.13, 10.15.2, Ubuntu 18.04
  • Warning: The video asset used for looping streaming is more than hundreds of MBs.

Requirements

docker
wget
curl

Simulating HLS / DASH with multiple renditions/resolutions and DVR

HLS

Run this server in one of your tabs:

curl -s https://raw.githubusercontent.com/leandromoreira/live-stream-from-desktop/master/start_http_server.sh | sh

Run this encoder in another of your tabs:

curl -s https://raw.githubusercontent.com/leandromoreira/live-stream-from-desktop/master/start_hls_abr_live_stream.sh | sh

Access the stream at http://localhost:8080/master.m3u8 or at clappr's demo page

HLS looping the file

If you want to use a video file instead of a synthetic media, run this encoder in another of your tabs:

curl -s https://raw.githubusercontent.com/leandromoreira/live-stream-from-desktop/master/start_hls_abr_live_stream_file_loop.sh | sh

DASH

Run this server in one of your tabs:

curl -s https://raw.githubusercontent.com/leandromoreira/live-stream-from-desktop/master/start_http_server.sh | sh

Run this encoder in another of your tabs:

curl -s https://raw.githubusercontent.com/leandromoreira/live-stream-from-desktop/master/start_dash_abr_live_stream.sh | sh

Access the stream at http://localhost:8080/out.mpd or go to dashjs's demo page

Simulating an HLS and MPEG-DASH live streaming for latency comparison

HLS

Run this server in one of your tabs:

curl -s https://raw.githubusercontent.com/leandromoreira/live-stream-from-desktop/master/start_http_server.sh | sh

Run this encoder in another of your tabs:

curl -s https://raw.githubusercontent.com/leandromoreira/live-stream-from-desktop/master/start_hls_low_latency_live_stream.sh | sh

Access the stream at http://localhost:8080/stream.m3u8 or at clappr's demo page

MPEG-DASH

Run this server in one of your tabs:

curl -s https://raw.githubusercontent.com/leandromoreira/live-stream-from-desktop/master/start_http_server.sh | sh

Run this encoder in another of your tabs:

curl -s https://raw.githubusercontent.com/leandromoreira/live-stream-from-desktop/master/start_mpeg_dash_low_latency_live_stream.sh | sh

Access the stream at http://localhost:8080/stream.mpd

Requirements

# I assume you have brew already

# or you could use curl
brew install wget
brew install ffmpeg
brew install node

# the http server
npm install http-server -g

#  WARNING IT IS A HUGE download file (263M)
wget -O bunny_1080p_30fps.mp4 http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_30fps_normal.mp4

Sending live RTMP from your local machine

Single Bitrate

From a pseudo FFmpeg video source color bar and generated audio signal made of a sine wave with amplitude 1/8.

ffmpeg -hide_banner \
-re -f lavfi -i "testsrc2=size=1280x720:rate=30,format=yuv420p" \
-f lavfi -i "sine=frequency=1000:sample_rate=4800" \
-c:v libx264 -preset ultrafast -tune zerolatency -profile:v high \
-b:v 1400k -bufsize 2800k -x264opts keyint=30:min-keyint=30:scenecut=-1 \
-c:a aac -b:a 128k -f flv rtmp://<HOST>:1935/live/<STREAM>

From a file.

ffmpeg -stream_loop -1 \
-re -i <YOUR_VIDEO>.mp4  -c:v libx264 \
-x264opts keyint=30:min-keyint=30:scenecut=-1 -tune zerolatency \
-s 1280x720 -b:v 1400k -bufsize 2800k \
-f flv rtmp://<HOST>:1935/live/<STREAM>

Multiple Bitrates

From a pseudo FFmpeg video source color bar and generated audio signal made of a sine wave with amplitude 1/8.

ffmpeg -hide_banner \
-re -f lavfi -i "testsrc2=size=1280x720:rate=30,format=yuv420p" \
-f lavfi -i "sine=frequency=1000:sample_rate=4800" \
-c:v libx264 -preset ultrafast -tune zerolatency -profile:v high \
-b:v 1400k -bufsize 2800k -x264opts keyint=30:min-keyint=30:scenecut=-1 \
-c:a aac -b:a 128k -f flv rtmp://<HOST>:1935/live/<STREAM> \
-c:v libx264 -preset ultrafast -tune zerolatency -profile:v high \
-b:v 750k -bufsize 1500k -s 640x360 -x264opts keyint=30:min-keyint=30:scenecut=-1 \
-c:a aac -b:a 128k -f flv rtmp://<HOST>:1935/live/<STREAM> 

From a file.

ffmpeg -stream_loop -1 \
-re -i <YOUR_VIDEO>.mp4  -c:v libx264 \
-x264opts keyint=30:min-keyint=30:scenecut=-1 -tune zerolatency \
-s 1280x720 -b:v 1400k -bufsize 2800k \
-f flv rtmp://<HOST>:1935/live/<STREAM> \
-x264opts keyint=30:min-keyint=30:scenecut=-1 -tune zerolatency \
-s 640x360 -b:v 750k -bufsize 1500k \
-f flv rtmp://<HOST>:1935/live/<STREAM>

Simulating a MPEG-DASH live streaming from a file

Open a terminal and run the ffmpeg command:

ffmpeg -stream_loop -1 -re -i bunny_1080p_30fps.mp4 \
       -c:v libx264 -x264opts keyint=30:min-keyint=30:scenecut=-1 \
       -preset superfast -profile:v baseline -level 3.0 \
       -tune zerolatency -s 1280x720 -b:v 1400k \
       -bufsize 1400k -use_timeline 1 -use_template 1 \
       -init_seg_name init-\$RepresentationID\$.mp4 \
       -min_seg_duration 2000000 -media_seg_name test-\$RepresentationID\$-\$Number\$.mp4 \
       -f dash stream.mpd

In another tab, run the following command to fire up the server:

http-server -a :: -p 8081 --cors -c-1

Now you can test this with your player (using the URL http://localhost:8081/stream.mpd).

Simulating an HLS live streaming from a file

Open a terminal and run the ffmpeg command:

ffmpeg -stream_loop -1 -re -i bunny_1080p_30fps.mp4 -c:v libx264 \
          -x264opts keyint=30:min-keyint=30:scenecut=-1 \
          -tune zerolatency -s 1280x720 \
          -b:v 1400k -bufsize 1400k \
          -hls_start_number_source epoch -f hls stream.m3u8

In another tab, run the following command to fire up the server:

http-server -a :: -p 8081 --cors -c-1

Now you can test this with your player (using the URL http://localhost:8081/stream.m3u8).

Simulating a MPEG-DASH live streaming from MacOS camera

Open a terminal and run the ffmpeg command:

ffmpeg -re -pix_fmt uyvy422 -f avfoundation -i "0" -pix_fmt yuv420p \
       -c:v libx264 -x264opts keyint=30:min-keyint=30:scenecut=-1 \
       -preset superfast -profile:v baseline -level 3.0 \
       -tune zerolatency -s 1280x720 -b:v 1400k \
       -bufsize 1400k -use_timeline 1 -use_template 1 \
       -init_seg_name init-\$RepresentationID\$.mp4 \
       -min_seg_duration 2000000 -media_seg_name test-\$RepresentationID\$-\$Number\$.mp4 \
       -f dash stream.mpd

In another tab, run the following command to fire up the server:

http-server -a :: -p 8081 --cors -c-1

Now you can test this with your player (using the URL http://localhost:8081/stream.mpd).

Simulating a HLS live streaming from MacOS camera

Playing Camera/Mic in FFplay

ffplay  -f avfoundation -video_device_index 0 -audio_device_index 0 \
        -pixel_format uyvy422 -framerate 30 -video_size 1280x720 -i "default"

MacOS Camera/Mic to HLS

Open a terminal and run the ffmpeg command:

ffmpeg  -f avfoundation -video_device_index 0 -audio_device_index 0 \
        -pixel_format uyvy422 -framerate 30 -video_size 640x480 -i "default" \
        -c:v libx264 -x264opts keyint=30:min-keyint=30:scenecut=-1 \
        -tune zerolatency -b:v 1000k -bufsize 2000k \
        -c:a aac -b:a 128k \
        -hls_time 5 -hls_start_number_source epoch \
        -f hls stream.m3u8

In another tab, run the following command to fire up the server:

http-server -a :: -p 8081 --cors -c-1

Now you can test this with your player (using the URL http://localhost:8081/stream.m3u8).

MacOS Camera/Mic to Twitch/Youtube/RTMP

Open a terminal and run the ffmpeg command:

ffmpeg  -f avfoundation -video_device_index 0 -audio_device_index 0 \
        -pixel_format uyvy422 -framerate 30 -video_size 640x480 -i "default" \
        -c:v libx264 -x264opts keyint=30:min-keyint=30:scenecut=-1 \
        -tune zerolatency -b:v 600k -bufsize 1200k -preset superfast \
        -c:a aac -b:a 128k \
        -f flv rtmp://yourserver:1935/live/yourstream_key

Bonus Round:

FFmpeg generating noise from /dev/random

It generates video and audio from /dev/urandom device, it produces a stream that looks A LOT like an old analog TV noise.

In analog video and television, is a random dot pixel pattern of static displayed when no transmission signal is obtained by the antenna receiver

# if you mess with the -video_size you can have bigger/smaller noise patterns than this. :D
ffmpeg -f rawvideo -pixel_format rgb8 -video_size 640x360 \
       -framerate 60 -i /dev/urandom \
       -f u8 -ar 48100 -ac 1 -i /dev/urandom \
       -sws_flags neighbor -s 640x360 urandom.mp4       

old tv noise

FFmpeg generating video from FFmpeg binary program

# you can replace the binary by any large binary chunk of data (library...)
ffmpeg -f rawvideo -pixel_format rgb8 -video_size 32x23 \
       -framerate 60 -i /usr/local/Cellar/ffmpeg/4.3_2/bin/ffmpeg \
       -f u8 -ar 48100 -ac 1 -i /usr/local/Cellar/ffmpeg/4.3_2/bin/ffmpeg \
       -sws_flags neighbor -s 640x360 -t 5s -pix_fmt yuv420p ffmpeg.mp4

FFmpeg generating video from Mandelbrot set

ffplay -f lavfi -i mandelbrot=size=640x320:rate=60 \
       -vf "drawtext = text = 'UTC %{gmtime}':fontsize=24:fontcolor=white:[email protected]:x=(w-text_w)/2:y=4:box=1:boxborderw=5"

More Repositories

1

digital_video_introduction

A hands-on introduction to video technology: image, video, codec (av1, vp9, h265) and more (ffmpeg encoding). Translations: 🇺🇸 🇨🇳 🇯🇵 🇮🇹 🇰🇷 🇷🇺 🇧🇷 🇪🇸
Jupyter Notebook
15,367
star
2

ffmpeg-libav-tutorial

FFmpeg libav tutorial - learn how media works from basic to transmuxing, transcoding and more. Translations: 🇺🇸 🇨🇳 🇰🇷 🇪🇸 🇻🇳 🇧🇷
C
9,873
star
3

linux-network-performance-parameters

Learn where some of the network sysctl variables fit into the Linux/Kernel network flow. Translations: 🇷🇺
5,380
star
4

cdn-up-and-running

CDN Up and Running - Building a CDN from Scratch to Learn about CDN, Nginx, Lua, Prometheus, Grafana, Load balancing, and Containers.
Lua
3,199
star
5

redlock-rb

Redlock is a redis-based distributed lock implementation in Ruby. More than 20M downloads.
Ruby
684
star
6

nginx-lua-redis-rate-measuring

A lua library to provide distributed rate measurement using nginx + redis, you can use it to do a throttling system within many nodes.
Lua
150
star
7

http-video-streaming-troubleshooting

A collection of fixes / problem solutions to HTTP video streaming
77
star
8

nott

The New OTT Platform - an excuse to discuss and design a simple edge computing platform
Lua
50
star
9

video-containers-debugging-tools

A set of command lines to debug video streaming files like mp4 (MPEG-4 Part 14), ts (MPEG-2 Part 1), fmp4 in Dash, HLS, or MSS, with or without DRM.
44
star
10

python_chip16

A full implementation (tested) of chip16 virtual machine, or emulator as you wish, using python and rendering with opengl.
Python
35
star
11

scte-35-scte-104-scte-67

Documentation/references about Dynamic Ad Insertion (DAI) through SCTE-104, SCTE-35 to HLS, MPEG DASH, Smooth, RTMP
31
star
12

tls_certificate_generation

Use temporary Amazon EC2 / Digital Ocean cloud machines to get / renew letsencrypt certificates
Shell
28
star
13

lua-resty-dynacode

A library to provide dynamic (via json/API) load of lua byte code into nginx/openresty.
Ruby
27
star
14

docker-ffmpeg-vmaf

Docker FFmpeg VMAF usage example / tips / workflow
25
star
15

edge-computing-resty

a simple edge computing platform using nginx, lua and rails
Ruby
24
star
16

resty-bakery

An Nginx+Lua library to modify media manifests like HLS and MPEG Dash, acting like a proxy.
Lua
21
star
17

player-ffmpeg

Up to date tutorial of ffmpeg
C
19
star
18

fake-as-fuck

I'm a lonely, lonely lord. Pick another day to be restored. Just another fate that's going overboard.
Python
19
star
19

lua-resty-perf

A small ngx resty lua library to benchmark memory and throughput of a function.
Lua
16
star
20

kaltura-media-framework-docker-compose

A docker compose for https://github.com/kaltura/media-framework
Go
13
star
21

cassandra-lock

A ruby lib to achieve consensus with Cassandra
Ruby
12
star
22

dotfiles

dotfiles
Shell
8
star
23

JChip16BR

An java implementation of VM Chip16.
Assembly
8
star
24

clappr-pause-tab-visibility

A clappr container plugin to pause when user is in another tab and resume when the user is back.
JavaScript
6
star
25

py-chip8

introduction to low level thingies
Python
6
star
26

tc-linux-rate-delay-specific-ip-on-docker

a docker experiment to learn to apply tc (linux traffic control) to shaping and delaying network for a specific CIDR/network.
Shell
6
star
27

jgb

gameboy emulator written in JavaScript
JavaScript
4
star
28

dcpu16

JDCPU16BR
Java
4
star
29

ruby_meta_programming

Meta programming Ruby - Book practise
Ruby
4
star
30

nginx-throttling-leaderboard

POC to test local throttling and top leaderboard most requested token
Lua
3
star
31

js_learning

My javascript training files
JavaScript
3
star
32

jmf

jmf - java media framework example of server and player
Java
3
star
33

hackday-27-06-19

Globo.com hackday-27-06-19
Lua
2
star
34

clojure_playground

It is a simple repo to study clojure
Clojure
2
star
35

clappr-dash-dashjs

A dash playback (based on dashjs) for 🎬 Clappr
HTML
2
star
36

clint

An ordinary encoder.
JavaScript
2
star
37

clojure-playground

Silly repo -> While I'm reading and learning about clojure I will use this guy to keep track
Clojure
2
star
38

jchip8br

Automatically exported from code.google.com/p/jchip8br
Java
1
star
39

playground.sh

A place to practice the fine art of shell script
Shell
1
star
40

d3.playground

A place to play with d3js
1
star
41

rslimbr

Ruby Slim Protocol for Fitnesse compatible with Ruby 1.9.x
Ruby
1
star
42

minimal-js-dash-player

JavaScript
1
star
43

jschip16br

the chip16 virtual machine specification implemented using javascript
1
star
44

playground.coffe

just another playground for a 'new' language
1
star
45

angularjs-pet

Pet project to learn and apply angularjs for large project with tests and fine structure.
JavaScript
1
star
46

test_legacy

Improve your legacy project providing certain level of test automation
Ruby
1
star
47

mediainfo

docker image for mediainfo
1
star
48

rspec_book

the book in praticse
Ruby
1
star
49

cat

Container as a Teacher
Shell
1
star