diff --git a/ChangeLog b/ChangeLog index 5a8510536..0471dd927 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-09-06 Moritz Bunkus + + * mkvmerge: bug fix: improved the timecode calculation for MP3 + tracks read from MP4 files. Another part of the fix for bug 165. + 2008-09-03 Moritz Bunkus * mkvmerge: bug fix: mkvmerge honors the timecode offsets of all diff --git a/src/output/p_mp3.cpp b/src/output/p_mp3.cpp index d72ba7846..4945afa81 100644 --- a/src/output/p_mp3.cpp +++ b/src/output/p_mp3.cpp @@ -35,7 +35,8 @@ mp3_packetizer_c::mp3_packetizer_c(generic_reader_c *_reader, bytes_skipped(0), samples_per_sec(_samples_per_sec), channels(_channels), spf(1152), byte_buffer(128 * 1024), - codec_id_set(false), valid_headers_found(source_is_good) { + codec_id_set(false), valid_headers_found(source_is_good), + previous_timecode(-1), num_packets_with_same_timecode(0) { set_track_type(track_audio); set_track_default_duration((int64_t)(1152000000000.0 / samples_per_sec)); @@ -164,7 +165,21 @@ mp3_packetizer_c::process(packet_cptr packet) { byte_buffer.add(packet->data->get(), packet->data->get_size()); while ((mp3_packet = get_mp3_packet(&mp3header)) != NULL) { - int64_t new_timecode = -1 == packet->timecode ? (int64_t)(1000000000.0 * packetno * spf / samples_per_sec) : packet->timecode; + int64_t new_timecode; + if (-1 == packet->timecode) + new_timecode = (int64_t)(1000000000.0 * packetno * spf / samples_per_sec); + else { + if ((-1 != previous_timecode) && (packet->timecode == previous_timecode)) { + new_timecode = previous_timecode + num_packets_with_same_timecode * 1000000000ll * spf / samples_per_sec; + ++num_packets_with_same_timecode; + } else { + new_timecode = packet->timecode; + num_packets_with_same_timecode = 0; + } + + previous_timecode = packet->timecode; + } + add_packet(new packet_t(new memory_c(mp3_packet, mp3header.framesize, true), new_timecode, (int64_t)(1000000000.0 * spf / samples_per_sec))); packetno++; } diff --git a/src/output/p_mp3.h b/src/output/p_mp3.h index 67eda2e16..dacfc3721 100644 --- a/src/output/p_mp3.h +++ b/src/output/p_mp3.h @@ -29,11 +29,10 @@ private: int samples_per_sec, channels, spf; byte_buffer_c byte_buffer; bool codec_id_set, valid_headers_found; + int64_t previous_timecode, num_packets_with_same_timecode; public: - mp3_packetizer_c(generic_reader_c *_reader, int _samples_per_sec, - int _channels, bool source_is_good, track_info_c &_ti) - throw (error_c); + mp3_packetizer_c(generic_reader_c *_reader, int _samples_per_sec, int _channels, bool source_is_good, track_info_c &_ti) throw (error_c); virtual ~mp3_packetizer_c(); virtual int process(packet_cptr packet); @@ -42,8 +41,7 @@ public: virtual const char *get_format_name() { return "MP3"; } - virtual connection_result_e can_connect_to(generic_packetizer_c *src, - string &error_message); + virtual connection_result_e can_connect_to(generic_packetizer_c *src, string &error_message); private: virtual unsigned char *get_mp3_packet(mp3_header_t *mp3header);