如何使用ffmpeg将live rtmp流转码为live hls流? [英] How can we transcode live rtmp stream to live hls stream using ffmpeg?

查看:695
本文介绍了如何使用ffmpeg将live rtmp流转码为live hls流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将实时rtmp流转换为hls流实时。



阅读后我有一些想法

< E2%80%93-部分-IV /> http://sonnati.wordpress.com/2011/08/30/ffmpeg-%E2%80%93-the-swiss-army-knife-of-internet-streaming - %E2%80%93-part-iv /



我可以将live rtmp流转换为hls,但不能在运行时转换。当我运行命令并测试任何hsl文件(.m3u8和.ts),我无法看到,但是当我中断命令并检查我需要hls文件。



我在google上搜索解决方案,但无法得到正确的答案。



任何身体都能帮助我吗?



感谢提前...

解决方案

这是一个简短的HLS流媒体与任何输入文件或流的指南:



我正在关注user1390208的方法,所以我只使用FFMPEG来产生我的服务器接收的rtmp流,以提供HLS 。而不是虚幻/ Wowza / Adob​​e,我使用免费的服务器nginx与rtmp模块,这是很容易设置。这是我简单的说:任何输入文件或流 - > ffmpeg - > rtmp - > nginx服务器 - > HLS - >客户端或更详细:



输入视频文件或流(http,rtmp,whatever) - > ffmpeg转码转换到x.264 + aac,输出到rtmp - > nginx将使用rtmp并为用户(客户端)提供HLS。
所以在客户端,您可以使用VLC或任何连接到由nginx提供的.m3u8文件。





您从哪里获取rtmp流?




  • 一个文件?那么你可以使用我的方法。

  • 任何具有流Y的服务器X?那么你必须将ffmpeg命令更改为:

      ffmpeg -re -i rtmp:// theServerX / yourStreamY -c:v libx264 -b:v 5M -pix_fmt yuv420p -c:a:0 libfdk_aac -b:a:0 480k -f flv rtmp:// localhost:12345 / hls / mystream; 

    或者如果您的rtmp流已经是h.264 / aac编码,可以尝试使用复制选项在ffmpeg中直接将内容流式传输到nginx。




在我的nginx配置文件中看到:




  • 我的rtmp服务器有一个名为hls的应用程序。这是描述nginx监听ffmpeg的rtmp流的地方,这就是为什么ffmpeg流到 rtmp:// localhost:12345 / hls / mystream;

  • 我的http服务器具有位置/ hls 。这意味着在VLC中,我可以连接到 http:// myServer:80 / hls / mystream.m3u8 来访问HLS流。



一切清楚吗?快乐流!


I am trying to convert a live rtmp stream to hls stream on real time.

I got some idea after reading

http://sonnati.wordpress.com/2011/08/30/ffmpeg-%E2%80%93-the-swiss-army-knife-of-internet-streaming-%E2%80%93-part-iv/

i am able to convert the live rtmp stream to hls but not at run time. when i run the command and test for any hsl files (.m3u8 and .ts) i am not able to see but when i interrupt the command and check there i get the hls files as required.

I searched on google for solution but not able to get proper answer.

Can any body help me?

Thanks in Advance...

解决方案

This is a short guide for HLS streaming with any input file or stream:

I am following user1390208's approach, so I use FFMPEG only to produce the rtmp stream which my server then receives to provide HLS. Instead of Unreal/Wowza/Adobe, I use the free server nginx with the rtmp module, which is quite easy to setup. This is how I do it in short: Any input file or stream -> ffmpeg -> rtmp -> nginx server -> HLS -> Client or more detailed:

input video file or stream (http, rtmp, whatever) --> ffmpeg transcodes live to x.264 + aac, outputs to rtmp --> nginx takes the rtmp and serves a HLS to the user (client). So on the client side you can use VLC or whatever and connect to the .m3u8 file which is provided by nginx.

  • I followed this setup guide for nginx.
  • This is my nginx config file.
  • This is how I use ffmpeg to transcode my input file to rtmp:

    ffmpeg -re -i mydirectory/myfile.mkv -c:v libx264 -b:v 5M -pix_fmt yuv420p -c:a:0 libfdk_aac -b:a:0 480k -f flv rtmp://localhost:12345/hls/mystream;
    

    (the .mkv is 1080p with 5.1 sound, depending on your input, you should use lower bitrates!)

Where do you get the rtmp stream from?

  • A file? Then you can use exactly my approach.
  • Any server X with a stream Y? Then you have to change the ffmpeg command to:

    ffmpeg -re -i rtmp://theServerX/yourStreamY -c:v libx264 -b:v 5M -pix_fmt yuv420p -c:a:0 libfdk_aac -b:a:0 480k -f flv rtmp://localhost:12345/hls/mystream;
    

    or if your rtmp stream is already h.264/aac encoded, you could try to use the copy option in ffmpeg to stream the content directly to nginx.

As you see in my nginx config file:

  • My rtmp server has an "application" called "hls". That's the part that describes where nginx listens to ffmpeg's rtmp stream and that's why ffmpeg streams to rtmp://localhost:12345/hls/mystream;
  • My http server has the location /hls. This means in VLC I can connect to http://myServer:80/hls/mystream.m3u8 to access the HLS stream.

Is everything clear? Happy streaming!

这篇关于如何使用ffmpeg将live rtmp流转码为live hls流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