diff --git a/src/extract/cuesheets.cpp b/src/extract/cuesheets.cpp index c18d58676..411e964b4 100644 --- a/src/extract/cuesheets.cpp +++ b/src/extract/cuesheets.cpp @@ -183,6 +183,9 @@ write_cuesheet(const char *file_name, if (chapters.ListSize() == 0) return; + if (no_variable_data) + file_name = "no-variable-data"; + out.write_bom("UTF-8"); print_if_global("CATALOG", "CATALOG %s\n"); // until 0.9.6 diff --git a/src/extract/mkvextract.h b/src/extract/mkvextract.h index 0c29e5cc9..7733c042f 100644 --- a/src/extract/mkvextract.h +++ b/src/extract/mkvextract.h @@ -58,7 +58,7 @@ extern bool no_variable_data; void show_element(EbmlElement *l, int level, const char *fmt, ...); void show_error(const char *fmt, ...); -bool extract_tracks(const char *file_name, vector &tracks); +bool extract_tracks(const char *file_name, vector &tspecs); void extract_tags(const char *file_name, bool parse_fully); void extract_chapters(const char *file_name, bool chapter_format_simple, bool parse_fully); diff --git a/src/extract/tracks.cpp b/src/extract/tracks.cpp index 00ce39e8a..890bdd700 100644 --- a/src/extract/tracks.cpp +++ b/src/extract/tracks.cpp @@ -216,18 +216,18 @@ close_extractors() { static void write_all_cuesheets(KaxChapters &chapters, KaxTags &tags, - vector &tracks) { + vector &tspecs) { int i; mm_io_c *out; out = NULL; - for (i = 0; i < tracks.size(); i++) { - if (tracks[i].extract_cuesheet) { + for (i = 0; i < tspecs.size(); i++) { + if (tspecs[i].extract_cuesheet) { string file_name, cue_file_name; int pos, pos2, pos3; - file_name = tracks[i].out_name; + file_name = tspecs[i].out_name; pos = file_name.rfind('/'); pos2 = file_name.rfind('\\'); if (pos2 > pos) @@ -235,7 +235,7 @@ write_all_cuesheets(KaxChapters &chapters, if (pos >= 0) file_name.erase(0, pos2); - cue_file_name = (string)tracks[i].out_name; + cue_file_name = (string)tspecs[i].out_name; pos = cue_file_name.rfind('.'); pos2 = cue_file_name.rfind('/'); pos3 = cue_file_name.rfind('\\'); @@ -250,16 +250,40 @@ write_all_cuesheets(KaxChapters &chapters, cue_file_name.c_str(), strerror(errno)); } mxinfo(_("The CUE sheet for track %lld will be written to '%s'.\n"), - tracks[i].tid, cue_file_name.c_str()); - write_cuesheet(file_name.c_str(), chapters, tags, tracks[i].tuid, *out); + tspecs[i].tid, cue_file_name.c_str()); + write_cuesheet(file_name.c_str(), chapters, tags, tspecs[i].tuid, *out); delete out; } } } +static void +find_track_uids(KaxTracks &tracks, + vector &tspecs) { + int t; + + for (t = 0; t < tracks.ListSize(); t++) { + KaxTrackEntry *track_entry; + int64_t track_number; + int s; + + track_entry = dynamic_cast(tracks[t]); + if (NULL == track_entry) + continue; + + track_number = kt_get_number(*track_entry); + + for (s = 0; s < tspecs.size(); s++) + if (tspecs[s].tid == track_number) { + tspecs[s].tuid = kt_get_uid(*track_entry); + break; + } + } +} + bool extract_tracks(const char *file_name, - vector &tracks) { + vector &tspecs) { int upper_lvl_el; // Elements for different levels EbmlElement *l0 = NULL, *l1 = NULL, *l2 = NULL, *l3 = NULL; @@ -371,7 +395,8 @@ extract_tracks(const char *file_name, tracks_found = true; l1->Read(*es, KaxTracks::ClassInfos.Context, upper_lvl_el, l2, true); - create_extractors(*dynamic_cast(l1), tracks); + find_track_uids(*dynamic_cast(l1), tspecs); + create_extractors(*dynamic_cast(l1), tspecs); } else if (EbmlId(*l1) == KaxCluster::ClassInfos.GlobalId) { show_element(l1, 1, _("Cluster")); @@ -492,7 +517,7 @@ extract_tracks(const char *file_name, delete es; delete in; - write_all_cuesheets(all_chapters, all_tags, tracks); + write_all_cuesheets(all_chapters, all_tags, tspecs); // Now just close the files and go to sleep. Mummy will sing you a // lullaby. Just close your eyes, listen to her sweet voice, singing, diff --git a/src/extract/xtr_base.cpp b/src/extract/xtr_base.cpp index 8e22b46ca..3ac056bc6 100644 --- a/src/extract/xtr_base.cpp +++ b/src/extract/xtr_base.cpp @@ -55,6 +55,16 @@ kt_get_number(KaxTrackEntry &track) { return uint64(*number); } +int64_t +kt_get_uid(KaxTrackEntry &track) { + KaxTrackUID *uid; + + uid = FINDFIRST(&track, KaxTrackUID); + if (NULL == uid) + return 0; + return uint64(*uid); +} + string kt_get_codec_id(KaxTrackEntry &track) { KaxCodecID *codec_id; diff --git a/src/extract/xtr_base.h b/src/extract/xtr_base.h index e52e9cf60..4996dbcd1 100644 --- a/src/extract/xtr_base.h +++ b/src/extract/xtr_base.h @@ -55,6 +55,7 @@ public: int64_t kt_get_default_duration(KaxTrackEntry &track); int64_t kt_get_number(KaxTrackEntry &track); +int64_t kt_get_uid(KaxTrackEntry &track); string kt_get_codec_id(KaxTrackEntry &track); int kt_get_max_blockadd_id(KaxTrackEntry &track); diff --git a/tests/results.txt b/tests/results.txt index 98a226fa4..1cd77310b 100644 --- a/tests/results.txt +++ b/tests/results.txt @@ -51,3 +51,4 @@ T_201avc_from_mp4_with_par:e8f2d2becffc65592ab541acb8394658:passed:20050125-2245 T_202avc_from_mp4_with_par_bframes:7cfd0e522b3b54ebdc987626c18be3a4:passed:20050125-224635 T_203wavpack_with_correctiondata:c18786fea4f93d385575aa4b6a0af4ed:passed:20050201-094411 T_204wavpack_without_correctiondata:0d01f5162a71fedc934d7e8a675a0004:passed:20050201-094414 +T_205X_cuesheets:3b00b00c7d185137e30d7e95e3123d33-b3bb67d316e20da12926d5c1d628f6e5:passed:20050210-211853 diff --git a/tests/test-205X_cuesheets.rb b/tests/test-205X_cuesheets.rb new file mode 100644 index 000000000..e110f642a --- /dev/null +++ b/tests/test-205X_cuesheets.rb @@ -0,0 +1,20 @@ +#!/usr/bin/ruby -w + +class T_205X_cuesheets < Test + def description + return "mkvextract / cue sheets / in(MKV)" + end + + def run + merge("#{tmp}-src", "data/simple/v.mp3 --chapters " + + "data/text/cuewithtags2.cue") + sys("../src/mkvextract cuesheet #{tmp}-src --no-variable-data &> #{tmp}") + hash = hash_tmp(false) + sys("../src/mkvextract tracks #{tmp}-src --no-variable-data " + + "--cuesheet 1:#{tmp} > /tmp/a") + hash += "-" + hash_tmp("#{tmp}.cue") + unlink_tmp_files + return hash + end +end +