: This article describes how to record and transcode multimedia streams on the nginx server. if you are interested in the PHP Tutorial, refer to it. There are already many articles on deploying the nginx streaming media server. today I will explain how to save the stream as an MP4 file while pushing the stream to the server, here we mainly use ffmpeg.
1. the exec command is not supported. It will automatically terminate the called external program when the client ends streaming. The result is that the final ffmpeg cannot be fully encoded. This command is only suitable for pushing received streams to other addresses.
2. exec_record_done should be used with the record command. That is, after the recording is completed, the recorded files are automatically transcoded to obtain the MP4 files. There are two different situations based on whether the record_interval command is used.
2A. if record_interval is not used, transcoding is performed after the streaming is stopped (that is, after the record is completely stopped), and no output is obtained before the streaming is stopped.
2B. if record_interval is used, you can set the recording to start again every other time. combined with the record_append on command, you can ensure that the last recorded video is in a file, otherwise, a separate file is generated for each recording segment. After these two commands are used, transcoding is performed at intervals, but output (overwrite) to the same file. The advantage is that transcoding can be performed almost in real time. The disadvantage is that ffmpeg is repeatedly called to occupy system resources.
3. Note that the final transcoding File (duration) obtained by the above two methods is the same.
4. nginx. conf configuration example
application hls { live on; hls on; record all; record_path /home/zhanghui/test;#record_interval 10s;#record_append on; hls_path /tmp/app; hls_fragment 5s; # convert recorded file to mp4 formatexec_record_done '/usr/local/bin/ffmpeg' -y -i /home/zhanghui/test/livestream.flv -vcodec libx264 -f mp4 /home/zhanghui/test/test_record.mp4 2>>/home/zhanghui/test/test_record.log; }
The above introduces how to achieve multimedia stream recording and transcoding on the nginx server, including some content, hope to be helpful to friends who are interested in PHP tutorials.