About Nginx Streaming Server deployment of the article has been a lot of, today I talk about how to push the stream to the server while the flow code to save the MP4 file, the main use of the ffmpeg.
1, the first need to explain is that you can not use the EXEC command. He will automatically terminate the calling external program at the end of the client push stream, and the result is that the final ffmpeg cannot be fully encoded. This command is only suitable for pushing the flow to other addresses.
2, should use Exec_record_done with the Record command. That is, the recorded files are automatically transcoded after the recording is finished to get the MP4 file. There are two different situations depending on whether you use the Record_interval command.
2 A, if the record_interval is not used, it will be transcoded after the push-flow stop (that is, after the record is completely stopped), before this can not get any output
2 B, if you use Record_interval, you can set to restart recording every once in a while, combined with the record_append on command, you can ensure that the last recorded video is in one file, or you will generate a separate file for each recording. After using these two commands, the transcoding will also be performed at intervals of time, but the final output (overwrite) is in the same file. The advantage is that it can be almost "real-time" transcoding, the disadvantage is to repeatedly call FFmpeg, occupy the system resources.
3, it should be noted that the two methods of the last obtained transcoding files (the length) 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-v Codec libx264-f mp4/home/zhanghui/test/test_record.mp4 2>>/home/zhanghui/test/test_record.log; }
The above describes how to implement the multimedia stream recording and transcoding on the Nginx server, including the content, I hope that the PHP tutorial interested in a friend helpful.