How to realize the recording and transcoding of multimedia stream on Nginx server

Source: Internet
Author: User
Tags nginx server
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.