[matroska] r934 - trunk/DvdMenuXtractor

[email protected]
Newsgroups gmane.comp.multimedia.matroska.cvs
Message-ID <[email protected]>
Author: robux4
Date: 2004-10-28 00:40:13 +0400 (Thu, 28 Oct 2004)
New Revision: 934

Modified:
   trunk/DvdMenuXtractor/DvdMenuXtractor.cpp
   trunk/DvdMenuXtractor/IFOFile.cpp
   trunk/DvdMenuXtractor/IFOFile.h
   trunk/DvdMenuXtractor/VobParser.cpp
   trunk/DvdMenuXtractor/VobParser.h
Log:
first part of .idx saving
don't use the "mask" directory for the moment

Modified: trunk/DvdMenuXtractor/DvdMenuXtractor.cpp
===================================================================
--- trunk/DvdMenuXtractor/DvdMenuXtractor.cpp	2004-10-27 15:02:11 UTC (rev 933)
+++ trunk/DvdMenuXtractor/DvdMenuXtractor.cpp	2004-10-27 20:40:13 UTC (rev 934)
@@ -69,7 +69,7 @@
 wxString subDirectory;
 wxString bmpDirectory;
 //wxString wavDirectory;
-wxString maskDirectory;
+//wxString maskDirectory;
 const wxString APPLICATION_NAME = "DVDMenu-X-tractor";
 
 // ----------------------------------------------------------------------------
@@ -559,6 +559,9 @@
 
 			const AudioTrackList & _audioTracks = IfoFile->AudioTracks(title, language);
 			const SubtitleTrackList & _subTracks = IfoFile->SubsTracks(title, language);
+			uint16_t _width, _height;
+			IfoFile->VideoSize(title, language, _width, _height);
+			const uint32_t * _palette = IfoFile->GetPalette(title, language);
 
             while(aVobParser.ParseNextPacket())
             {
@@ -579,7 +582,6 @@
 						int _stream;
 
 						// decide which audio streams to process
-						const AudioTrackList & _audioTracks = IfoFile->AudioTracks(title, language);
 						if (_audioTracks.GetCount())
 						{
 							for (_stream=0; _stream<_audioTracks.GetCount();_stream++)
@@ -627,8 +629,6 @@
 							}
 						}
 
-						// _TODO_ decide which subs streams to process
-						const SubtitleTrackList & _subTracks = IfoFile->SubsTracks(title, language);
 						if (_subTracks.GetCount())
 						{
 							for (_stream=0; _stream<_subTracks.GetCount();_stream++)
@@ -646,7 +646,7 @@
 										_langName = wxString::Format("_%d_%c%c", _IDs.Item(_IDidx), _attr->lang_code >> 8, _attr->lang_code & 0xFF);
 //									if(aVobParser.m_pci.btn_ns > 0)
 									{
-										_muxer = new SubDemuxWriter(subDirectory+newFilename+_langName, 0x20 + _IDs.Item(_IDidx));
+										_muxer = new SubDemuxWriter(subDirectory+newFilename+_langName, 0x20 + _IDs.Item(_IDidx), _width, _height, _palette, _attr->lang_code, _attr->lang_extension == 9);
 										if (!demuxer.AddDemuxer(0x20 + _IDs.Item(_IDidx), _muxer))
 											delete _muxer;
 									}
@@ -738,7 +738,6 @@
 		delete WAVWriter;
 		delete a52decoder;
     }
-#endif
 
     void ConvertButtonMaskToBMP(int16_t title, bool language)
     {
@@ -774,6 +773,7 @@
 		//delete BMPWriter;
 		delete subdecoder;
     }
+#endif
 
 	static wxString IndentString(int lvl)
 	{
@@ -1293,8 +1293,8 @@
 //        wavDirectory = pConfig->Read("OutputDirectory","")+ "wav" + wxFILE_SEP_PATH;
 //        wxMkdir(wavDirectory);
 		// Create mask directory
-		maskDirectory = pConfig->Read("OutputDirectory","") + "mask" + wxFILE_SEP_PATH;
-        wxMkdir(maskDirectory);
+//		maskDirectory = pConfig->Read("OutputDirectory","") + "mask" + wxFILE_SEP_PATH;
+//        wxMkdir(maskDirectory);
 	}
 
    virtual void AfterShow(void)

Modified: trunk/DvdMenuXtractor/IFOFile.cpp
===================================================================
--- trunk/DvdMenuXtractor/IFOFile.cpp	2004-10-27 15:02:11 UTC (rev 933)
+++ trunk/DvdMenuXtractor/IFOFile.cpp	2004-10-27 20:40:13 UTC (rev 934)
@@ -341,6 +341,77 @@
 		return _ifo->m_Subs;
 }
 
