Ffmpeg combat course (9) under windows ffmpeg Command + nginx + rtmp to achieve push and pull.

Summary Nginx is a lightweight Web server/reverse proxy server and email (IMAP/POP3) proxy server. nginx-rmtp-module is a streaming media plug-in for...
Summary
First, introduce how to build nginx + rtmp under windows
Nginx Start, Stop, etc.
FFmpeg push flow
Pull flow
Here are some common commands for ffmpeg.

Summary

Nginx is a lightweight Web server/reverse proxy server and email (IMAP/POP3) proxy server.
nginx-rmtp-module is a streaming media plug-in for Nginx server.

Nginx provides rtmp service through rtmp module, ffmpeg pushes a rtmp stream to nginx, and then the client accesses nginx to watch real-time video stream.

First, introduce how to build nginx + rtmp under windows

There are two options:
(1)
1. Download nginx: http://nginx.org/
2. Download nginx-rmtp-module: https://github.com/arut/nginx-rtmp-module
3. Configure nginx.conf

#nginx.conf rtmp { server { listen 1935; chunk_size 4000; # TV mode: one publisher, many subscribers application wstv{ # enable live streaming live on; # record first 1K of stream record all; record_path /tmp/av; record_max_size 1K; # append current timestamp to each flv record_unique on; # publish only from localhost allow publish 127.0.0.1; deny publish all; #allow play all; }

4. compilation

./configure --add-module=/path/to/nginx-rtmp-module make make install

Note that the configuration command for nginx version in nginx (1.3.14-1.5.0) is as follows:
./configure –add-module=/path/to/nginx-rtmp-module –with-http_ssl_module

5. Open the server, test
Browser input localhost:80

(two)
The first one needs us to inherit the rtmp module, and the second one is relatively simple.
We can be at http://nginx-win.ecsds.eu/ Download the integrated nginx. You can refer to it here. http://blog.csdn.net/lishimin1012/article/details/52130683

Nginx Start, Stop, etc.

1. Start up:

C:\nginx-1.10.2>start nginx

or

C:\nginx-1.10.2>nginx.exe

Note: The first one is recommended, and the second one keeps your cmd window in execution and cannot perform other command operations.

2. Stop:

C:\nginx-1.10.2>nginx.exe -s stop

or

C:\nginx-1.10.2>nginx.exe -s quit

Note: stop is to stop nginx quickly, and may not save relevant information; quit is to stop nginx completely and orderly, and save relevant information.

3. Reload Nginx:

C:\nginx-1.10.2>nginx.exe -s reload

Use this command when configuration information is modified and these configurations need to be reloaded.

FFmpeg push flow

Push-flow and pull-flow address: rtmp://localhost:1935/wstv/home
Place a video file named ws2.avi on the desktop
cd to desktop input:

ffmpeg -re -i ws2.avi -vcodec libx264 -acodec aac -f flv rtmp://localhost:1935/wstv/home

Pull flow

Open the vlc player
Enter pull-in address:

rtmp://localhost:1935/wstv/home

Then return from the command line and click the play button of vlc.

Of course, you can also write some js code on the web ports, and also support playback. If your mobile player supports rtmp streaming protocol, it can also play.
If you feel that pushing a stream, pulling a stream is not addictive, but there are more than n streams pushing and pulling at the same time, then you can open another cmd, pushing one is also possible.

Here are some common commands for ffmpeg.

1. If you want to record or share your desktop, you can use the command line as follows:

ffmpeg -f avfoundation -i "1" -vcodec libx264 -preset ultrafast -acodec libfaac -f flv rtmp://localhost:1935/wstv/home
This can only push the desktop.

2. If desktop + microphone is needed, for example, the command line for distance education sharing is as follows:

ffmpeg -f avfoundation -i "1:0" -vcodec libx264 -preset ultrafast -acodec libmp3lame -ar 44100 -ac 1 -f flv rtmp://localhost:1935/wstv/home
This can push desktop + microphone.

3. If you need a desktop + microphone, and you need a camera to take pictures of yourself, such as interactive anchor, game anchor, the command line is as follows

ffmpeg -f avfoundation -framerate 30 -i "1:0" \-f avfoundation -framerate 30 -video_size 640x480 -i "0" \-c:v libx264 -preset ultrafast \-filter_complex 'overlay=main_w-overlay_w-10:main_h-overlay_h-10' -acodec libmp3lame -ar 44100 -ac 1 -f flv rtmp://localhost:1935/wstv/home
This can push the desktop + microphone, and the camera puts the human head under the interface.

Common basic commands of FFmpeg
1. Separation of video and audio streams

ffmpeg -i input_file -vcodec copy -an output_file_video //Separation of video streams ffmpeg -i input_file -acodec copy -vn output_file_audio //Separation of audio streams

2. Video Demultiplexing

ffmpeg –i test.mp4 –vcodec copy –an –f m4v test.264ffmpeg –i test.avi –vcodec copy –an –f m4v test.264

3. Video transcoding

ffmpeg –i test.mp4 –vcodec h264 –s 352*278 –an –f m4v test.264 //Transcoding to the original stream file ffmpeg –i test.mp4 –vcodec h264 –bf 0 –g 25 –s 352*278 –an –f m4v test.264 //Transcoding to the original stream file ffmpeg –i test.avi -vcodec mpeg4 –vtag xvid –qsame test_xvid.avi //Transcoding to encapsulated file
-bf B Frame Number Control -g key frame interval control -s resolution control

4. Video Encapsulation

ffmpeg –i video_file –i audio_file –vcodec copy –acodec copy output_file

5. Video clipping

ffmpeg –i test.avi –r 1 –f image2 image-%3d.jpeg //Extract pictures ffmpeg -ss 0:1:30 -t 0:0:20 -i input.avi -vcodec copy -acodec copy output.avi //Clip video
-r Extraction Frequency of Image -ss start time - t duration

6. Video recording

ffmpeg –i rtsp://192.168.3.205:5555/test –vcodec copy out.avi

7.YUV Sequence Play

ffplay -f rawvideo -video_size 1920x1080 input.yuv

8.YUV sequence to AVI

ffmpeg –s w*h –pix_fmt yuv420p –i input.yuv –vcodec mpeg4 output.avi

9. Description of common parameters:

Main parameters:
i Set Input Flow
f Setting Output Format
ss start time
Video parameters:
b Set video traffic, default frame rate for 200Kbit/s-r, default 25
s Setting Screen Width and Height-aspect Setting Screen Ratio
vn does not process video-vcodec to set the video codec, and when not set, it uses the same codec as the input stream.
Audio parameters:
ar set sampling rate
ac Sets Channel Number of Sounds
acodec sets the audio codec, and when not set, uses the same codec an as the input stream to not process the audio.

21 December 2018, 07:54 | Views: 8876

Add new comment

For adding a comment, please log in
or create account

0 comments