FFMPEG streaming RTP: time base not set
You are making settings in a wrong codec context.
The streams created by avformat_new_stream()
have their own internal codec contexts, the one you created with avcodec_alloc_context3()
is unnecessary and has no effect on the workings of avformat_write_header()
.
To set the variables correctly, set them this way:
AVCodec* codec = avcodec_find_encoder(AV_CODEC_ID_H264);
struct AVStream* stream = avformat_new_stream(avctx, codec);
stream->codec->pix_fmt = AV_PIX_FMT_YUV420P;
stream->codec->flags = CODEC_FLAG_GLOBAL_HEADER;
stream->codec->width = WIDTH;
stream->codec->height = HEIGHT;
stream->codec->time_base = (AVRational){1,FPS};
stream->codec->gop_size = FPS;
stream->codec->bit_rate = BITRATE;
That solved this particular problem for me, I added the other answer given here as well, as that's how I have it set, though your method of setting the time_base
probably could have worked too, if you had been talking to the correct codec context.