+bool IFOFile::VideoSize(unsigned int title, bool language, uint16_t & width, uint16_t & height) const
+{
+	IfoContent *_ifo = m_ifos.GetIfoTitle(title);
+	assert(_ifo != NULL);
+	video_attr_t *_attr = NULL;
+	if (language)
+	{
+		if (title == 0)
+		{
+			if (_ifo->Handle().vmgi_mat)
+			{
+				_attr = &_ifo->Handle().vmgi_mat->vmgm_video_attr;
+			}
+		}
+		else
+		{
+			if (_ifo->Handle().vtsi_mat)
+			{
+				_attr = &_ifo->Handle().vtsi_mat->vtsm_video_attr;
+			}
+		}
+	}
+	else
+	{
+		if (_ifo->Handle().vtsi_mat)
+		{
+			_attr = &_ifo->Handle().vtsi_mat->vts_video_attr;
+		}
+	}
+
+	if (_attr != NULL)
+	{
+		height = 480;
+		if(_attr->video_format != 0) 
+			height = 576;
+		switch(_attr->picture_size) {
+			case 0:
+				width = 720;
+				break;
+			case 1:
+				width = 704;
+				break;
+			case 2:
+				width = 352;
+				break;
+			case 3:
+				width = 352;
+				height >>= 1;
+			break;      
+		}
+		return true;
+	}
+	return false;
+}
+
+const uint32_t * IFOFile::GetPalette(unsigned int title, bool language) const
+{
+	IfoContent *_ifo = m_ifos.GetIfoTitle(title);
+	assert(_ifo != NULL);
+	video_attr_t *_attr = NULL;
+	if (language)
+	{
+		return (_ifo->Handle().pgci_ut->lu->pgcit->pgci_srp->pgc->palette);
+	}
+	else
+	{
+		return (_ifo->Handle().vts_pgcit->pgci_srp->pgc->palette);
+	}
+	return NULL;
+}
+
 uint8_t IFOFile::GetAudioId(uint8_t streamID, uint8_t title, bool language) const
 {
 	IfoContent *_ifo = m_ifos.GetIfoTitle(title);
@@ -359,6 +430,8 @@
 	return _ifo->FindSubStream(streamID, language);
 }
 
+// ----------------------------------------------------------------------------
+
 IfoContent::IfoContent(dvd_reader_t *dvdr, int16_t title)
 	:m_title(title)
 {

Modified: trunk/DvdMenuXtractor/IFOFile.h
===================================================================
--- trunk/DvdMenuXtractor/IFOFile.h	2004-10-27 15:02:11 UTC (rev 933)
+++ trunk/DvdMenuXtractor/IFOFile.h	2004-10-27 20:40:13 UTC (rev 934)
@@ -91,6 +91,8 @@
 	const int16_t NumberOfTitles() const;
 	const AudioTrackList & AudioTracks(unsigned int title, bool language) const;
 	const SubtitleTrackList & SubsTracks(unsigned int title, bool language) const;
+	bool VideoSize(unsigned int title, bool language, uint16_t & width, uint16_t & height) const;
+	const uint32_t * GetPalette(unsigned int title, bool language) const;
 
 	uint8_t GetAudioId(uint8_t streamID, uint8_t title, bool language) const;
 	IdArray GetSubsId(uint8_t streamID, uint8_t title, bool language) const;

Modified: trunk/DvdMenuXtractor/VobParser.cpp
===================================================================
--- trunk/DvdMenuXtractor/VobParser.cpp	2004-10-27 15:02:11 UTC (rev 933)
+++ trunk/DvdMenuXtractor/VobParser.cpp	2004-10-27 20:40:13 UTC (rev 934)
@@ -10,6 +10,8 @@
 #include <wx/filename.h>
 WX_DEFINE_LIST(ButtonsListType);
 
+#include "iso/iso_lang.h"
+
 // ----------------------------------------------------------------------------
 
 #define VOB_SLICE			0x00000100
@@ -807,5 +809,58 @@
 	return m_map;
 }
 
