我正在尝试使用 the FFmpeg muxing example使用 RTMP 发送内容。
修改示例以向 youtube channel 发送内容时,实时结果不正确:
av_log_set_level(AV_LOG_DEBUG);
avformat_alloc_output_context2(&oc, NULL, "flv", "rtmp://x.rtmp.youtube.com/live2/KEY");
日志似乎很好:[flv @ 0000016CDFB97640] intra_quant_bias = 0 inter_quant_bias = -64
[SWR @ 0000016CDFBD5140] Using s16p internally between filters
Output #0, flv, to 'rtmp://x.rtmp.youtube.com/live2/KEY':
Stream #0:0, 0, 1/30: Video: flv1, 1 reference frame, yuv420p, 256x144 (0x0), 0/1, q=2-31, 400 kb/s, 30 tbn
Stream #0:1, 0, 1/44100: Audio: adpcm_swf, 44100 Hz, stereo, s16, 352 kb/s
[rtmp @ 0000016CDFB63300] No default whitelist set
[tcp @ 0000016CDFB7E780] No default whitelist set
[tcp @ 0000016CDFB7E780] Original list of addresses:
[tcp @ 0000016CDFB7E780] Address 142.250.178.172 port 1935
[tcp @ 0000016CDFB7E780] Interleaved list of addresses:
[tcp @ 0000016CDFB7E780] Address 142.250.178.172 port 1935
[tcp @ 0000016CDFB7E780] Starting connection attempt to 142.250.178.172 port 1935
[tcp @ 0000016CDFB7E780] Successfully connected to 142.250.178.172 port 1935
[rtmp @ 0000016CDFB63300] Handshaking...
[rtmp @ 0000016CDFB63300] Type answer 3
[rtmp @ 0000016CDFB63300] Server version 4.0.0.1
[rtmp @ 0000016CDFB63300] Proto = rtmp, path = /live2/KEY, app = live2, fname = KEY
[rtmp @ 0000016CDFB63300] Window acknowledgement size = 2500000
[rtmp @ 0000016CDFB63300] Max sent, unacked = 57000000
[rtmp @ 0000016CDFB63300] Releasing stream...
[rtmp @ 0000016CDFB63300] FCPublish stream...
[rtmp @ 0000016CDFB63300] Creating stream...
[rtmp @ 0000016CDFB63300] Sending publish command for 'KEY'
在youtube上,问题如下:经过1分20秒的流媒体,时间线长度为10分钟左右,如您所见here .
我的猜测是 youtube 每秒接收超过 25 帧,并且不会丢弃它们。
因此,时间线会增长,创建具有第二个设备的所有帧 1/25 的视频,这与流的实际长度不对应。
如果需要,我可以提供 PTS DTS。
我不确定如何让 AVCodeccontext 等待。
有什么帮助吗?
最佳答案
来自 this有点旧的 rtmp ffmpeg 示例;我用了av_usleep
:
// inside write_frame
/* rescale output packet timestamp values from codec to stream timebase */
av_packet_rescale_ts(pkt, c->time_base, st->time_base);
pkt->stream_index = st->index;
AVRational time_base = st->time_base;
AVRational time_base_q = { 1,AV_TIME_BASE };
int64_t pts_time = av_rescale_q(pkt->dts, time_base, time_base_q);
int64_t now_time = av_gettime() - start_time;
if (pts_time > now_time) {
av_usleep(pts_time - now_time);
}
/* Write the compressed frame to the media file. */
log_packet(fmt_ctx, pkt);
关于c++ - RTMP FFmpeg 复用示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71495817/