<div dir="ltr"><div><br></div><div><br></div><div>Objective:</div><div>To allow regular mpegts options to be used with the rtp_mpegts muxer</div><div><br></div><div>Current issue</div><div>Modified the rtpenc_mpegts.c source code to hardcode the "-mux_rate 8M" option into an AVOption dictionary. This option is passed into the av_write_header (see code #1) call that sets up the context for the mpegts muxer. However, when the application is then run the output gives an ever increasing bitrate (see code #2).</div><div><br></div><div>I have tracked the issue down to the get_pcr command in the mpegtsenc.c code. This call seeks in the mpegts_ctx->pb to get the pcr. This is then used to decide if a pcr or null packet should be entered into the stream. I think the issue is coming about due to the incorrect data in the mpegts_ctx->pb buffer (this is what the get_pcr command is seeking in). However, when I copy the raw mpegts packet into that buffer it als does not work (see code #3 for how I am copying). For reference running the mpegts command on the same input file works correctly (see code #4) as it is correctly muxed.</div><div><br></div><div>I will continue to look into why this may be happening but I am not 100% clear on the reason for the mpegts_ctx->pb object. What does it serve? What is it trying to achieve?</div><div><br></div><div><br></div><div>CODE #1</div><div>Hardcoded change to set the mucrate of the mpegts to 8M</div><div><span style="white-space:pre">     </span>av_dict_set(&d, "muxrate", "8000000", 0);</div><div><br></div><div>    for (i = 0; i < s->nb_streams; i++) {</div><div>        AVStream* st = avformat_new_stream(mpegts_ctx, NULL);</div><div>        if (!st)</div><div>            goto fail;</div><div>        st->time_base           = s->streams[i]->time_base;</div><div>        st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;</div><div>        avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar);</div><div>    }</div><div>    if ((ret = avio_open_dyn_buf(&mpegts_ctx->pb)) < 0)</div><div>        goto fail;</div><div>    if ((ret = avformat_write_header(mpegts_ctx, &d)) < 0)</div><div>        goto fail;</div><div><br></div><div>CODE #</div><div>The input command is </div><div>gdb --args ffmpeg_g -y -re -i remux_test.ts -c copy -muxrate 8M -f rtp_mpegts rtp://<a href="http://127.0.0.1:5000">127.0.0.1:5000</a></div><div><br></div><div>The output from running the above command is like the below; where the bitrate constantly increases and the speed decreases.</div><div>frame=  272 fps= 17 q=-1.0 size=  960935kB time=00:00:05.91 bitrate=1331976.5kbits/s speed=0.361x</div><div><br></div><div>CODE #3</div><div>    if (!chain->mpegts_ctx->pb) {</div><div>        if ((ret = avio_open_dyn_buf(&chain->mpegts_ctx->pb)) < 0)</div><div>            return ret;</div><div>    }</div><div><span style="white-space:pre">  </span>chain->mpegts_ctx->pb->buffer = s->pb->buffer;</div><div><span style="white-space:pre"> </span>chain->mpegts_ctx->pb->buf_ptr_max = s->pb->buf_ptr_max ;</div><div><span style="white-space:pre">      </span>chain->mpegts_ctx->pb->buf_ptr = s->pb->buf_ptr ;</div><div><span style="white-space:pre">      </span>chain->mpegts_ctx->pb->buf_end = s->pb->buf_end;</div><div><span style="white-space:pre">       </span>chain->mpegts_ctx->pb->buffer_size = s->pb->buffer_size;</div><div><span style="white-space:pre">       </span>chain->mpegts_ctx->pb->orig_buffer_size = s->pb->orig_buffer_size;</div><div><span style="white-space:pre">     </span>chain->mpegts_ctx->pb->max_packet_size = s->pb->max_packet_size;</div><div><span style="white-space:pre">       </span></div><div>    if ((ret = av_write_frame(chain->mpegts_ctx, pkt)) < 0)</div><div>        return ret;</div><div><span style="white-space:pre">      </span></div><div>    size = avio_close_dyn_buf(chain->mpegts_ctx->pb, &buf);</div><div>    chain->mpegts_ctx->pb = NULL;</div><div><br></div><div><br></div><div>CODE #4</div><div>gdb --args ffmpeg_g -y -re -i remux_test.ts -c copy -muxrate 8M -f mpegts udp://<a href="http://127.0.0.1:5000">127.0.0.1:5000</a></div><div><br></div>
</div>