Use C++, RTMP protocol and FFmpeg to push video streams, and use VLC to receive and play HTTP streams.
This project is simple to show how to use ffmpeg & RTMP to push video streaming.
You can find for more details form my notion.
Win 10 | Ubuntu 1604 |
---|
- nginx 1.7.11.3 Gryphon
- nginx 1.7.11.3 Gryphon: to http://nginx-win.ecsds.eu/download/ download "nginx 1.7.11.3 Gryphon.zip"
- nginx-rtmp-module: https://github.com/sergey-dryabzhinsky/nginx-rtmp-module
- FFmpeg Source Code: https://www.ffmpeg.org/download.html GIthub Windows build: BtbN/FFmpeg-Builds
- VLC https://www.videolan.org/
- Sample flv sample flv video: https://sample-videos.com/
You can find for more details form my notion.
Use C++, RTMP protocol and FFmpeg to push a local flv video stream, and use VLC to live HTTP streams.
This project is simple to show how to use ffmpeg & RTMP to push video streaming.
- Function
- avformat_open_input():
- Allocate memory to the component AVFormatContext *in
- Open the file and read its header and fill the AVFormatContext with minimal information about the format.
- avformat_find_stream_info():
- To access the streams, we need to read data from the media. Throught this function, in->nb_streams will hold the amount of streams and in->streams[i] will return the i stream.
- avformat_open_input():
- Method
/** * @param input_format_context AVFormatContext type input ptr. * @param file_path input file path. * @return 0:ok; -1:error **/ int GetFileStreamInfo(AVFormatContext*& input_format_context, const char* file_path);
-
Description
-
Function
- avformat_alloc_output_context2():
- Allocate memory to AVFormatContext *output_format_context
- According to format_type to fill the AVFormatContext with minimal information about the format.
- avformat_alloc_output_context2():
-
Method
/** * @param output_format_context AVFormatContext output ptr. * @param format_type video format * @param out_url RTMP URL * @return 0:ok; -1:error **/ int CreateAVFormatContextInstance(AVFormatContext *&output_format_context, const char *format_type, const char *out_url);
- Function
- avcodec_find_encoder(): Find the input_format_context codec ID(AVCodec).
- avformat_new_stream(): To create new out stream into our output format context.
- avcodec_parameters_copy(): Copy the contents of src to dst.
- Method
/** * @param AVFormatContext input ptr. * @param AVFormatContext output ptr. * @return 0:ok; -1:error **/ int CreateOutputStream(AVFormatContext*& input_format_context, AVFormatContext*& output_format_context);
- Description Create the output file.
- Function
- avio_open():
- Create and initialize a AVIOContext for accessing the resource indicated by url.
- avformat_write_header():
- Allocate the stream private data and write the stream header to an output media file
- avio_open():
- Method
/** * @param output_format_context AVFormatContext output ptr. * @param url output file name. * @return 0:ok; -1:error **/ int CreateAndInitAVIOContext(AVFormatContext*& output_format_context, const char* url);
- Description Remuxing is the act of changing from one format (container) to another. (allows an Elementary stream to be divided into packets)(transport stream). Copy the streams, packet by packet, from our input to our output streams.
- Function
- av_read_frame(): Feed packets(AVPacket) from the stream while it has packets.
- av_rescale_q_rnd():
Rescale a 64-bit integer by 2 rational numbers with specified rounding.The operation is mathematically equivalent to
a * bq / cq
. - av_interleaved_write_frame(): Write a packet to an output media file ensuring correct interleaving.This function will buffer the packets internally as needed to make sure thepackets in the output file are properly interleaved in the order ofincreasing dts.
- Method
/** * @param input_format_context AVFormatContext intput ptr. * @param output_format_context AVFormatContext output ptr. * @return 0:ok; -1:error **/ int Remuxing(AVFormatContext*& input_format_context, AVFormatContext*& output_format_context);
- According to nginx-1.7.11.3-Gryphon\conf\nginx-win.conf, ours RTMP URL is "rtmp://127.0.0.1:1935/live/home".
- Open VLC.exe -> Playback -> Play -> Network -> enter the URL: rtmp://127.0.0.1:1935/live/home -> Play
- Run your executable file (bin\Release\video_to_rtmp.exe)
And VLC media play will receive packgets