[bug/patch] MPEG-TS muxer: PCR not in sync with PTS/DTS
On 09/04/2009 07:28 AM, Niobos wrote:
* Changed the calculation of total_bit_rate to be more accurate This still had a bug in it (bits vs bytes thing), which is corrected in the attached version
On 03 Sep 2009, at 12:13, Alexandre Ferrieux wrote:
Just done preliminary tests with your patches and a set-top-box:
- the VBR works but as bitrate increases, the box gets troubled by bursts (loss of picture updates) - the CBR works beautifully at all bitrates
Thanks a lot for this work !
I run my tests in VLC and on iPhone, both work without a glitch; bitrates range from 200kbps to 1.5Mbps.
Thanks a lot for the work, I'll review ASAP.
Hi, Many thanks for this latest patch. This seems to help make TS files created by ffmpeg more compatible with VLC. I have been looking at the calculation of total_bit_rate in the latest update to this patch. I think that I understand the calculation but I am confused by the line total_bit_rate += 4 * total_bit_rate / (TS_PACKET_SIZE-4) + /* TS header size */ 1000 * 8 * sdt_size / SDT_RETRANS_TIME + /* SDT size */ 1000 * 8 * pat_pmt_size / PAT_RETRANS_TIME + /* PAT+PMT size */ 1000 * 8 * 8 / PCR_RETRANS_TIME; /* PCR size */ It is the following part that is causing confusion: 4 * total_bit_rate / (TS_PACKET_SIZE-4) + /* TS header size */ I believe that this is trying to adjust the total_bit_rate to allow for the fact that the stream will be sent as TS packets, and, therefore, will require an extra 4 bytes of data for each 184 bytes in the stream. If this is not the case then please ignore the rest of this post, but I would greatly appreciate an explanation of what the line does. If my understanding is correct this part should be: total_bit_rate * TS_PACKET_SIZE / (TS_PACKET_SIZE-4) + /*TS header size*/ i.e. multiply the stream size by 188/184 to account for 4 extra bytes every TS packet. Alan -------------------------------------------------------------------------- Rosemount Aerospace Limited. Registered Office: Stratford Road, Solihull, West Midlands, B90 4LA. Registered in England No. 02849033. --------------------------------------------------------------------------
On 07 Sep 2009, at 18:05, Stratford, Alan wrote:
I have been looking at the calculation of total_bit_rate in the latest update to this patch. I think that I understand the calculation but I am confused by the line
total_bit_rate += 4 * total_bit_rate / (TS_PACKET_SIZE-4) + /* TS header size */ 1000 * 8 * sdt_size / SDT_RETRANS_TIME + /* SDT size */ 1000 * 8 * pat_pmt_size / PAT_RETRANS_TIME + /* PAT+PMT size */ 1000 * 8 * 8 / PCR_RETRANS_TIME; /* PCR size */
It is the following part that is causing confusion:
4 * total_bit_rate / (TS_PACKET_SIZE-4) + /* TS header size */
I believe that this is trying to adjust the total_bit_rate to allow for the fact that the stream will be sent as TS packets, and, therefore, will require an extra 4 bytes of data for each 184 bytes in the stream. If this is not the case then please ignore the rest of this post, but I would greatly appreciate an explanation of what the line does. Correct
If my understanding is correct this part should be:
total_bit_rate * TS_PACKET_SIZE / (TS_PACKET_SIZE-4) + /*TS header size*/
Also correct, but: total_bit_rate * TS_PACKET_SIZE / (TS_PACKET_SIZE-4) = total_bit_rate * (TS_PACKET_SIZE - 4 + 4 ) / (TS_PACKET_SIZE-4) = total_bit_rate * (1 + 4/(TS_PACKET_SIZE-4) ) = total_bit_rate + 4 * total_bit_rate / (TS_PACKET_SIZE-4) Hence it's exactly equivalent to total_bit_rate += 4 * total_bit_rate / (TS_PACKET_SIZE-4); which is what I used Niobos
On 07 Sep 2009, at 18:05, Stratford, Alan wrote:
I have been looking at the calculation of total_bit_rate in the latest update to this patch. I think that I understand the calculation but I am confused by the line
total_bit_rate += 4 * total_bit_rate / (TS_PACKET_SIZE-4) + /* TS header size */ 1000 * 8 * sdt_size / SDT_RETRANS_TIME + /* SDT size
*/ 1000 * 8 * pat_pmt_size / PAT_RETRANS_TIME + /* PAT+PMT size */ 1000 * 8 * 8 / PCR_RETRANS_TIME; /* PCR size */
It is the following part that is causing confusion:
4 * total_bit_rate / (TS_PACKET_SIZE-4) + /* TS header size */
I believe that this is trying to adjust the total_bit_rate to allow for the fact that the stream will be sent as TS packets, and, therefore, will require an extra 4 bytes of data for each 184 bytes in the stream. If this is not the case then please ignore the rest of this post, but I would greatly appreciate an explanation of what the line does. Correct
If my understanding is correct this part should be:
total_bit_rate * TS_PACKET_SIZE / (TS_PACKET_SIZE-4) + /*TS header size*/
Also correct, but: total_bit_rate * TS_PACKET_SIZE / (TS_PACKET_SIZE-4) = total_bit_rate * (TS_PACKET_SIZE - 4 + 4 ) / (TS_PACKET_SIZE-4) = total_bit_rate * (1 + 4/(TS_PACKET_SIZE-4) ) = total_bit_rate + 4 * total_bit_rate / (TS_PACKET_SIZE-4)
Hence it's exactly equivalent to total_bit_rate += 4 * total_bit_rate / (TS_PACKET_SIZE-4); which is what I used
Niobos
Thanks for the explanation. My algebra skills must be going rusty. However, while I can see that your rearrangement is equivalent I don't see the reason for it. It seems to make it less clear what the calculation does for no obvious gain. I have a couple of further points on the total_bit_rate calculation. 1. It seems that the PCRs are accounted for, but the fact that they contribute to extra TS headers are not. i.e. I think that the extra bytes due to PCRs should be added to total_bit_rate before adjusting it for TS headers. Something like this: total_bit_rate += 1000 * 8 * 8 / PCR_RETRANS_TIME; total_bit_rate += 4 * total_bit_rate / (TS_PACKET_SIZE-4) + 1000 * 8 * sdt_size / SDT_RETRANS_TIME + 1000 * 8 * pat_pmt_size / PAT_RETRANS_TIME; 2. It seems that the stuffing bytes in the last TS packet in each PES are also not accounted for. I don't know how one would account for these as the size would depend on the achieved compression rate. Any ideas? I am very new to MPEG, so please forgive any errors in the above. Again I would greatly appreciate any explanation you can give. Alan _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel -------------------------------------------------------------------------- Rosemount Aerospace Limited. Registered Office: Stratford Road, Solihull, West Midlands, B90 4LA. Registered in England No. 02849033. --------------------------------------------------------------------------
On 09 Sep 2009, at 12:07, Stratford, Alan wrote:
Thanks for the explanation. My algebra skills must be going rusty. However, while I can see that your rearrangement is equivalent I don't see the reason for it. It seems to make it less clear what the calculation does for no obvious gain.
I'll use "my" and "your" version in the list below to indicate the different approaches. Reasons: * To stay close to the original code * My formula can be combined with the other overhead lines since it's an addition; your formula is a multiplication and needs its own statement. * I don't think that "add 4 bytes of TS header ever 184" is unclear. I'm ok with adopting your formula if more people support it.
I have a couple of further points on the total_bit_rate calculation.
1. It seems that the PCRs are accounted for, but the fact that they contribute to extra TS headers are not. i.e. I think that the extra bytes due to PCRs should be added to total_bit_rate before adjusting it for TS headers. Something like this:
total_bit_rate += 1000 * 8 * 8 / PCR_RETRANS_TIME; total_bit_rate += 4 * total_bit_rate / (TS_PACKET_SIZE-4) + 1000 * 8 * sdt_size / SDT_RETRANS_TIME + 1000 * 8 * pat_pmt_size / PAT_RETRANS_TIME;
You are correct, although it hardly matters: 70bps with the current PCR_RETRANS_TIME. Adapted patch (against r19796) in attachment
On 09 Sep 2009, at 14:01, Niobos wrote:
You are correct, although it hardly matters: 70bps with the current PCR_RETRANS_TIME. Adapted patch (against r19796) in attachment <ffmpeg-mpegts-vbr-3.diff>
This thread has been silent for over a week now. What is the status of this patch? Is there anything more I need to do to get this included? Niobos
Hi, On 09/16/2009 11:48 PM, Niobos wrote:
On 09 Sep 2009, at 14:01, Niobos wrote:
You are correct, although it hardly matters: 70bps with the current PCR_RETRANS_TIME. Adapted patch (against r19796) in attachment <ffmpeg-mpegts-vbr-3.diff>
This thread has been silent for over a week now.
What is the status of this patch? Is there anything more I need to do to get this included?
I'll apply it shortly. It would be nice if VBR could be tested a bit more also. -- Baptiste COUDURIER Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA FFmpeg maintainer http://www.ffmpeg.org
Baptiste Coudurier wrote:
Hi,
On 09/16/2009 11:48 PM, Niobos wrote:
On 09 Sep 2009, at 14:01, Niobos wrote:
You are correct, although it hardly matters: 70bps with the current PCR_RETRANS_TIME. Adapted patch (against r19796) in attachment <ffmpeg-mpegts-vbr-3.diff>
This thread has been silent for over a week now.
What is the status of this patch? Is there anything more I need to do to get this included?
I'll apply it shortly. It would be nice if VBR could be tested a bit more also.
FWIW, I'm using the patch in VBR mode rather intensively with live cam streams, and I have no defect to report (on the specific set-top-boxes I'm using), even at -vb 4096k. Kudos to Niobos ! -Alex
On 17 Sep 2009, at 08:48, Niobos wrote:
On 09 Sep 2009, at 14:01, Niobos wrote:
You are correct, although it hardly matters: 70bps with the current PCR_RETRANS_TIME. Adapted patch (against r19796) in attachment <ffmpeg-mpegts-vbr-3.diff>
This thread has been silent for over a week now.
What is the status of this patch? Is there anything more I need to do to get this included?
I reviewed this patch since I needed some additional features: * Bugfix: In VBR mode, the SI-table period was calculated on the muxrate after it had been multiplied by 10. The resulting rates were 10x to slow. * Extra feature: Specifying a negative muxrate on the commandline overwrites the calculated muxrate, but still activates VBR. * I added an additional patch which includes some additional info/ clarification and does not cause any changes in the compiled code. This extra feature is needed to produce a VBR MPEG-TS by remultiplexing a source ("-{a,v}codec copy"), since the bitrates can't be learned from the stearm. Attached patches are against r20080.
On Thu, Oct 01, 2009 at 02:11:29PM +0200, Niobos wrote:
On 17 Sep 2009, at 08:48, Niobos wrote:
On 09 Sep 2009, at 14:01, Niobos wrote:
You are correct, although it hardly matters: 70bps with the current PCR_RETRANS_TIME. Adapted patch (against r19796) in attachment <ffmpeg-mpegts-vbr-3.diff>
This thread has been silent for over a week now.
What is the status of this patch? Is there anything more I need to do to get this included?
I reviewed this patch since I needed some additional features: * Bugfix: In VBR mode, the SI-table period was calculated on the muxrate after it had been multiplied by 10. The resulting rates were 10x to slow. * Extra feature: Specifying a negative muxrate on the commandline overwrites the calculated muxrate, but still activates VBR. * I added an additional patch which includes some additional info/clarification and does not cause any changes in the compiled code.
This extra feature is needed to produce a VBR MPEG-TS by remultiplexing a source ("-{a,v}codec copy"), since the bitrates can't be learned from the stearm.
Attached patches are against r20080. [...]
mpegtsenc.c | 64 ++++++++++++++++++++++++++++++++++++++++++++---------------- options.c | 2 - 2 files changed, 48 insertions(+), 18 deletions(-) 8379b5dc6eca030239c061436c56f32180626ab1 ffmpeg-mpegts-vbr-4.diff Index: libavformat/options.c =================================================================== --- libavformat/options.c (revision 20080) +++ libavformat/options.c (working copy) @@ -41,7 +41,7 @@
static const AVOption options[]={ {"probesize", "set probing size", OFFSET(probesize), FF_OPT_TYPE_INT, 5000000, 32, INT_MAX, D}, -{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E}, +{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, E}, {"packetsize", "set packet size", OFFSET(packet_size), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E}, {"fflags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, D|E, "fflags"}, {"ignidx", "ignore index", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_IGNIDX, INT_MIN, INT_MAX, D, "fflags"},
iam against such hacks, rates are positive values about the rest of the patch, no comment, ive not reviewed it. [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Dictatorship naturally arises out of democracy, and the most aggravated form of tyranny and slavery out of the most extreme liberty. -- Plato
On 01 Oct 2009, at 16:20, Michael Niedermayer wrote:
-{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E}, +{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, E},
iam against such hacks, rates are positive values about the rest of the patch, no comment, ive not reviewed it.
I agree that is is a hack. However, I don't know enough of the ffmpeg-code to know if/where to add an extra option such as -muxvbr or use some sort of -flags variant. What would be the "right" way to activate VBR-muxing? Would it be wise to make VBR the default and set an option for CBR muxing? Niobos
Niobos wrote:
On 01 Oct 2009, at 16:20, Michael Niedermayer wrote:
-{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E}, +{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, E},
iam against such hacks, rates are positive values about the rest of the patch, no comment, ive not reviewed it.
I agree that is is a hack. However, I don't know enough of the ffmpeg-code to know if/where to add an extra option such as -muxvbr or use some sort of -flags variant.
FWIW, adding an option amounts to adding a line in ffmpeg.c (in the OptionDef constant array). Here is one from my sandbox: + { "pcroff", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&pcr_offset}, "offset to PCR in TS mux", "pcr-90kHz-units" }, -Alex
On 02 Oct 2009, at 10:11, Alexandre FERRIEUX - FT/RD/SIRP/ASF/SOFTL wrote:
Niobos wrote:
-{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E}, +{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, E}, However, I don't know enough of the ffmpeg-code to know if/where to add an extra option such as -muxvbr or use some sort of -flags variant.
FWIW, adding an option amounts to adding a line in ffmpeg.c (in the OptionDef constant array). Here is one from my sandbox:
+ { "pcroff", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&pcr_offset}, "offset to PCR in TS mux", "pcr-90kHz-units" },
I also found some options hiding in libavformat/options.c. What should go where? I propose to have VBR-muxing as default and add "-muxcbr" to overwrite this. I'd like to have some support for these change. Is it wise to change the default behaviour (currently, the default is CBR which usually fails because of it)? Niobos
Niobos wrote:
I propose to have VBR-muxing as default and add "-muxcbr" to overwrite this. I'd like to have some support for these change. Is it wise to change the default behaviour (currently, the default is CBR which usually fails because of it)?
My selfish position is that since CBR makes little sense on IP, let VBR be the default. Counter-arguments welcome though. -Alex
On Fri, Oct 02, 2009 at 08:50:32AM +0200, Niobos wrote:
On 01 Oct 2009, at 16:20, Michael Niedermayer wrote:
-{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E}, +{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, E},
iam against such hacks, rates are positive values about the rest of the patch, no comment, ive not reviewed it.
I agree that is is a hack. However, I don't know enough of the ffmpeg-code to know if/where to add an extra option such as -muxvbr or use some sort of -flags variant.
you would have to add max/min_muxrate like muxrate if there is some need for that, (cbr would be the special case of min==max). [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB He who knows, does not speak. He who speaks, does not know. -- Lao Tsu
Hi Niobos, Niobos wrote:
I reviewed this patch since I needed some additional features: * Bugfix: In VBR mode, the SI-table period was calculated on the muxrate after it had been multiplied by 10. The resulting rates were 10x to slow. * Extra feature: Specifying a negative muxrate on the commandline overwrites the calculated muxrate, but still activates VBR. * I added an additional patch which includes some additional info/clarification and does not cause any changes in the compiled code.
This extra feature is needed to produce a VBR MPEG-TS by remultiplexing a source ("-{a,v}codec copy"), since the bitrates can't be learned from the stearm.
Attached patches are against r20080.
As usual I tested your update. Indeed the fix of the SI table frequency has a nice effect on hardware decoders :-) Now I observed a regression wrt your previous patches: when muxing an audio-only TS, the PCR is wrong by a large factor (between 4 and 6 times too slow). When muxing video only or both, it is correct. -Alex
(resending, not sure the intended dest got it ;-) Hi Niobos,
Niobos wrote:
I reviewed this patch since I needed some additional features: * Bugfix: In VBR mode, the SI-table period was calculated on the muxrate after it had been multiplied by 10. The resulting rates were 10x to slow. * Extra feature: Specifying a negative muxrate on the commandline overwrites the calculated muxrate, but still activates VBR. * I added an additional patch which includes some additional info/clarification and does not cause any changes in the compiled code.
This extra feature is needed to produce a VBR MPEG-TS by remultiplexing a source ("-{a,v}codec copy"), since the bitrates can't be learned from the stearm.
Attached patches are against r20080.
As usual I tested your update. Indeed the fix of the SI table frequency has a nice effect on hardware decoders :-) Now I observed a regression wrt your previous patches: when muxing an audio-only TS, the PCR is wrong by a large factor (between 4 and 6 times too slow). When muxing video only or both, it is correct. -Alex
Alexandre Ferrieux wrote:
(resending, not sure the intended dest got it ;-)
Hi Niobos,
Niobos wrote:
I reviewed this patch since I needed some additional features: * Bugfix: In VBR mode, the SI-table period was calculated on the muxrate after it had been multiplied by 10. The resulting rates were 10x to slow. * Extra feature: Specifying a negative muxrate on the commandline overwrites the calculated muxrate, but still activates VBR. * I added an additional patch which includes some additional info/clarification and does not cause any changes in the compiled code.
This extra feature is needed to produce a VBR MPEG-TS by remultiplexing a source ("-{a,v}codec copy"), since the bitrates can't be learned from the stearm.
Attached patches are against r20080.
As usual I tested your update. Indeed the fix of the SI table frequency has a nice effect on hardware decoders :-)
Now I observed a regression wrt your previous patches: when muxing an audio-only TS, the PCR is wrong by a large factor (between 4 and 6 times too slow). When muxing video only or both, it is correct.
-Alex
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel Not to interfere, maybe off-topic, not intended anyway, I think it's relevant.
After applying the patch, ffmpeg-mpegts-vbr-4.diff, doing ffmpeg -i 86240frames-h264.ts -an -vcodec copy -f rawvideo 86240frames.h264 produces the raw frames where last line is: frame=172480 fps=2285 q=-1.0 Lsize= 3996695kB time=3449.58 bitrate=9491.3kbits/s Notice frame vs. field problem. ffmpeg -i 86240frames.h264 -an -vcodec copy -f mpegts new.ts now produces frame=172480 fps=1393 q=-1.0 Lsize= 7371403kB time=3449.62 bitrate=17505.3kbits/s Notice size/bitrate increase FFmpeg version SVN-r20199, Copyright (c) 2000-2009 Fabrice Bellard, et al. built on Oct 16 2009 16:18:11 with gcc 4.2.2 20070909 (prerelease) (4.2.2-0.RC.1mdv2008.0) configuration: --prefix=/usr --enable-libx264 --enable-libxvid --enable-gpl --enable-libfaac --enable-libmp3lame --enable-pthreads --disable-ffserver --enable-libfaad --disable-ffplay --as=yasm --enable-nonfree libavutil 50. 3. 0 / 50. 3. 0 libavcodec 52.36. 0 / 52.36. 0 libavformat 52.39. 0 / 52.39. 0 libavdevice 52. 2. 0 / 52. 2. 0 libswscale 0. 7. 1 / 0. 7. 1
On 16 Oct 2009, at 16:56, belcampo wrote:
After applying the patch, ffmpeg-mpegts-vbr-4.diff, doing ffmpeg -i 86240frames-h264.ts -an -vcodec copy -f rawvideo 86240frames.h264 produces the raw frames where last line is: frame=172480 fps=2285 q=-1.0 Lsize= 3996695kB time=3449.58 bitrate=9491.3kbits/s
Notice frame vs. field problem.
ffmpeg -i 86240frames.h264 -an -vcodec copy -f mpegts new.ts now produces frame=172480 fps=1393 q=-1.0 Lsize= 7371403kB time=3449.62 bitrate=17505.3kbits/s
Notice size/bitrate increase
Is this a pure cosmetic problem? or is there a difference in the output file? I'm not a specialist at this, but I don't think this has anything to do with the MPEG-TS muxer... From how I understand the code, the muxer is simply handed a series of bytes to store. Greets, Niobos
Niobos wrote:
On 16 Oct 2009, at 16:56, belcampo wrote:
After applying the patch, ffmpeg-mpegts-vbr-4.diff, doing ffmpeg -i 86240frames-h264.ts -an -vcodec copy -f rawvideo 86240frames.h264 produces the raw frames where last line is: frame=172480 fps=2285 q=-1.0 Lsize= 3996695kB time=3449.58 bitrate=9491.3kbits/s
Notice frame vs. field problem.
ffmpeg -i 86240frames.h264 -an -vcodec copy -f mpegts new.ts now produces frame=172480 fps=1393 q=-1.0 Lsize= 7371403kB time=3449.62 bitrate=17505.3kbits/s
Notice size/bitrate increase
Is this a pure cosmetic problem? or is there a difference in the output file? No it's NOT cosmetic only. File-size, also in the real world, grows from Lsize= 3996695kB to Lsize= 7371403kB
I'm not a specialist at this, but I don't think this has anything to do with the MPEG-TS muxer... From how I understand the code, the muxer is simply handed a series of bytes to store.
Greets, Niobos_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
On 19 Oct 2009, at 10:46, belcampo wrote:
Niobos wrote:
On 16 Oct 2009, at 16:56, belcampo wrote:
After applying the patch, ffmpeg-mpegts-vbr-4.diff, doing ffmpeg -i 86240frames-h264.ts -an -vcodec copy -f rawvideo 86240frames.h264 produces the raw frames where last line is: frame=172480 fps=2285 q=-1.0 Lsize= 3996695kB time=3449.58 bitrate=9491.3kbits/s
Notice frame vs. field problem.
ffmpeg -i 86240frames.h264 -an -vcodec copy -f mpegts new.ts now produces frame=172480 fps=1393 q=-1.0 Lsize= 7371403kB time=3449.62 bitrate=17505.3kbits/s
Notice size/bitrate increase Is this a pure cosmetic problem? or is there a difference in the output file? No it's NOT cosmetic only. File-size, also in the real world, grows from Lsize= 3996695kB to Lsize= 7371403kB
That points more "away" from the muxer: As far as I understand the muxer-code, it only puts a header/trailer around the bytes it gets from the rest of the code. To confirm this guess, could you retry the same test but with another codec (eg mpeg2)? Greets, Niobos
On 19 Oct 2009, at 10:46, belcampo wrote:
Niobos wrote:
On 16 Oct 2009, at 16:56, belcampo wrote:
After applying the patch, ffmpeg-mpegts-vbr-4.diff, doing ffmpeg -i 86240frames-h264.ts -an -vcodec copy -f rawvideo 86240frames.h264 produces the raw frames where last line is: frame=172480 fps=2285 q=-1.0 Lsize= 3996695kB time=3449.58 bitrate=9491.3kbits/s
Notice frame vs. field problem.
ffmpeg -i 86240frames.h264 -an -vcodec copy -f mpegts new.ts now produces frame=172480 fps=1393 q=-1.0 Lsize= 7371403kB time=3449.62 bitrate=17505.3kbits/s
Notice size/bitrate increase Is this a pure cosmetic problem? or is there a difference in the output file? No it's NOT cosmetic only. File-size, also in the real world, grows from Lsize= 3996695kB to Lsize= 7371403kB
That points more "away" from the muxer: As far as I understand the muxer-code, it only puts a header/trailer around the bytes it gets from the rest of the code.
To confirm this guess, could you retry the same test but with another codec (eg mpeg2)?
Niobos wrote: source.mpg incl. audio-track is 1911772564bytes ffmpeg -i source.mpg -an -vcodec copy -f mpegts result.ts result.ts is 2602941968bytes -rw-r--r-- 1 root root 1911772564 2009-10-19 04:50 tv/29014_20091019041500.mpg -rw-r--r-- 1 mythtv users 2602941968 2009-10-19 15:45 tv/29014_20091019041500.ts
Greets, Niobos _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
On 16 Oct 2009, at 15:37, Alexandre Ferrieux wrote: > (resending, not sure the intended dest got it ;-) I did get it, but had no access to my email at that time > As usual I tested your update. Indeed the fix of the SI table > frequency > has a nice effect on hardware decoders :-) That's good news > Now I observed a regression wrt your previous patches: when muxing an > audio-only TS, the PCR is wrong by a large factor (between 4 and 6 > times > too slow). When muxing video only or both, it is correct. Can you provide me with: * The command line you used * The characteristics of the input file (especially number of channels, since there is a filed bug about this) Thx, Niobos
Niobos wrote:
On 16 Oct 2009, at 15:37, Alexandre Ferrieux wrote:
Now I observed a regression wrt your previous patches: when muxing an audio-only TS, the PCR is wrong by a large factor (between 4 and 6 times too slow). When muxing video only or both, it is correct.
Can you provide me with: * The command line you used
ffmpeg.r20212vbr -i file.wav -vn -ar 44100 file.ts
* The characteristics of the input file (especially number of channels, since there is a filed bug about this)
I've done this with both mono and stereo wav files, same result. Below are the details with one of each kind. On these small files the PCR bug is even stronger (a ratio nearing 9). FFmpeg versions: 20212vbr is your latest patch; 19754vbr is your previous one. -Alex (1) =========================== Stereo ==> ffmpeg.r20212vbr -i ab.wav Input #0, wav, from 'ab.wav': Duration: 00:00:04.86, bitrate: 128 kb/s Stream #0.0: Audio: pcm_alaw, 8000 Hz, 2 channels, s16, 128 kb/s ==> ffmpeg.r20212vbr -i ab.wav -vn -ar 44100 -y ab.20212.ts FFmpeg version SVN-r20212, Copyright (c) 2000-2009 Fabrice Bellard, et al. built on Oct 12 2009 18:28:32 with gcc 3.4.6 20060404 (Red Hat 3.4.6-10) configuration: --enable-libx264 --enable-gpl --disable-demuxer=v4l --disable-demuxer=v4l2 --disable-indev=v4l --disable-indev=v4l2 libavutil 50. 3. 0 / 50. 3. 0 libavcodec 52.37. 0 / 52.37. 0 libavformat 52.39. 0 / 52.39. 0 libavdevice 52. 2. 0 / 52. 2. 0 libswscale 0. 7. 1 / 0. 7. 1 [wav @ 0x8dd2420]max_analyze_duration reached Input #0, wav, from 'ab.wav': Duration: 00:00:04.86, bitrate: 128 kb/s Stream #0.0: Audio: pcm_alaw, 8000 Hz, 2 channels, s16, 128 kb/s [mpegts @ 0x8ddba80]calculated bitrate 104114bps, muxrate 1041140bps, sdt every 34, pat/pmt every 6 pkts Output #0, mpegts, to 'ab.20212.ts': Stream #0.0: Audio: mp2, 44100 Hz, 2 channels, s16, 64 kb/s Stream mapping: Stream #0.0 -> #0.0 Press [q] to stop encoding size= 57kB time=4.88 bitrate= 95.4kbits/s video:0kB audio:38kB global headers:0kB muxing overhead 49.133806% ==> ffmpeg.r19754vbr -i ab.wav -vn -ar 44100 -y ab.19754.ts FFmpeg version SVN-r19754, Copyright (c) 2000-2009 Fabrice Bellard, et al. configuration: --disable-demuxer=v4l --disable-demuxer=v4l2 --disable-indev=v4l --disable-indev=v4l2 libavutil 50. 3. 0 / 50. 3. 0 libavcodec 52.35. 0 / 52.35. 0 libavformat 52.38. 0 / 52.38. 0 libavdevice 52. 2. 0 / 52. 2. 0 libswscale 0. 7. 1 / 0. 7. 1 built on Sep 3 2009 16:01:15, gcc: 3.4.6 20060404 (Red Hat 3.4.6-10) Input #0, wav, from 'ab.wav': Duration: 00:00:04.86, bitrate: 128 kb/s Stream #0.0: Audio: pcm_alaw, 8000 Hz, 2 channels, s16, 128 kb/s [mpegts @ 0x9940aa0]calculated bitrate 104044bps, muxrate 1040440bps, sdt every 345, pat/pmt every 69 pkts Output #0, mpegts, to 'ab.19754.ts': Stream #0.0: Audio: mp2, 44100 Hz, 2 channels, s16, 64 kb/s Stream mapping: Stream #0.0 -> #0.0 Press [q] to stop encoding size= 58kB time=4.88 bitrate= 97.0kbits/s video:0kB audio:38kB global headers:0kB muxing overhead 51.539190% ==> PCR analysis: ab.20212.ts: delta PCR == 19890 ab.19754.ts: delta PCR == 182975 (2) ============================= Mono ==> ffmpeg.r20212vbr -i a.wav Input #0, wav, from 'a.wav': Duration: 00:00:06.12, bitrate: 64 kb/s Stream #0.0: Audio: pcm_alaw, 8000 Hz, 1 channels, s16, 64 kb/s ==> ffmpeg.r20212vbr -i a.wav -vn -ar 44100 -y a.20212.ts FFmpeg version SVN-r20212, Copyright (c) 2000-2009 Fabrice Bellard, et al. built on Oct 12 2009 18:28:32 with gcc 3.4.6 20060404 (Red Hat 3.4.6-10) configuration: --enable-libx264 --enable-gpl --disable-demuxer=v4l --disable-demuxer=v4l2 --disable-indev=v4l --disable-indev=v4l2 libavutil 50. 3. 0 / 50. 3. 0 libavcodec 52.37. 0 / 52.37. 0 libavformat 52.39. 0 / 52.39. 0 libavdevice 52. 2. 0 / 52. 2. 0 libswscale 0. 7. 1 / 0. 7. 1 [wav @ 0xa8b0420]max_analyze_duration reached Input #0, wav, from 'a.wav': Duration: 00:00:06.12, bitrate: 64 kb/s Stream #0.0: Audio: pcm_alaw, 8000 Hz, 1 channels, s16, 64 kb/s [mpegts @ 0xa8b9a80]calculated bitrate 104114bps, muxrate 1041140bps, sdt every 34, pat/pmt every 6 pkts Output #0, mpegts, to 'a.20212.ts': Stream #0.0: Audio: mp2, 44100 Hz, 1 channels, s16, 64 kb/s Stream mapping: Stream #0.0 -> #0.0 Press [q] to stop encoding size= 72kB time=6.14 bitrate= 95.5kbits/s video:0kB audio:48kB global headers:0kB muxing overhead 49.297495% ==> ffmpeg.r19754vbr -i a.wav -vn -ar 44100 -y a.19754.ts FFmpeg version SVN-r19754, Copyright (c) 2000-2009 Fabrice Bellard, et al. configuration: --disable-demuxer=v4l --disable-demuxer=v4l2 --disable-indev=v4l --disable-indev=v4l2 libavutil 50. 3. 0 / 50. 3. 0 libavcodec 52.35. 0 / 52.35. 0 libavformat 52.38. 0 / 52.38. 0 libavdevice 52. 2. 0 / 52. 2. 0 libswscale 0. 7. 1 / 0. 7. 1 built on Sep 3 2009 16:01:15, gcc: 3.4.6 20060404 (Red Hat 3.4.6-10) Input #0, wav, from 'a.wav': Duration: 00:00:06.12, bitrate: 64 kb/s Stream #0.0: Audio: pcm_alaw, 8000 Hz, 1 channels, s16, 64 kb/s [mpegts @ 0xa934aa0]calculated bitrate 104044bps, muxrate 1040440bps, sdt every 345, pat/pmt every 69 pkts Output #0, mpegts, to 'a.19754.ts': Stream #0.0: Audio: mp2, 44100 Hz, 1 channels, s16, 64 kb/s Stream mapping: Stream #0.0 -> #0.0 Press [q] to stop encoding size= 73kB time=6.14 bitrate= 97.5kbits/s video:0kB audio:48kB global headers:0kB muxing overhead 52.360008% ==> PCR analysis: a.20212.ts: delta PCR == 25090 a.19754.ts: delta PCR == 233610
On 19 Oct 2009, at 09:50, Alexandre FERRIEUX - FT/RD/SIRP/ASF/SOFTL wrote:
Niobos wrote:
On 16 Oct 2009, at 15:37, Alexandre Ferrieux wrote:
Now I observed a regression wrt your previous patches: when muxing an audio-only TS, the PCR is wrong by a large factor (between 4 and 6 times too slow). When muxing video only or both, it is correct.
Can you provide me with: * The command line you used
ffmpeg.r20212vbr -i file.wav -vn -ar 44100 file.ts
* The characteristics of the input file (especially number of channels, since there is a filed bug about this)
I've done this with both mono and stereo wav files, same result. Below are the details with one of each kind. On these small files the PCR bug is even stronger (a ratio nearing 9).
I reviewed the differences between (my) version 3 and 4 of the patch and found the source of the difference, which is a factor 10. However, I think the _new_ version is correct, while the old version was "too slow". Although it should happen equally with Video and Audio +video...
v4: [mpegts @ 0x8ddba80]calculated bitrate 104114bps, muxrate 1041140bps, sdt every 34, pat/pmt every 6 pkts
v3: [mpegts @ 0x9940aa0]calculated bitrate 104044bps, muxrate 1040440bps, sdt every 345, pat/pmt every 69 pkts
This also illustrates that factor 10: PAT is inserted every 100ms; which is calculated correctly in the new version (86ms in this case), but not in the old version (996ms). The PCR is calculated in the exact same way and I didn't change the rest of the code in this patch. Could you try this regression between the unpatched ffmpeg and the version 4? Greets, Niobos
Niobos wrote:
On 19 Oct 2009, at 09:50, Alexandre FERRIEUX - FT/RD/SIRP/ASF/SOFTL wrote:
Niobos wrote:
On 16 Oct 2009, at 15:37, Alexandre Ferrieux wrote:
Now I observed a regression wrt your previous patches: when muxing an audio-only TS, the PCR is wrong by a large factor (between 4 and 6 times too slow). When muxing video only or both, it is correct.
Can you provide me with: * The command line you used
ffmpeg.r20212vbr -i file.wav -vn -ar 44100 file.ts
* The characteristics of the input file (especially number of channels, since there is a filed bug about this)
I've done this with both mono and stereo wav files, same result. Below are the details with one of each kind. On these small files the PCR bug is even stronger (a ratio nearing 9).
I reviewed the differences between (my) version 3 and 4 of the patch and found the source of the difference, which is a factor 10. However, I think the _new_ version is correct, while the old version was "too slow". Although it should happen equally with Video and Audio+video...
Well, one fact is that the old one plays perfectly in hardware decoders, the new one doesn't ! Also, look at the delta-PCR values I provided: can you tell me which ones make sense given the original sound's duration ? Stereo sound, 4.86s: ab.20212.ts: delta PCR == 19890 ab.19754.ts: delta PCR == 182975 Mono sound, 6.12s: a.20212.ts: delta PCR == 25090 a.19754.ts: delta PCR == 233610 (these "delta" are just the difference between the high 33 bits of PCR in first and last packet with adaptation field.)
v4: [mpegts @ 0x8ddba80]calculated bitrate 104114bps, muxrate 1041140bps, sdt every 34, pat/pmt every 6 pkts
v3: [mpegts @ 0x9940aa0]calculated bitrate 104044bps, muxrate 1040440bps, sdt every 345, pat/pmt every 69 pkts
This also illustrates that factor 10: PAT is inserted every 100ms; which is calculated correctly in the new version (86ms in this case), but not in the old version (996ms). The PCR is calculated in the exact same way and I didn't change the rest of the code in this patch.
Could you try this regression between the unpatched ffmpeg and the version 4?
Yes. Results below (20212 == unpatched) for the stereo file (ab) above: ab.20212.ts: delta PCR == 342432 -> very jerky ab.20212vbr.ts: delta PCR == 19890 -> no sound ab.19754vbr.ts: delta PCR == 182975 -> perfect -Alex
Alexandre Ferrieux wrote:
ffmpeg.r20212vbr -i file.wav -vn -ar 44100 file.ts
... Could you try this regression between the unpatched ffmpeg and the version 4?
Yes. Results below (20212 == unpatched) for the stereo file (ab) above:
ab.20212.ts: delta PCR == 342432 -> very jerky ab.20212vbr.ts: delta PCR == 19890 -> no sound ab.19754vbr.ts: delta PCR == 182975 -> perfect
-Alex
Alex, It looks to me like the the first entry ("very jerky") is the closest to being correct. If the clip is 4.8 seconds, it should give a delta of about 430000 (= 4.8 * 90000). Niobos, I've been testing your patch, and see two major problems with the transport stream that is created by ffmpeg. 1) The first problem (which you did not cause) is that st->codec->bit_rate is 0 for some streams. This means the container bitrate estimate is completely wrong, and therefore the PCR values inserted are completely wrong. In my local copy of the code, I hard-fail if st->codec->bit_rate is 0, and suggest that the user use '-muxrate n' to specify the container bitrate. 2) The second problem (which may be what is happening above) is that PCR output gets priority over null-packet insertion. This causes PES packets on the pcr_pid to have a (DTS-PCR) much, much bigger than it should be. Effectively, ts->max_delay is ignored. My solution was to check for this case, and generate pcr_pid packets with no pes payload (i.e. the adaptation_field_length is 183.) Thanks for your efforts on the mpeg muxer. -- Mike Scheutzow scheutzow at alcatel-lucent.com
Mike Scheutzow wrote:
Alexandre Ferrieux wrote:
ffmpeg.r20212vbr -i file.wav -vn -ar 44100 file.ts
... Could you try this regression between the unpatched ffmpeg and the version 4?
Yes. Results below (20212 == unpatched) for the stereo file (ab) above:
ab.20212.ts: delta PCR == 342432 -> very jerky ab.20212vbr.ts: delta PCR == 19890 -> no sound ab.19754vbr.ts: delta PCR == 182975 -> perfect
-Alex
Alex,
It looks to me like the the first entry ("very jerky") is the closest to being correct. If the clip is 4.8 seconds, it should give a delta of about 430000 (= 4.8 * 90000).
Oh, thanks for pointing that out. I now realize that all the PCR values I am displaying are actually the high 32 bits of the 33 (for obvious convenience reasons), so they are scaled by 1/2. IOW, they stick to a 45kHz clock. In that corrected view, the one that is closest to truth is 182975 (corresponding to 4.06 seconds). (which is consistent with the fact that it plays perfectly !) As to the missing ~0.7s, I notice that by running ffmpeg -i again on any of the three generated TS, I get: Duration: 00:00:04.78, start: 0.700000, ... This "start 0.7" seems to account for the missing delta PCR. No idea where it comes from though. -Alex
Attached is a patch for the MPEG-TS muxer which makes it generate an accurate Constant Bitrate transport stream. This requires null packet insertion so that the PCR values are correct. This patch incorporates the work done by Niobos in ffmpeg-mpegts-vbr-4.diff, and also includes the follow-on fix I suggested to him. This patch does not solve all the problems I'm aware of with the ffmpeg mpegts muxer. In particular, there are still situations where the estimated bitrate is too small. For example, it is wrong for H.264 video streams, and for audio-only streams. Those problems are separate bugs. For now, the -muxrate option can be used with these type of input streams. Comments? -- Mike Scheutzow scheutzow at alcatel-lucent.com
Mike Scheutzow wrote:
Attached is a patch for the MPEG-TS muxer which makes it generate an accurate Constant Bitrate transport stream. This requires null packet insertion so that the PCR values are correct.
The above patch was submitted 5 days ago. I was expecting discussion from at least the mpeg-ts mux maintainer? -- Mike Scheutzow
Hi, On 10/27/2009 02:28 PM, Mike Scheutzow wrote:
Mike Scheutzow wrote:
Attached is a patch for the MPEG-TS muxer which makes it generate an accurate Constant Bitrate transport stream. This requires null packet insertion so that the PCR values are correct.
The above patch was submitted 5 days ago. I was expecting discussion from at least the mpeg-ts mux maintainer?
Yes, I'm on it. -- Baptiste COUDURIER Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA FFmpeg maintainer http://www.ffmpeg.org
Hi, On 10/22/2009 12:51 PM, Mike Scheutzow wrote:
Attached is a patch for the MPEG-TS muxer which makes it generate an accurate Constant Bitrate transport stream. This requires null packet insertion so that the PCR values are correct.
This patch incorporates the work done by Niobos in ffmpeg-mpegts-vbr-4.diff, and also includes the follow-on fix I suggested to him.
This patch does not solve all the problems I'm aware of with the ffmpeg mpegts muxer.
In particular, there are still situations where the estimated bitrate is too small. For example, it is wrong for H.264 video streams, and for audio-only streams. Those problems are separate bugs. For now, the -muxrate option can be used with these type of input streams.
Comments?
-- Mike Scheutzow scheutzow at alcatel-lucent.com
mpeg-mux-cbr-v1.patch
Index: libavformat/mpegtsenc.c =================================================================== --- libavformat/mpegtsenc.c (revision 20231) +++ libavformat/mpegtsenc.c (working copy) @@ -384,7 +384,7 @@ MpegTSService *service; AVStream *st; AVMetadataTag *title; - int i, total_bit_rate; + int i, total_bit_rate, nb_pkt; const char *service_name; uint64_t sdt_size, pat_pmt_size, pos;
@@ -448,15 +448,6 @@ service->pcr_pid = ts_st->pid; }
- if (total_bit_rate<= 8 * 1024) - total_bit_rate = 8 * 1024; - service->pcr_packet_period = (total_bit_rate * PCR_RETRANS_TIME) / - (TS_PACKET_SIZE * 8 * 1000); - ts->sdt_packet_period = (total_bit_rate * SDT_RETRANS_TIME) / - (TS_PACKET_SIZE * 8 * 1000); - ts->pat_packet_period = (total_bit_rate * PAT_RETRANS_TIME) / - (TS_PACKET_SIZE * 8 * 1000); - ts->mux_rate = 1; // avoid div by 0
/* write info at the start of the file, so that it will be fast to @@ -471,23 +462,36 @@ } pat_pmt_size = url_ftell(s->pb) - pos;
- total_bit_rate += - total_bit_rate * 4 / TS_PACKET_SIZE + /* TS header size */ - SDT_RETRANS_TIME * 8 * sdt_size / 1000 + /* SDT size */ - PAT_RETRANS_TIME * 8 * pat_pmt_size / 1000 + /* PAT+PMT size */ - PCR_RETRANS_TIME * 8 * 8 / 1000; /* PCR size */ + if (total_bit_rate<= 8 * 1024) + total_bit_rate = 8 * 1024;
- av_log(s, AV_LOG_DEBUG, "muxrate %d freq sdt %d pat %d\n", - total_bit_rate, ts->sdt_packet_period, ts->pat_packet_period); + total_bit_rate += 1000 * 8 * 8 / PCR_RETRANS_TIME; /* PCR size */ + total_bit_rate += 4 * total_bit_rate / (TS_PACKET_SIZE-4) + /* TS header size */ + 1000 * 8 * sdt_size / SDT_RETRANS_TIME + /* SDT size */ + 1000 * 8 * pat_pmt_size / PAT_RETRANS_TIME; /* PAT+PMT size */
I think TS header size must be added first, then PCR, then SDT/PAT. Let's compute the bitrate correctly :)
[...]
+ // want to output a PCR as soon as possible + service->pcr_packet_count = service->pcr_packet_period;
Ok.
+ av_log(s, AV_LOG_INFO, "calculated bitrate %dbps, muxrate %dbps, sdt every %d, pat/pmt every %d pkts\n", + total_bit_rate, ts->mux_rate, ts->sdt_packet_period, ts->pat_packet_period); + + // calc current pcr value using new ts->mux_rate (first ts pkt is pcr=0) + nb_pkt = (sdt_size + pat_pmt_size) / TS_PACKET_SIZE; + ts->cur_pcr = (nb_pkt * TS_PACKET_SIZE * 8 * 90000LL) / ts->mux_rate;
This should not be needed. cur_pcr is already adjusted in write_pat and write_pmt. That's why cur_pcr is adjusted below in the code.
[...]
+/* Write a single null transport stream packet */ +static void mpegts_insert_null_packet( AVFormatContext *s )
No space after '(' and before ')', this applies to the whole patch.
[...]
+ +/* Add a pes header to the front of payload, and segment into an integer number of + * ts packets. The final ts packet is padded using an over-sized adaptation header + * to exactly fill the last ts packet. + * NOTE: 'payload' contains a complete PES payload. + */ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, const uint8_t *payload, int payload_size, int64_t pts, int64_t dts) @@ -545,6 +602,7 @@ int val, is_start, len, header_len, write_pcr, private_code, flags; int afc_len, stuffing_len; int64_t pcr = -1; /* avoid warning */ + int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE);
is_start = 1; while (payload_size> 0) { @@ -560,6 +618,18 @@ } }
+ if ( dts != AV_NOPTS_VALUE&& (dts - (int64_t)ts->cur_pcr)> delay ) { + + /* pcr insert gets priority over null packet insert */ + if ( write_pcr ) { + mpegts_insert_pcr_only(s, st); + } else { + mpegts_insert_null_packet(s); + } + + continue; /* recalculate write_pcr and possibly retransmit si_info */ + } +
Can't pcr be written along with data ? Maybe something like: if (!write_pcr && dts != AV_NOPTS_VALUE && dts - .. > delay) { mpegts_insert_null_packet(s); ts_st->service->pcr_packet_count++; continue; }
/* prepare packet header */ q = buf; *q++ = 0x47; @@ -709,7 +779,7 @@ uint8_t *buf= pkt->data; uint8_t *data= NULL; MpegTSWriteStream *ts_st = st->priv_data; - const uint64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE); + const int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE);
Left over ? [...] -- Baptiste COUDURIER Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA FFmpeg maintainer http://www.ffmpeg.org
Baptiste Coudurier wrote:
I think TS header size must be added first, then PCR, then SDT/PAT. Let's compute the bitrate correctly :)
Yes, you're right. Good catch.
+ // calc current pcr value using new ts->mux_rate (first ts pkt is pcr=0) + nb_pkt = (sdt_size + pat_pmt_size) / TS_PACKET_SIZE; + ts->cur_pcr = (nb_pkt * TS_PACKET_SIZE * 8 * 90000LL) / ts->mux_rate;
This should not be needed. cur_pcr is already adjusted in write_pat and write_pmt. That's why cur_pcr is adjusted below in the code.
Yes, now I understand why that adjustment works.
+/* Write a single null transport stream packet */ +static void mpegts_insert_null_packet( AVFormatContext *s )
No space after '(' and before ')', this applies to the whole patch.
Spaces removed.
+ if ( dts != AV_NOPTS_VALUE&& (dts - (int64_t)ts->cur_pcr)> delay ) { + + /* pcr insert gets priority over null packet insert */ + if ( write_pcr ) { + mpegts_insert_pcr_only(s, st); + } else { + mpegts_insert_null_packet(s); + } + + continue; /* recalculate write_pcr and possibly retransmit si_info */ + } +
Can't pcr be written along with data ?
Maybe something like:
if (!write_pcr && dts != AV_NOPTS_VALUE && dts - .. > delay) { mpegts_insert_null_packet(s); ts_st->service->pcr_packet_count++; continue; }
No, the situation being handled is that (dts-pcr) exceeds max_delay. When this occurs, the correct behavior is to output a PCR without outputting any video pes data. This situation occurs when multiple small video frames arrive at the muxer, where 'small' means the frame bitrate is less than the average bitrate allocated to that stream in the muxer.
- const uint64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE); + const int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE);
Left over ?
change removed. v2 of the patch is attached. -- Mike Scheutzow
Mike Scheutzow wrote:
v2 of the patch is attached.
-- Mike Scheutzow
It has been 17 days since I submitted a modified patch to address the comments from Baptiste. Seven days ago I pinged. How should I interpret the fact that there has been no response of any kind? Mike Scheutzow
On 11/16/2009 07:59 AM, Mike Scheutzow wrote:
Mike Scheutzow wrote:
v2 of the patch is attached.
-- Mike Scheutzow
It has been 17 days since I submitted a modified patch to address the comments from Baptiste.
Seven days ago I pinged.
How should I interpret the fact that there has been no response of any kind?
That I was busy and that I missed the ping. Sorry about that, and thanks for your help. I'll review it ASAP. -- Baptiste COUDURIER Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA FFmpeg maintainer http://www.ffmpeg.org
On Wed, Dec 9, 2009 at 22:43, Baptiste Coudurier < baptiste.coudurier at gmail.com> wrote:
On 11/16/2009 07:59 AM, Mike Scheutzow wrote:
Mike Scheutzow wrote:
v2 of the patch is attached.
-- Mike Scheutzow
It has been 17 days since I submitted a modified patch to address the comments from Baptiste.
Seven days ago I pinged.
How should I interpret the fact that there has been no response of any kind?
That I was busy and that I missed the ping. Sorry about that, and thanks for your help. I'll review it ASAP.
-- Baptiste COUDURIER Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA FFmpeg maintainer http://www.ffmpeg.org _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
ping? right now TS muxing in ffmpeg is broken...
On 01/13/2010 01:23 AM, aviad rozenhek wrote:
On Wed, Dec 9, 2009 at 22:43, Baptiste Coudurier< baptiste.coudurier at gmail.com> wrote:
On 11/16/2009 07:59 AM, Mike Scheutzow wrote:
Mike Scheutzow wrote:
v2 of the patch is attached.
-- Mike Scheutzow
It has been 17 days since I submitted a modified patch to address the comments from Baptiste.
Seven days ago I pinged.
How should I interpret the fact that there has been no response of any kind?
That I was busy and that I missed the ping. Sorry about that, and thanks for your help. I'll review it ASAP.
ping? right now TS muxing in ffmpeg is broken...
Finally, patch has been split and applied. Please test it. The VBR case still needs some adjustements I think. -- Baptiste COUDURIER Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA FFmpeg maintainer http://www.ffmpeg.org
On 01/13/2010 02:47 PM, Carl Eugen Hoyos wrote:
Baptiste Coudurier<baptiste.coudurier<at> gmail.com> writes:
right now TS muxing in ffmpeg is broken...
Finally, patch has been split and applied.
Merci, did that possibly affect issues 1279 or 1674?
Definitely 1279 but not 1674. -- Baptiste COUDURIER Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA FFmpeg maintainer http://www.ffmpeg.org
Baptiste Coudurier <baptiste.coudurier <at> gmail.com> writes:
Finally, patch has been split and applied.
Merci, did that possibly affect issues 1279 or 1674?
Definitely 1279 but not 1674.
So could you fix their stati? (I don't know how to confirm them.) Thanks, Carl Eugen
Hi, I'm having a problem with this patch. I'm writing a segmenter that needs to produce TS stream with packets that have pts and dts delayed by an offset. The patch however cause lot of empty packets at the beginning of each segment (to compensate for delayed pts/dts). Is there any way to avoid this? Thanks. -Matej On Thu, Jan 14, 2010 at 2:05 AM, Carl Eugen Hoyos <cehoyos at ag.or.at> wrote:
Baptiste Coudurier <baptiste.coudurier <at> gmail.com> writes:
Finally, patch has been split and applied.
Merci, did that possibly affect issues 1279 or 1674?
Definitely 1279 but not 1674.
So could you fix their stati? (I don't know how to confirm them.)
Thanks, Carl Eugen
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
I'm having a problem with this patch. I'm writing a segmenter that needs to produce TS stream with packets that have pts and dts delayed by an offset. The patch however cause lot of empty packets at the beginning of each segment (to compensate for delayed pts/dts).
Is there any way to avoid this?
Thanks. -Matej
Please don't top-post on this list. It is my understanding that the mpeg-ts muxer is supposed to generate Constant Bitrate (CBR) transport streams. In the current code, the PCR *always* starts at 0, so the behavior you call "a problem" is actually the correct behavior. One solution would be to add a new feature to the mpeg-ts mux so that the initial PCR can be specified by the caller (using metadata?) or maybe calculated from the first DTS received. I'll work on a patch if Baptiste indicates he is OK with the concept. Mike Scheutzow
On Mon, Feb 08, 2010 at 12:52:32PM -0500, Mike Scheutzow wrote:
I'm having a problem with this patch. I'm writing a segmenter that needs to produce TS stream with packets that have pts and dts delayed by an offset. The patch however cause lot of empty packets at the beginning of each segment (to compensate for delayed pts/dts).
Is there any way to avoid this?
Thanks. -Matej
Please don't top-post on this list.
It is my understanding that the mpeg-ts muxer is supposed to generate Constant Bitrate (CBR) transport streams. In the current code, the PCR *always* starts at 0, so the behavior you call "a problem" is actually the correct behavior.
One solution would be to add a new feature to the mpeg-ts mux so that the initial PCR can be specified by the caller (using metadata?) or maybe calculated from the first DTS received.
I'll work on a patch if Baptiste indicates he is OK with the concept.
iam not baptiste but i think 1. we need VBR support 2. its the muxers job to figure all timestamps out from the DTS/PTS do proper interleaving and all that in a fully system/video/audio compliant way (as long as the codec streams are compliant) 3. only add minimal overhead our PS muxer can do all that,what is so different on TS that the existing code from our PS muxer cannot just be used? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Complexity theory is the science of finding the exact solution to an approximation. Benchmarking OTOH is finding an approximation of the exact
On Mon, Feb 08, 2010 at 12:52:32PM -0500, Mike Scheutzow wrote:
One solution would be to add a new feature to the mpeg-ts mux so that the initial PCR can be specified by the caller (using metadata?) or maybe calculated from the first DTS received. I'll work on a patch if Baptiste indicates he is OK with the concept.
Michael Niedermayer wrote:
iam not baptiste but i think 1. we need VBR support 2. its the muxers job to figure all timestamps out from the DTS/PTS do proper interleaving and all that in a fully system/video/audio compliant way (as long as the codec streams are compliant) 3. only add minimal overhead
our PS muxer can do all that,what is so different on TS that the existing code from our PS muxer cannot just be used?
Michael, I certainly agree with (2) and (3). I was hoping we'd hear from Baptiste, but it's been 10 days now, without comment from him on any of these topics. I am interested in helping improve the mpegts muxer, but it seems pointless for me to contribute patches when the maintainer won't respond or show any interest. Mike Scheutzow
Mike Scheutzow wrote:
On Mon, Feb 08, 2010 at 12:52:32PM -0500, Mike Scheutzow wrote:
One solution would be to add a new feature to the mpeg-ts mux so that the initial PCR can be specified by the caller (using metadata?) or maybe calculated from the first DTS received. I'll work on a patch if Baptiste indicates he is OK with the concept.
Michael Niedermayer wrote:
iam not baptiste but i think 1. we need VBR support 2. its the muxers job to figure all timestamps out from the DTS/PTS do proper interleaving and all that in a fully system/video/audio compliant way (as long as the codec streams are compliant) 3. only add minimal overhead
our PS muxer can do all that,what is so different on TS that the existing code from our PS muxer cannot just be used?
Michael,
I certainly agree with (2) and (3). I was hoping we'd hear from Baptiste, but it's been 10 days now, without comment from him on any of these topics.
I am interested in helping improve the mpegts muxer, but it seems pointless for me to contribute patches when the maintainer won't respond or show any interest.
Mike Scheutzow
Baptiste is missing in action, most likely on vacation. MvH Benjamin Larsson
Hi Mike, Ben, Michael, On 02/17/2010 01:20 PM, Benjamin Larsson wrote:
Mike Scheutzow wrote:
On Mon, Feb 08, 2010 at 12:52:32PM -0500, Mike Scheutzow wrote:
One solution would be to add a new feature to the mpeg-ts mux so that the initial PCR can be specified by the caller (using metadata?) or maybe calculated from the first DTS received. I'll work on a patch if Baptiste indicates he is OK with the concept.
Michael Niedermayer wrote:
iam not baptiste but i think 1. we need VBR support 2. its the muxers job to figure all timestamps out from the DTS/PTS do proper interleaving and all that in a fully system/video/audio compliant way (as long as the codec streams are compliant) 3. only add minimal overhead
our PS muxer can do all that,what is so different on TS that the existing code from our PS muxer cannot just be used?
Michael,
I certainly agree with (2) and (3). I was hoping we'd hear from Baptiste, but it's been 10 days now, without comment from him on any of these topics.
I am interested in helping improve the mpegts muxer, but it seems pointless for me to contribute patches when the maintainer won't respond or show any interest.
Mike Scheutzow
Baptiste is missing in action, most likely on vacation.
I think Michael points are exactly right. IMHO: 1) is the first priority. 2) is mandatory. 3) is the goal, but sometimes it might not be possible to accomodate all equipments requirements. Any work on the TS muxer is very welcome, and thanks a lot Mike for showing interest in it. -- Baptiste COUDURIER Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA FFmpeg maintainer http://www.ffmpeg.org
participants (11)
-
Alan.Stratford@Goodrich.com -
alexandre.ferrieux@orange-ftgroup.com -
aviadr1@gmail.com -
banan@ludd.ltu.se -
baptiste.coudurier@gmail.com -
belcampo@zonnet.nl -
cehoyos@ag.or.at -
matej.knopp@gmail.com -
michaelni@gmx.at -
niobos@dest-unreach.be -
scheutzow@alcatel-lucent.com