ffmpeg 推流FLV文件,采用rtmp协议

本文介绍了如何使用ffmpeg将FLV文件通过rtmp协议进行推流,涉及音视频基础知识如时间基、AVRational结构体、PTS与DTS概念,以及rtmp协议和FLV格式解析。通过学习,读者可以理解ffmpeg推流过程中的关键点。
摘要由CSDN通过智能技术生成
  • 想看懂这个代码需要掌握以下音视频基础知识

1、音视频时间基是什么?
FFMPEG之TimeBase成员理解
补充:封装/解封装、编码/解码、采集/显示这三个层面中的taimeBase是代表不同的意思的,需要通过转换才可以进行上下层的交互。

2、ffmpeg中对AVRational结构体理解
ffmpeg # AVRational
假如一秒25帧就是1/25;那么换算成每毫秒25帧就是1000* 1 /25 = 1000/25;换算成每微妙25帧话就是1000*1000/25(每一毫秒等于1000微妙)。

3、PTS和DTS是什么?
PTS:显示的时间;
DTS:编码/解码时间;
音频在时间轴是连续的,所以PTS和DTS是一样的;
视频中因为有I、B、P帧,I是关键帧,P是向前预测,B是向前向后预测所以当没有B帧时候PTS和DTS在时间轴是一样的,为什么有了B帧就就不一样的呢,因为B帧要等待其他帧解码出来后才知道这个B帧是 多少。
I、B、P帧主要是为了更拼命努力

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是使用Qt和FFmpeg推流flv的示例代码: ```cpp #include <QCoreApplication> #include <QDebug> #include <QThread> #include <QTimer> #include <QDateTime> #include <QProcess> class FFmpegPusher : public QObject { Q_OBJECT public: explicit FFmpegPusher(QObject *parent = nullptr) : QObject(parent) {} void start(QString ipAddress, QString pushAddress) { QString command = QString("ffmpeg -i %1 -f flv %2").arg(ipAddress).arg(pushAddress); qDebug() << "Command:" << command; m_process = new QProcess(this); connect(m_process, &QProcess::readyReadStandardOutput, this, &FFmpegPusher::onReadyReadStandardOutput); connect(m_process, &QProcess::readyReadStandardError, this, &FFmpegPusher::onReadyReadStandardError); connect(m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &FFmpegPusher::onFinished); m_process->start(command); } private slots: void onReadyReadStandardOutput() { qDebug() << "Standard Output:" << m_process->readAllStandardOutput(); } void onReadyReadStandardError() { qDebug() << "Standard Error:" << m_process->readAllStandardError(); } void onFinished(int exitCode, QProcess::ExitStatus exitStatus) { qDebug() << "Process Finished with Exit Code:" << exitCode << "Exit Status:" << exitStatus; } private: QProcess *m_process = nullptr; }; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); FFmpegPusher pusher; pusher.start("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov", "rtmp://live.hkstv.hk.lxdns.com/live/hks"); return a.exec(); } ``` 该示例代码使用Qt的QProcess类来启动FFmpeg进程,并将其输出重定向到标准输出和标准错误流。您可以根据需要修改IP地址和推送地址。请确保已正确安装FFmpeg并将其添加到系统路径中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

太极者,无极而生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值