+// ----------------------------------------------------------------------------
+ 
+void SubDemuxWriter::WriteTimecodeInfo(int32_t delay, wxString & debug)
+{
+	if (!m_TimecodeFile)
+	{
+		wxString m_filename = m_Filename;
+		m_filename += ".idx";
+		m_TimecodeFile = fopen(m_filename.c_str(),"w");
+		fwrite("# VobSub index file, v7 (do not modify this line!)\n#\n", 1, 53, m_TimecodeFile);
+		fwrite("# Settings\n\n# Original frame size\nsize: ", 1, 40, m_TimecodeFile);
+		fprintf(m_TimecodeFile, "%dx%d\n\n", m_width, m_height);
+		fwrite("# Origin, relative to the upper-left corner, can be overloaded by aligment\n"
+		       "org: 0, 0\n\n"
+		       "# Image scaling (hor,ver), origin is at the upper-left corner or at the alignment coord (x, y)\n"
+		       "scale: 100%, 100%\n\n"
+		       "# Alpha blending\n"
+		       "alpha: 100%\n\n"
+		       "# Smoothing for very blocky images (use OLD for no filtering)\n"
+		       "smooth: OFF\n\n"
+		       "# In millisecs\n"
+		       "fadein/out: 50, 50\n\n"
+		       "# Force subtitle placement relative to (org.x, org.y)\n"
+		       "align: OFF at LEFT TOP\n\n"
+		       "# For correcting non-progressive desync. (in millisecs or hh:mm:ss:ms)\n"
+		       "# Note: Not effective in DirectVobSub, use \"delay: ... \" instead.\n"
+		       "time offset: 0\n\n"
+		       "# ON: displays only forced subtitles, OFF: shows everything\n"
+               "forced subs: OFF\n\n"
+               "# The original palette of the DVD\n"
+			   "palette: ", 1, 692, m_TimecodeFile);
+		for (int i=0; i<15; i++)
+		{
+			fprintf(m_TimecodeFile, "%06x, ", m_palette[i]);
+		}
+		fprintf(m_TimecodeFile, "%06x\n\n", m_palette[i]);
+		fwrite("# Custom colors (transp idxs and the four colors)\n"
+		       "custom colors: OFF, tridx: 0000, colors: 000000, 000000, 000000, 000000\n\n"
+		       "# Language index in use\n"
+		       "langidx: 0\n\n"
+		       "id: ", 1, 163, m_TimecodeFile);
+		if (m_language)
+			fprintf(m_TimecodeFile, "%c%c", m_language >> 8, m_language);
+		else
+			fwrite("un", 1, 2, m_TimecodeFile);
+		fwrite(", index: 0\n"
+		       "# Decomment next line to activate alternative name in DirectVobSub / Windows Media Player 6.x\n"
+		       "# alt: ", 1, 112, m_TimecodeFile);
+        fprintf(m_TimecodeFile, "%s\n\n", DecodeLanguage(m_language));
+	}
+	fwrite(debug.c_str(), 1, debug.length(), m_TimecodeFile);
+}
+
 // ============================================================================
 

Modified: trunk/DvdMenuXtractor/VobParser.h
===================================================================
--- trunk/DvdMenuXtractor/VobParser.h	2004-10-27 15:02:11 UTC (rev 933)
+++ trunk/DvdMenuXtractor/VobParser.h	2004-10-27 20:40:13 UTC (rev 934)
@@ -196,6 +196,16 @@
 			m_file = fopen(m_filename.c_str(),"wb");
 		}
 		fwrite(buff, 1, size, m_file);
+		WriteTimecodeInfo(delay, debug);
+	}
+protected:
+	wxString m_Filename;
+	wxString m_fileExtension;
+	FILE* m_file;
+	FILE* m_TimecodeFile;
+
+	virtual void WriteTimecodeInfo(int32_t delay, wxString & debug)
+	{
 		if (!m_TimecodeFile)
 		{
 			wxString m_filename = m_Filename;
@@ -205,11 +215,6 @@
 		}
 		fwrite(debug.c_str(), 1, debug.length(), m_TimecodeFile);
 	}
-protected:
-	wxString m_Filename;
-	wxString m_fileExtension;
-	FILE* m_file;
-	FILE* m_TimecodeFile;
 };
 
 // ----------------------------------------------------------------------------
@@ -286,14 +291,26 @@
 class SubDemuxWriter : public Demuxer, public Writer
 {
 public:
-	SubDemuxWriter(const char* filenamePrefix, const uint8_t streamID) :
-	  Writer(filenamePrefix, "sub"), m_streamID(streamID) {}
+	SubDemuxWriter(const char* filenamePrefix, const uint8_t streamID, uint16_t width, uint16_t height, const uint32_t * palette, uint16_t language, bool forced)
+		:Writer(filenamePrefix, "sub")
+		,m_width(width)
+		,m_height(height)
+		,m_forced(forced)
+		,m_palette(palette)
+		,m_language(language)
+	{}
 	void ProcessStream(uint8_t* buff, uint32_t size, int32_t delay, wxString & debug)
 	{
 		Write(buff,size, delay, debug);
 	}
+protected:
+	void WriteTimecodeInfo(int32_t delay, wxString & debug);
 private:
-	uint8_t m_streamID;
+	uint16_t m_width;
+	uint16_t m_height;
+	bool m_forced;
+	const uint32_t * m_palette;
+	uint16_t m_language;
 };
 
 // ----------------------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.