简体   繁体   中英

Send H.264 encoded stream through RTMP using FFmpeg

I followed this to encode a sequences images to h.264 video.

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. As I know, the container for the RTMP is 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.

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.

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。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM