[英]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.