简体   繁体   English

使用FFmpeg通过RTMP发送H.264编码的流

[英]Send H.264 encoded stream through RTMP using FFmpeg

I followed this to encode a sequences images to h.264 video. 我按照此步骤将序列图像编码为h.264视频。

Here is outputting part of my code: 这是我的代码的输出部分:

int srcstride = outwidth*4;
sws_scale(convertCtx, src_data, &srcstride, 0, outheight, pic_in.img.plane, pic_in.img.i_stride);
x264_nal_t* nals;
int i_nals;
int frame_size = x264_encoder_encode(encoder, &nals, &i_nals, &pic_in, &pic_out);
if (frame_size) {
    fwrite(nals[0].p_payload, frame_size, 1, fp);
}

This is in a loop to process frames and write them into a file. 这是一个循环,用于处理框架并将其写入文件。

Now, I'm trying to stream these encoded frames through RTMP. 现在,我正在尝试通过RTMP流式传输这些编码的帧。 As I know, the container for the RTMP is FLV. 据我所知,RTMP的容器是FLV。 So I used command line as a trial: 因此,我使用命令行作为试用版:

ffmpeg -i test.h264 -vcodec copy -f flv rtmp://localhost:1935/hls/test

This one works well as streaming a h.264 encoded video file. 这个文件可以很好地播放h.264编码的视频文件。

But how can I implement it as C++ code and stream the frames at the same time when they are generated, just like what I did to stream my Facetime camera. 但是如何将其实现为C ++代码,并在生成帧的同时对其进行流传输,就像我对Facetime相机进行流传输一样。

ffmpeg -f avfoundation -pix_fmt uyvy422  -video_size 1280x720 -framerate 30 -i "1:0" -pix_fmt yuv420p -vcodec libx264 -preset veryfast -acodec libvo_aacenc -f flv -framerate 30 rtmp://localhost:1935/hls/test

This may be a common and practical topic. 这可能是一个常见且实用的主题。 But I'm stuck here for days, really need some relevant exprience. 但是我在这里呆了好几天,真的需要一些相关经验。 Thank you! 谢谢!

寻找关于libavformat的教程(例如dranger,google it)或更简单的方法,将h.264流写入stdio,然后将其通过管道传输到ffmpeg。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 ffmpeg 将缓冲区中的 H.264 流写入可流式传输的 mp4 - Write H.264 stream in buffer to a streamable mp4 using ffmpeg 将QUdpSocket用于自定义FFMPEG I / O(原始H.264) - Using a QUdpSocket for Custom FFMPEG I/O (raw H.264) 使用MediaCodec API JNI解码H.264流 - Decode H.264 stream using MediaCodec API JNI 如何在ffmpeg C ++ API中将关键帧(Iframe)插入到h.264视频流中? - How to insert a key frame(Iframe) to a h.264 video stream in ffmpeg C++ api? 如何使用FFMPEG从存储为视频AVPackets的NAL单元播放H.264流 - How to use FFMPEG to play H.264 stream from NAL units that are stored as video AVPackets 在 Windows 上通过 Live555 服务一个直播 OpenCV H.264 stream - Service a live OpenCV H.264 stream through Live555 on Windows 使用 FFmpeg 通过 UDP 流式传输 H.264 和“未设置尺寸”错误 - Streaming H.264 over UDP using FFmpeg, and "dimensions not set" error 如何使用FFmpeg C API对H.264视频进行编码,然后使用媒体播放器打开输出? - How to encode H.264 video using FFmpeg C API and then open the output with a media player? 使用媒体基础从h.264字节流创建MP4容器(附件B)? - Creating an MP4 container from an h.264 byte stream (Annex B), using media foundation? 使用带有vcopy / acopy的libavformat合并H.264 Annex B和AAC流 - Muxing a H.264 Annex B & AAC stream using libavformat with vcopy/acopy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM