[PATCH] matroskadec: Fix TTA duration calculation
Still not perfect due to rounding errors, but several samples should demux correctly now instead of none. Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/matroskadec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index d52877c..e4b11a2 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1738,7 +1738,7 @@ static int matroska_read_header(AVFormatContext *s) avio_wl16(&b, track->audio.channels); avio_wl16(&b, track->audio.bitdepth); avio_wl32(&b, track->audio.out_samplerate); - avio_wl32(&b, matroska->ctx->duration * track->audio.out_samplerate); + avio_wl32(&b, av_rescale(matroska->ctx->duration, track->audio.out_samplerate, AV_TIME_BASE)); } else if (codec_id == AV_CODEC_ID_RV10 || codec_id == AV_CODEC_ID_RV20 || codec_id == AV_CODEC_ID_RV30 || codec_id == AV_CODEC_ID_RV40) { extradata_offset = 26; -- 1.8.1.5
On Thu, Aug 15, 2013 at 06:22:47AM -0300, James Almer wrote:
Still not perfect due to rounding errors, but several samples should demux correctly now instead of none.
please add a link to a sample to reproduce this bugfix in the commit message [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The real ebay dictionary, page 3 "Rare item" - "Common item with rare defect or maybe just a lie" "Professional" - "'Toy' made in china, not functional except as doorstop" "Experts will know" - "The seller hopes you are not an expert"
On 8/15/13, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Aug 15, 2013 at 06:22:47AM -0300, James Almer wrote:
Still not perfect due to rounding errors, but several samples should demux correctly now instead of none.
please add a link to a sample to reproduce this bugfix in the commit message
Samples are not needed at all, this can be easily reproduced. And its incorrect to claim current one could not demux correctly any files. It just fails if last packet have number of samples smaller than all other packets before, which is 'almost' always but not always. Question to OP: I wonder does other program(s) always decode last frame no matter what number of samples are in it?
On 8/15/13, Paul B Mahol <onemda@gmail.com> wrote:
On 8/15/13, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Aug 15, 2013 at 06:22:47AM -0300, James Almer wrote:
Still not perfect due to rounding errors, but several samples should demux correctly now instead of none.
please add a link to a sample to reproduce this bugfix in the commit message
Samples are not needed at all, this can be easily reproduced.
And its incorrect to claim current one could not demux correctly any files. It just fails if last packet have number of samples smaller than all other packets before, which is 'almost' always but not always.
Question to OP: I wonder does other program(s) always decode last frame no matter what number of samples are in it?
Also commit message is misleading: it does not fix duration calculation it just improves it. AFAIK there is no way to really fix calculation, but I would like to be proven wrong....
On Thu, Aug 15, 2013 at 10:44:27AM +0000, Paul B Mahol wrote:
On 8/15/13, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Aug 15, 2013 at 06:22:47AM -0300, James Almer wrote:
Still not perfect due to rounding errors, but several samples should demux correctly now instead of none.
please add a link to a sample to reproduce this bugfix in the commit message
Samples are not needed at all, this can be easily reproduced.
then the commit message should contain a reproducable testcase Having such testcases can simplify my work maintaining matroskadec [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Let us carefully observe those good qualities wherein our enemies excel us and endeavor to excel them, by avoiding what is faulty, and imitating what is excellent in them. -- Plutarch
On 15/08/13 9:00 AM, Michael Niedermayer wrote:
On Thu, Aug 15, 2013 at 10:44:27AM +0000, Paul B Mahol wrote:
On 8/15/13, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Aug 15, 2013 at 06:22:47AM -0300, James Almer wrote:
Still not perfect due to rounding errors, but several samples should demux correctly now instead of none.
please add a link to a sample to reproduce this bugfix in the commit message
Samples are not needed at all, this can be easily reproduced.
then the commit message should contain a reproducable testcase Having such testcases can simplify my work maintaining matroskadec
I'll resubmit the patch with a testcase using a sample from the FATE suit and a different commit message since, as Paul said, it doesn't fix the calculation but improves it. Regards.
On 15/08/13 7:44 AM, Paul B Mahol wrote:
On 8/15/13, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Aug 15, 2013 at 06:22:47AM -0300, James Almer wrote:
Still not perfect due to rounding errors, but several samples should demux correctly now instead of none.
please add a link to a sample to reproduce this bugfix in the commit message
Samples are not needed at all, this can be easily reproduced.
And its incorrect to claim current one could not demux correctly any files. It just fails if last packet have number of samples smaller than all other packets before, which is 'almost' always but not always.
Yeah, bad choice of words from my part. It is about the last frame when its size is different than the rest.
Question to OP: I wonder does other program(s) always decode last frame no matter what number of samples are in it?
No, when dealing with files where the last frame is different than the rest, foobar2000 successfully decodes said frame in some, and fails in others. With this patch ffmpeg does the same, but some files that fail with fb2k might work, and vice-versa. Regards.
Calculate the duration as accurately as possible to improve decoding of samples where the last frame is smaller than the rest. Example: Take lossless-audio/luckynight-partial.tak from the FATE suit and convert it to TTA muxed into matroska: ffmpeg -i $(SAMPLES)/lossless-audio/luckynight-partial.tak -c:a tta lucky.mka The framemd5 output for lucky.mka without this patch: 0, 0, 0, 46080, 184320, 7c3751ddd571d2903c3cf0ab4b3e3d0a 0, 46080, 46080, 46080, 184320, 6b70c782ba1da3f933fde2daa4f96b73 0, 92160, 92160, 46080, 184320, dcf70d89c54b9a4f0b302d4ec4fb302d 0, 138240, 138240, 46080, 184320, 48713ca38b388d2ea4abf5b86ed1226f 0, 184320, 184320, 46080, 184320, 12188a23648e7ebfb07cd6fe9197b2ea 0, 230400, 230400, 46080, 184320, 49653ab8186a5d4a044ed284671a26e0 0, 276480, 276480, 46080, 184320, 5e82c6a7fe58c7ea612c03a0a2927dd4 0, 322560, 322560, 46080, 184320, 83dc449dbd9eab5f2e8ad2b4403d6a21 0, 368640, 368640, 46080, 184320, bdd6b92c23d30978d4e802d305b0fc49 With this patch: 0, 0, 0, 46080, 184320, 7c3751ddd571d2903c3cf0ab4b3e3d0a 0, 46080, 46080, 46080, 184320, 6b70c782ba1da3f933fde2daa4f96b73 0, 92160, 92160, 46080, 184320, dcf70d89c54b9a4f0b302d4ec4fb302d 0, 138240, 138240, 46080, 184320, 48713ca38b388d2ea4abf5b86ed1226f 0, 184320, 184320, 46080, 184320, 12188a23648e7ebfb07cd6fe9197b2ea 0, 230400, 230400, 46080, 184320, 49653ab8186a5d4a044ed284671a26e0 0, 276480, 276480, 46080, 184320, 5e82c6a7fe58c7ea612c03a0a2927dd4 0, 322560, 322560, 46080, 184320, 83dc449dbd9eab5f2e8ad2b4403d6a21 0, 368640, 368640, 46080, 184320, bdd6b92c23d30978d4e802d305b0fc49 0, 414720, 414720, 4230, 16920, b50b440c5bbcecb8e9fbece643447593 The duration without this patch was calculated as 418950000000, which is bigger than uint32_t and as such stored as 2338172288. With this patch the duration is correctly calculated as 418950. Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/matroskadec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index d52877c..e4b11a2 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1738,7 +1738,7 @@ static int matroska_read_header(AVFormatContext *s) avio_wl16(&b, track->audio.channels); avio_wl16(&b, track->audio.bitdepth); avio_wl32(&b, track->audio.out_samplerate); - avio_wl32(&b, matroska->ctx->duration * track->audio.out_samplerate); + avio_wl32(&b, av_rescale(matroska->ctx->duration, track->audio.out_samplerate, AV_TIME_BASE)); } else if (codec_id == AV_CODEC_ID_RV10 || codec_id == AV_CODEC_ID_RV20 || codec_id == AV_CODEC_ID_RV30 || codec_id == AV_CODEC_ID_RV40) { extradata_offset = 26; -- 1.8.1.5
On 8/15/13, James Almer <jamrial@gmail.com> wrote:
Calculate the duration as accurately as possible to improve decoding of samples where the last frame is smaller than the rest.
Example: Take lossless-audio/luckynight-partial.tak from the FATE suit and convert it
to TTA muxed into matroska:
ffmpeg -i $(SAMPLES)/lossless-audio/luckynight-partial.tak -c:a tta lucky.mka
The framemd5 output for lucky.mka without this patch:
0, 0, 0, 46080, 184320, 7c3751ddd571d2903c3cf0ab4b3e3d0a 0, 46080, 46080, 46080, 184320, 6b70c782ba1da3f933fde2daa4f96b73 0, 92160, 92160, 46080, 184320, dcf70d89c54b9a4f0b302d4ec4fb302d 0, 138240, 138240, 46080, 184320, 48713ca38b388d2ea4abf5b86ed1226f 0, 184320, 184320, 46080, 184320, 12188a23648e7ebfb07cd6fe9197b2ea 0, 230400, 230400, 46080, 184320, 49653ab8186a5d4a044ed284671a26e0 0, 276480, 276480, 46080, 184320, 5e82c6a7fe58c7ea612c03a0a2927dd4 0, 322560, 322560, 46080, 184320, 83dc449dbd9eab5f2e8ad2b4403d6a21 0, 368640, 368640, 46080, 184320, bdd6b92c23d30978d4e802d305b0fc49
With this patch:
0, 0, 0, 46080, 184320, 7c3751ddd571d2903c3cf0ab4b3e3d0a 0, 46080, 46080, 46080, 184320, 6b70c782ba1da3f933fde2daa4f96b73 0, 92160, 92160, 46080, 184320, dcf70d89c54b9a4f0b302d4ec4fb302d 0, 138240, 138240, 46080, 184320, 48713ca38b388d2ea4abf5b86ed1226f 0, 184320, 184320, 46080, 184320, 12188a23648e7ebfb07cd6fe9197b2ea 0, 230400, 230400, 46080, 184320, 49653ab8186a5d4a044ed284671a26e0 0, 276480, 276480, 46080, 184320, 5e82c6a7fe58c7ea612c03a0a2927dd4 0, 322560, 322560, 46080, 184320, 83dc449dbd9eab5f2e8ad2b4403d6a21 0, 368640, 368640, 46080, 184320, bdd6b92c23d30978d4e802d305b0fc49 0, 414720, 414720, 4230, 16920, b50b440c5bbcecb8e9fbece643447593
The duration without this patch was calculated as 418950000000, which is bigger than uint32_t and as such stored as 2338172288. With this patch the duration is correctly calculated as 418950.
Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/matroskadec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index d52877c..e4b11a2 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1738,7 +1738,7 @@ static int matroska_read_header(AVFormatContext *s) avio_wl16(&b, track->audio.channels); avio_wl16(&b, track->audio.bitdepth); avio_wl32(&b, track->audio.out_samplerate); - avio_wl32(&b, matroska->ctx->duration * track->audio.out_samplerate); + avio_wl32(&b, av_rescale(matroska->ctx->duration, track->audio.out_samplerate, AV_TIME_BASE));
Isn't time base variable thing that can be changed by muxer? Perhaps this could be used when muxing tta files to make sure last packet can always decode.
} else if (codec_id == AV_CODEC_ID_RV10 || codec_id == AV_CODEC_ID_RV20 || codec_id == AV_CODEC_ID_RV30 || codec_id == AV_CODEC_ID_RV40) { extradata_offset = 26; -- 1.8.1.5
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
On 16/08/13 7:24 AM, Paul B Mahol wrote:
On 8/15/13, James Almer <jamrial@gmail.com> wrote:
- avio_wl32(&b, matroska->ctx->duration * track->audio.out_samplerate); + avio_wl32(&b, av_rescale(matroska->ctx->duration, track->audio.out_samplerate, AV_TIME_BASE));
Isn't time base variable thing that can be changed by muxer?
Perhaps this could be used when muxing tta files to make sure last packet can always decode.
Our muxer already uses 1000000 (aka AV_TIME_BASE) as timescale for every file. Other muxers use values like round(1000000000 / sampleRate), which seems to be recommended for audio-only matroska: http://matroska.org/technical/specs/notes.html
On 8/16/13, James Almer <jamrial@gmail.com> wrote:
On 16/08/13 7:24 AM, Paul B Mahol wrote:
On 8/15/13, James Almer <jamrial@gmail.com> wrote:
- avio_wl32(&b, matroska->ctx->duration * track->audio.out_samplerate); + avio_wl32(&b, av_rescale(matroska->ctx->duration, track->audio.out_samplerate, AV_TIME_BASE));
Isn't time base variable thing that can be changed by muxer?
Perhaps this could be used when muxing tta files to make sure last packet can always decode.
Our muxer already uses 1000000 (aka AV_TIME_BASE) as timescale for every file.
But this patch does not use time base as used in file, but hardcode it,
Other muxers use values like round(1000000000 / sampleRate), which seems to be recommended for audio-only matroska: http://matroska.org/technical/specs/notes.html
If it does not provide sample accurate track duration we should not use it.
On 16/08/13 5:21 PM, Paul B Mahol wrote:
On 8/16/13, James Almer <jamrial@gmail.com> wrote:
On 16/08/13 7:24 AM, Paul B Mahol wrote:
On 8/15/13, James Almer <jamrial@gmail.com> wrote:
- avio_wl32(&b, matroska->ctx->duration * track->audio.out_samplerate); + avio_wl32(&b, av_rescale(matroska->ctx->duration, track->audio.out_samplerate, AV_TIME_BASE));
Isn't time base variable thing that can be changed by muxer?
Perhaps this could be used when muxing tta files to make sure last packet can always decode.
Our muxer already uses 1000000 (aka AV_TIME_BASE) as timescale for every file.
But this patch does not use time base as used in file, but hardcode it,
It's using matroska->ctx->duration, which is calculated using the duration and the timescale of the stream as stored in the file (line 1546). That line for that matter could use av_rescale() as well instead of a plain a*b/c, but that's unrelated.
On 8/16/13, James Almer <jamrial@gmail.com> wrote:
On 16/08/13 5:21 PM, Paul B Mahol wrote:
On 8/16/13, James Almer <jamrial@gmail.com> wrote:
On 16/08/13 7:24 AM, Paul B Mahol wrote:
On 8/15/13, James Almer <jamrial@gmail.com> wrote:
- avio_wl32(&b, matroska->ctx->duration * track->audio.out_samplerate); + avio_wl32(&b, av_rescale(matroska->ctx->duration, track->audio.out_samplerate, AV_TIME_BASE));
Isn't time base variable thing that can be changed by muxer?
Perhaps this could be used when muxing tta files to make sure last packet can always decode.
Our muxer already uses 1000000 (aka AV_TIME_BASE) as timescale for every file.
But this patch does not use time base as used in file, but hardcode it,
It's using matroska->ctx->duration, which is calculated using the duration and the timescale of the stream as stored in the file (line 1546).
But could it use track duration which is set in track time base units?
That line for that matter could use av_rescale() as well instead of a plain a*b/c, but that's unrelated. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
On 17/08/13 6:48 AM, Paul B Mahol wrote:
On 8/16/13, James Almer <jamrial@gmail.com> wrote:
On 16/08/13 5:21 PM, Paul B Mahol wrote:
On 8/16/13, James Almer <jamrial@gmail.com> wrote:
On 16/08/13 7:24 AM, Paul B Mahol wrote:
On 8/15/13, James Almer <jamrial@gmail.com> wrote:
- avio_wl32(&b, matroska->ctx->duration * track->audio.out_samplerate); + avio_wl32(&b, av_rescale(matroska->ctx->duration, track->audio.out_samplerate, AV_TIME_BASE));
Isn't time base variable thing that can be changed by muxer?
Perhaps this could be used when muxing tta files to make sure last packet can always decode.
Our muxer already uses 1000000 (aka AV_TIME_BASE) as timescale for every file.
But this patch does not use time base as used in file, but hardcode it,
It's using matroska->ctx->duration, which is calculated using the duration and the timescale of the stream as stored in the file (line 1546).
But could it use track duration which is set in track time base units?
So you mean doing "av_rescale((matroska->duration * matroska->time_scale), track->audio.out_samplerate, AV_TIME_BASE * 1000)"? I guess that might be a tad more accurate depending on the file. I'll send a new patch in a moment.
On 8/17/13, James Almer <jamrial@gmail.com> wrote:
On 17/08/13 6:48 AM, Paul B Mahol wrote:
On 8/16/13, James Almer <jamrial@gmail.com> wrote:
On 16/08/13 5:21 PM, Paul B Mahol wrote:
On 8/16/13, James Almer <jamrial@gmail.com> wrote:
On 16/08/13 7:24 AM, Paul B Mahol wrote:
On 8/15/13, James Almer <jamrial@gmail.com> wrote: > - avio_wl32(&b, matroska->ctx->duration * > track->audio.out_samplerate); > + avio_wl32(&b, av_rescale(matroska->ctx->duration, > track->audio.out_samplerate, AV_TIME_BASE));
Isn't time base variable thing that can be changed by muxer?
Perhaps this could be used when muxing tta files to make sure last packet can always decode.
Our muxer already uses 1000000 (aka AV_TIME_BASE) as timescale for every file.
But this patch does not use time base as used in file, but hardcode it,
It's using matroska->ctx->duration, which is calculated using the duration and the timescale of the stream as stored in the file (line 1546).
But could it use track duration which is set in track time base units?
So you mean doing "av_rescale((matroska->duration * matroska->time_scale), track->audio.out_samplerate, AV_TIME_BASE * 1000)"? I guess that might be a tad more accurate depending on the file.
I do not mean anything. But isn't time scale & duration different for each track?
I'll send a new patch in a moment. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
On 17/08/13 3:30 PM, Paul B Mahol wrote:
On 8/17/13, James Almer <jamrial@gmail.com> wrote:
On 17/08/13 6:48 AM, Paul B Mahol wrote:
On 8/16/13, James Almer <jamrial@gmail.com> wrote:
On 16/08/13 5:21 PM, Paul B Mahol wrote:
On 8/16/13, James Almer <jamrial@gmail.com> wrote:
On 16/08/13 7:24 AM, Paul B Mahol wrote: > On 8/15/13, James Almer <jamrial@gmail.com> wrote: >> - avio_wl32(&b, matroska->ctx->duration * >> track->audio.out_samplerate); >> + avio_wl32(&b, av_rescale(matroska->ctx->duration, >> track->audio.out_samplerate, AV_TIME_BASE)); > > Isn't time base variable thing that can be changed by muxer? > > Perhaps this could be used when muxing tta files to make sure > last packet can always decode.
Our muxer already uses 1000000 (aka AV_TIME_BASE) as timescale for every file.
But this patch does not use time base as used in file, but hardcode it,
It's using matroska->ctx->duration, which is calculated using the duration and the timescale of the stream as stored in the file (line 1546).
But could it use track duration which is set in track time base units?
So you mean doing "av_rescale((matroska->duration * matroska->time_scale), track->audio.out_samplerate, AV_TIME_BASE * 1000)"? I guess that might be a tad more accurate depending on the file.
I do not mean anything. But isn't time scale & duration different for each track?
I guess so, but what difference does that make?
On 8/17/13, James Almer <jamrial@gmail.com> wrote:
On 17/08/13 3:30 PM, Paul B Mahol wrote:
On 8/17/13, James Almer <jamrial@gmail.com> wrote:
On 17/08/13 6:48 AM, Paul B Mahol wrote:
On 8/16/13, James Almer <jamrial@gmail.com> wrote:
On 16/08/13 5:21 PM, Paul B Mahol wrote:
On 8/16/13, James Almer <jamrial@gmail.com> wrote: > On 16/08/13 7:24 AM, Paul B Mahol wrote: >> On 8/15/13, James Almer <jamrial@gmail.com> wrote: >>> - avio_wl32(&b, matroska->ctx->duration * >>> track->audio.out_samplerate); >>> + avio_wl32(&b, av_rescale(matroska->ctx->duration, >>> track->audio.out_samplerate, AV_TIME_BASE)); >> >> Isn't time base variable thing that can be changed by muxer? >> >> Perhaps this could be used when muxing tta files to make sure >> last packet can always decode. > > Our muxer already uses 1000000 (aka AV_TIME_BASE) as timescale for > every > file.
But this patch does not use time base as used in file, but hardcode it,
It's using matroska->ctx->duration, which is calculated using the duration and the timescale of the stream as stored in the file (line 1546).
But could it use track duration which is set in track time base units?
So you mean doing "av_rescale((matroska->duration * matroska->time_scale), track->audio.out_samplerate, AV_TIME_BASE * 1000)"? I guess that might be a tad more accurate depending on the file.
I do not mean anything. But isn't time scale & duration different for each track?
I guess so, but what difference does that make?
audio is in track and each track can have different duration? Thus global one can be for anything else.
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
On 17/08/13 4:23 PM, Paul B Mahol wrote:
On 8/17/13, James Almer <jamrial@gmail.com> wrote:
On 17/08/13 3:30 PM, Paul B Mahol wrote:
On 8/17/13, James Almer <jamrial@gmail.com> wrote:
On 17/08/13 6:48 AM, Paul B Mahol wrote:
On 8/16/13, James Almer <jamrial@gmail.com> wrote:
On 16/08/13 5:21 PM, Paul B Mahol wrote: > On 8/16/13, James Almer <jamrial@gmail.com> wrote: >> On 16/08/13 7:24 AM, Paul B Mahol wrote: >>> On 8/15/13, James Almer <jamrial@gmail.com> wrote: >>>> - avio_wl32(&b, matroska->ctx->duration * >>>> track->audio.out_samplerate); >>>> + avio_wl32(&b, av_rescale(matroska->ctx->duration, >>>> track->audio.out_samplerate, AV_TIME_BASE)); >>> >>> Isn't time base variable thing that can be changed by muxer? >>> >>> Perhaps this could be used when muxing tta files to make sure >>> last packet can always decode. >> >> Our muxer already uses 1000000 (aka AV_TIME_BASE) as timescale for >> every >> file. > > But this patch does not use time base as used in file, but hardcode > it,
It's using matroska->ctx->duration, which is calculated using the duration and the timescale of the stream as stored in the file (line 1546).
But could it use track duration which is set in track time base units?
So you mean doing "av_rescale((matroska->duration * matroska->time_scale), track->audio.out_samplerate, AV_TIME_BASE * 1000)"? I guess that might be a tad more accurate depending on the file.
I do not mean anything. But isn't time scale & duration different for each track?
I guess so, but what difference does that make?
audio is in track and each track can have different duration? Thus global one can be for anything else.
I tried two muxers (ffmpeg and mkvtoolnix) and neither of them stored a value for track->time_scale. Our muxer also didn't store a value for track->default_duration. The other muxer did, but i can't make sense of the value after a quick look. I'm not sure how to use those, or if they can be used. But until we find how we should commit this patch which will at least improve support for audio only files.
On 8/17/13, James Almer <jamrial@gmail.com> wrote:
On 17/08/13 4:23 PM, Paul B Mahol wrote:
On 8/17/13, James Almer <jamrial@gmail.com> wrote:
On 17/08/13 3:30 PM, Paul B Mahol wrote:
On 8/17/13, James Almer <jamrial@gmail.com> wrote:
On 17/08/13 6:48 AM, Paul B Mahol wrote:
On 8/16/13, James Almer <jamrial@gmail.com> wrote: > On 16/08/13 5:21 PM, Paul B Mahol wrote: >> On 8/16/13, James Almer <jamrial@gmail.com> wrote: >>> On 16/08/13 7:24 AM, Paul B Mahol wrote: >>>> On 8/15/13, James Almer <jamrial@gmail.com> wrote: >>>>> - avio_wl32(&b, matroska->ctx->duration * >>>>> track->audio.out_samplerate); >>>>> + avio_wl32(&b, av_rescale(matroska->ctx->duration, >>>>> track->audio.out_samplerate, AV_TIME_BASE)); >>>> >>>> Isn't time base variable thing that can be changed by muxer? >>>> >>>> Perhaps this could be used when muxing tta files to make sure >>>> last packet can always decode. >>> >>> Our muxer already uses 1000000 (aka AV_TIME_BASE) as timescale for >>> every >>> file. >> >> But this patch does not use time base as used in file, but hardcode >> it, > > It's using matroska->ctx->duration, which is calculated using the > duration > and the timescale of the stream as stored in the file (line 1546).
But could it use track duration which is set in track time base units?
So you mean doing "av_rescale((matroska->duration * matroska->time_scale), track->audio.out_samplerate, AV_TIME_BASE * 1000)"? I guess that might be a tad more accurate depending on the file.
I do not mean anything. But isn't time scale & duration different for each track?
I guess so, but what difference does that make?
audio is in track and each track can have different duration? Thus global one can be for anything else.
I tried two muxers (ffmpeg and mkvtoolnix) and neither of them stored a value for track->time_scale. Our muxer also didn't store a value for track->default_duration. The other muxer did, but i can't make sense of the value after a quick look.
I'm not sure how to use those, or if they can be used. But until we find how we should commit this patch which will at least improve support for audio only files.
Yes, I agree.
Calculate the duration as accurately as possible to improve decoding of samples where the last frame is smaller than the rest. Example: Take lossless-audio/luckynight-partial.tak from the FATE suit and convert it to TTA muxed into matroska: ffmpeg -i $(SAMPLES)/lossless-audio/luckynight-partial.tak -c:a tta lucky.mka The framemd5 output for lucky.mka without this patch: 0, 0, 0, 46080, 184320, 7c3751ddd571d2903c3cf0ab4b3e3d0a 0, 46080, 46080, 46080, 184320, 6b70c782ba1da3f933fde2daa4f96b73 0, 92160, 92160, 46080, 184320, dcf70d89c54b9a4f0b302d4ec4fb302d 0, 138240, 138240, 46080, 184320, 48713ca38b388d2ea4abf5b86ed1226f 0, 184320, 184320, 46080, 184320, 12188a23648e7ebfb07cd6fe9197b2ea 0, 230400, 230400, 46080, 184320, 49653ab8186a5d4a044ed284671a26e0 0, 276480, 276480, 46080, 184320, 5e82c6a7fe58c7ea612c03a0a2927dd4 0, 322560, 322560, 46080, 184320, 83dc449dbd9eab5f2e8ad2b4403d6a21 0, 368640, 368640, 46080, 184320, bdd6b92c23d30978d4e802d305b0fc49 With this patch: 0, 0, 0, 46080, 184320, 7c3751ddd571d2903c3cf0ab4b3e3d0a 0, 46080, 46080, 46080, 184320, 6b70c782ba1da3f933fde2daa4f96b73 0, 92160, 92160, 46080, 184320, dcf70d89c54b9a4f0b302d4ec4fb302d 0, 138240, 138240, 46080, 184320, 48713ca38b388d2ea4abf5b86ed1226f 0, 184320, 184320, 46080, 184320, 12188a23648e7ebfb07cd6fe9197b2ea 0, 230400, 230400, 46080, 184320, 49653ab8186a5d4a044ed284671a26e0 0, 276480, 276480, 46080, 184320, 5e82c6a7fe58c7ea612c03a0a2927dd4 0, 322560, 322560, 46080, 184320, 83dc449dbd9eab5f2e8ad2b4403d6a21 0, 368640, 368640, 46080, 184320, bdd6b92c23d30978d4e802d305b0fc49 0, 414720, 414720, 4230, 16920, b50b440c5bbcecb8e9fbece643447593 The duration without this patch was calculated as 418950000000, which is bigger than uint32_t and as such stored as 2338172288. With this patch the duration is correctly calculated as 418950. Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/matroskadec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index d52877c..b78553e 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1738,7 +1738,7 @@ static int matroska_read_header(AVFormatContext *s) avio_wl16(&b, track->audio.channels); avio_wl16(&b, track->audio.bitdepth); avio_wl32(&b, track->audio.out_samplerate); - avio_wl32(&b, matroska->ctx->duration * track->audio.out_samplerate); + avio_wl32(&b, av_rescale((matroska->duration * matroska->time_scale), track->audio.out_samplerate, AV_TIME_BASE * 1000)); } else if (codec_id == AV_CODEC_ID_RV10 || codec_id == AV_CODEC_ID_RV20 || codec_id == AV_CODEC_ID_RV30 || codec_id == AV_CODEC_ID_RV40) { extradata_offset = 26; -- 1.8.1.5
On Sat, Aug 17, 2013 at 02:48:33PM -0300, James Almer wrote:
Calculate the duration as accurately as possible to improve decoding of samples where the last frame is smaller than the rest.
Example: Take lossless-audio/luckynight-partial.tak from the FATE suit and convert it to TTA muxed into matroska:
ffmpeg -i $(SAMPLES)/lossless-audio/luckynight-partial.tak -c:a tta lucky.mka
The framemd5 output for lucky.mka without this patch:
0, 0, 0, 46080, 184320, 7c3751ddd571d2903c3cf0ab4b3e3d0a 0, 46080, 46080, 46080, 184320, 6b70c782ba1da3f933fde2daa4f96b73 0, 92160, 92160, 46080, 184320, dcf70d89c54b9a4f0b302d4ec4fb302d 0, 138240, 138240, 46080, 184320, 48713ca38b388d2ea4abf5b86ed1226f 0, 184320, 184320, 46080, 184320, 12188a23648e7ebfb07cd6fe9197b2ea 0, 230400, 230400, 46080, 184320, 49653ab8186a5d4a044ed284671a26e0 0, 276480, 276480, 46080, 184320, 5e82c6a7fe58c7ea612c03a0a2927dd4 0, 322560, 322560, 46080, 184320, 83dc449dbd9eab5f2e8ad2b4403d6a21 0, 368640, 368640, 46080, 184320, bdd6b92c23d30978d4e802d305b0fc49
With this patch:
0, 0, 0, 46080, 184320, 7c3751ddd571d2903c3cf0ab4b3e3d0a 0, 46080, 46080, 46080, 184320, 6b70c782ba1da3f933fde2daa4f96b73 0, 92160, 92160, 46080, 184320, dcf70d89c54b9a4f0b302d4ec4fb302d 0, 138240, 138240, 46080, 184320, 48713ca38b388d2ea4abf5b86ed1226f 0, 184320, 184320, 46080, 184320, 12188a23648e7ebfb07cd6fe9197b2ea 0, 230400, 230400, 46080, 184320, 49653ab8186a5d4a044ed284671a26e0 0, 276480, 276480, 46080, 184320, 5e82c6a7fe58c7ea612c03a0a2927dd4 0, 322560, 322560, 46080, 184320, 83dc449dbd9eab5f2e8ad2b4403d6a21 0, 368640, 368640, 46080, 184320, bdd6b92c23d30978d4e802d305b0fc49 0, 414720, 414720, 4230, 16920, b50b440c5bbcecb8e9fbece643447593
The duration without this patch was calculated as 418950000000, which is bigger than uint32_t and as such stored as 2338172288. With this patch the duration is correctly calculated as 418950.
Signed-off-by: James Almer <jamrial@gmail.com>
applied thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB No great genius has ever existed without some touch of madness. -- Aristotle
participants (3)
-
James Almer -
Michael Niedermayer -
Paul B Mahol