Write additional timecode as sum of last frame's timecode + duration

This commit is contained in:
Moritz Bunkus 2012-01-13 19:10:49 +01:00
parent f99072b9a5
commit 0979a736eb
3 changed files with 35 additions and 7 deletions

View File

@ -1,3 +1,11 @@
2012-01-13 Moritz Bunkus <moritz@bunkus.org>
* mkvextract: bug fix for the "timecodes_v2" mode: mkvextract will
write one more timecode than there are frames in the file. The
last timecode written will be the the sum of the last frame's
timecode and duration with the "last frame" being the one with the
highest timecode. Fix for bug 691.
2012-01-12 Moritz Bunkus <moritz@bunkus.org>
* mkvmerge: bug fix: Fixed writing into paths on which a drive is

View File

@ -40,10 +40,26 @@
using namespace libmatroska;
struct timecode_t {
int64_t m_timecode, m_duration;
timecode_t(int64_t timecode, int64_t duration)
: m_timecode(timecode)
, m_duration(duration)
{
}
};
bool
operator <(const timecode_t &t1,
const timecode_t &t2) {
return t1.m_timecode < t2.m_timecode;
}
struct timecode_extractor_t {
int64_t m_tid, m_tnum;
mm_io_cptr m_file;
std::vector<int64_t> m_timecodes;
std::vector<timecode_t> m_timecodes;
int64_t m_default_duration;
timecode_extractor_t(int64_t tid, int64_t tnum, const mm_io_cptr &file, int64_t default_duration)
@ -62,12 +78,16 @@ static std::vector<timecode_extractor_t> timecode_extractors;
static void
close_timecode_files() {
for (auto &extractor : timecode_extractors) {
std::vector<int64_t> &timecodes = extractor.m_timecodes;
std::vector<int64_t>::const_iterator timecode;
auto &timecodes = extractor.m_timecodes;
std::sort(timecodes.begin(), timecodes.end());
for (auto timecode : timecodes)
extractor.m_file->puts(to_string(timecode, 1000000, 6) + "\n");
extractor.m_file->puts(to_string(timecode.m_timecode, 1000000, 6) + "\n");
if (!timecodes.empty()) {
timecode_t &last_timecode = timecodes.back();
extractor.m_file->puts(to_string(last_timecode.m_timecode + last_timecode.m_duration, 1000000, 6) + "\n");
}
}
timecode_extractors.clear();
@ -137,7 +157,7 @@ handle_blockgroup(KaxBlockGroup &blockgroup,
// Pass the block to the extractor.
size_t i;
for (i = 0; block->NumberFrames() > i; ++i)
extractor->m_timecodes.push_back((int64_t)(block->GlobalTimecode() + i * (double)duration / block->NumberFrames()));
extractor->m_timecodes.push_back(timecode_t(block->GlobalTimecode() + i * duration / block->NumberFrames(), duration / block->NumberFrames()));
}
static void
@ -155,7 +175,7 @@ handle_simpleblock(KaxSimpleBlock &simpleblock,
// Pass the block to the extractor.
size_t i;
for (i = 0; simpleblock.NumberFrames() > i; ++i)
extractor->m_timecodes.push_back((int64_t)(simpleblock.GlobalTimecode() + i * (double)extractor->m_default_duration));
extractor->m_timecodes.push_back(timecode_t(simpleblock.GlobalTimecode() + i * extractor->m_default_duration, extractor->m_default_duration));
}
void

View File

@ -174,5 +174,5 @@ T_325propedit_tags:785209f2dc35ad6177bea2ca6e43198f-3f151ff52e43ed1df3c173e5b0c7
T_326mpeg_ps_mpeg_audio_layer4:ff06a9bda2235c9c834ef839344325af:passed:20111207-224511:2.60761265
T_327vp8_frame_type:69725de2b6569734a3b1f955b4775e74:passed:20111207-233304:0.214913089
T_328dts_detected_as_ac3:dfac59530d2d96ab9f41465fdc3931fd:passed:20111229-192324:0.053131334
T_329X_timecodes_v2:400aff17fffdc572d89f4309bcced867-71f8e59278cd7d0ef23904c9bc680667-aa8357fa884d973f0352b3f85ff85d69-cb82fa530d2be50f488d12da274fc4a9-3eed680b7540d8cb77cdf2f08abb9ded-71f8e59278cd7d0ef23904c9bc680667-7493030589eb6bdda8306709189c77df-ec1caab0af5051ccbd2004e2c8e8fb95-a140081fef32c1c33bcd9047b117a6f9-c546e869d30eef2203d62bebb6a6d458:passed:20120105-202451:2.051321822
T_329X_timecodes_v2:dadc36ce79c1c4b281f8f1f865746598-049cdc2d9226fac8c61d193d803bfc1f-3720aac3f16b66ec3308ffa7bf913c6e-6469e2522a4b48b7b20bae93f5d9086d-1ff091abfcb0938d6ac7fd0495e899b3-049cdc2d9226fac8c61d193d803bfc1f-d172a9340cbf2802690479e396879d1e-bf76c5886cc7c18cc7e6ee796c3406b4-b3f9d126c31505c22f292a1d2bdffba2-4bd97467fac0ac0b561d68b8b15a79dd:passed:20120105-202451:2.051321822
T_330dts_detection:38c941b579418e6c874950f4c55f84ce:passed:20120107-210130:1.22781858