1 /* 2 mkvextract -- extract tracks from Matroska files into other files 3 4 Distributed under the GPL v2 5 see the file COPYING for details 6 or visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.html 7 8 extracts chapters from Matroska files into other files 9 Written by Moritz Bunkus <moritz@bunkus.org>. 10 */ 11 12 #include "common/common_pch.h" 13 14 #include <cassert> 15 #include <iostream> 16 17 #include <ebml/EbmlHead.h> 18 #include <ebml/EbmlSubHead.h> 19 #include <ebml/EbmlStream.h> 20 #include <ebml/EbmlVoid.h> 21 22 #include <matroska/FileKax.h> 23 #include <matroska/KaxChapters.h> 24 25 #include "avilib.h" 26 #include "common/chapters/chapters.h" 27 #include "common/ebml.h" 28 #include "common/mm_io.h" 29 #include "common/mm_io_x.h" 30 #include "common/kax_analyzer.h" 31 #include "common/xml/ebml_chapters_converter.h" 32 #include "extract/mkvextract.h" 33 34 using namespace libmatroska; 35 36 bool extract_chapters(kax_analyzer_c & analyzer,options_c::mode_options_c & options)37extract_chapters(kax_analyzer_c &analyzer, 38 options_c::mode_options_c &options) { 39 auto element = analyzer.read_all(EBML_INFO(KaxChapters)); 40 auto chapters = dynamic_cast<KaxChapters *>(element.get()); 41 42 if (!chapters) 43 return true; 44 45 mtx::chapters::fix_country_codes(*chapters); 46 auto output = open_output_file(options.m_output_file_name); 47 48 if (!options.m_simple_chapter_format) 49 mtx::xml::ebml_chapters_converter_c::write_xml(*chapters, *output); 50 51 else 52 mtx::chapters::write_simple(*chapters, *output, options.m_simple_chapter_language); 53 54 return true; 55 } 56