How to streaming video via nginx with Local Docker run

Chaiwat Tungtongsoontorn
Tri Petch Digital
Published in
2 min readDec 13, 2022

introduction

I was curious about “how can I streaming video”. This blog is the door for getting started how to do it. There are components to complete streaming video in your local environment.

prerequisites

  • FFmpeg — A complete, cross-platform solution to record, convert and stream audio and video to send video to rtmp server.
  • Docker image — We are going to run rtmp protocal server via nginx which already has rtmp plugins. This is image we discuss — https://github.com/tiangolo/nginx-rtmp-docker
  • VLC media player — open source cross-platform multimedia player and framework that plays most multimedia files as well as DVDs, Audio CDs, VCDs, and various streaming protocols. This tool is for watching our video streaming. You can download and install on this link (http://www.videolan.org/vlc/index.html).

Steps to run

  1. First thing first, Run docker container with this command
$ docker run -p 1935:1935 --name nginx-rtmp tiangolo/nginx-rtmp

2. Then convert your video and copy your video to rtmp server with this command

$ ffmpeg -re -i <PATH_TO_YOUR_VIDEO_DIRECT>/<YOUR_VIDEO> -vcodec copy -c:a aac -b:a 160k -ar 44100 -f flv rtmp://<NGINX_SERVER>/live

## Example
$ ffmpeg -re -i ./tmp/video_example_1920_18mb.mp4 -vcodec copy -c:a aac -b:a 160k -ar 44100 -f flv rtmp://localhost/live

3. Try to access your video streaming via VLC

  • Goto Media Library menu as figure below
  • Add URL streaming from your nginx server with this URL — rtmp://localhost/live

🎉🎉 Congratulations, now you can test your streaming video with few steps on your local machine.

Contact us or find more Blogs here.
- https://medium.com/tri-petch-digital

--

--