[Libav-user] How to set mpegts muxrate via API?
Jason Livingston
jettoblack at gmail.com
Mon May 14 00:38:17 CEST 2012
Hello,
When I set the muxrate via ffmpeg CLI, it works fine, so this isn't a
bug. I just can't figure out how to set the same muxrate option via
the APIs.
E.g. this works fine and the muxed rate looks right:
ffmpeg -i inputfile -muxrate 3500000 -vcodec copy -acodec copy output.ts
Log msg from muxer:
[mpegts @ 0x7faf82028400] muxrate 3500000, pcr every 49 pkts, sdt
every 1246, pat/pmt every 249 pkts
Trying to set the same thing via API, and the option setting seems to
stick in the MpegTs private class options (calling av_get_int() for
"muxrate" gives me the intended value back, so it looks like I
succeeded in setting the option value), but the resulting stream is
not muxed at the right rate.
Code:
AVFormatContext *out = NULL;
int mux_rate = 3500000;
char *outfile = "test.ts";
int r;
// Open output file for writing
out = avformat_alloc_context();
assert(out);
out->oformat = av_guess_format(NULL, outfile, NULL); // Guess
output container format based on file extension
assert(out->oformat);
printf("Open output file: %s\nOutput format: %s\n", outfile,
out->oformat->long_name);
// set output muxrate
r = av_opt_set_int(&out->oformat->priv_class, "muxrate", mux_rate,
AV_OPT_SEARCH_CHILDREN);
if (r) {
char errbuf[128];
av_strerror(r, errbuf, 128);
printf("error %s when setting opt muxrate=%"PRId64"\n",
errbuf, mux_rate);
}
// read back muxrate
int64_t res = av_get_int(&out->oformat->priv_class, "muxrate", NULL);
printf("muxrate set to %"PRId64"\n", res);
if (res != mux_rate) {
printf("Warning: output mux rate %"PRId64" doesn't match input
mux rate %"PRId64"\n", res, mux_rate);
}
// open output
r = avio_open2(&out->pb, outfile, AVIO_FLAG_WRITE, NULL, NULL);
if (r) {
printf("err %x\n", r);
return r;
}
I get this log output:
muxrate set to 3500000
[mpegts @ 0x103023c00] muxrate VBR, pcr every 5 pkts, sdt every 200,
pat/pmt every 40 pkts
So the "muxrate VBR" log msg from the muxer seems to indicate that my
muxrate option is not being used.
Any ideas? How does the ffmpeg "-muxrate" option get passed into the muxer?
Thanks!
More information about the Libav-user
mailing list