+++ /dev/null
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
-/*
- * main.cc
- * Copyright (C) Koichi Akabe 2009 <mail@vbkaisetsu.com>
- *
- * main.cc is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * main.cc is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <iostream>
-#include <stdlib.h>
-#include <string.h>
-
-namespace TsRemux {
- enum TsFileType
- {
- UNKNOWN = 0,
- TS,
- M2TS,
- EVOB,
- ELEMENTARY,
- PES_ELEMENTARY,
- SUP_ELEMENTARY,
- BLU_RAY,
- MKV
- };
-
- enum DtcpCci
- {
- CopyFree = 0,
- NoMoreCopies,
- CopyOnce,
- CopyNever
- };
-
- enum ElementaryStreamTypes
- {
- INVALID = 0,
- VIDEO_STREAM_MPEG1 = 0x01,
- VIDEO_STREAM_MPEG2 = 0x02,
- AUDIO_STREAM_MPEG1 = 0x03, // all layers including mp3
- AUDIO_STREAM_MPEG2 = 0x04,
- VIDEO_STREAM_H264 = 0x1b,
- AUDIO_STREAM_LPCM = 0x80,
- AUDIO_STREAM_AC3 = 0x81,
- AUDIO_STREAM_DTS = 0x82,
- AUDIO_STREAM_AC3_TRUE_HD = 0x83,
- AUDIO_STREAM_AC3_PLUS = 0x84,
- AUDIO_STREAM_DTS_HD = 0x85,
- AUDIO_STREAM_DTS_HD_MASTER_AUDIO = 0x86,
- PRESENTATION_GRAPHICS_STREAM = 0x90,
- INTERACTIVE_GRAPHICS_STREAM = 0x91,
- SUBTITLE_STREAM = 0x92,
- SECONDARY_AUDIO_AC3_PLUS = 0xa1,
- SECONDARY_AUDIO_DTS_HD = 0xa2,
- VIDEO_STREAM_VC1 = 0xea
- };
-
- enum VideoFormat
- {
- VF_Reserved = 0,
- i480,
- i576,
- p480,
- i1080,
- p720,
- p1080,
- p576
- };
-
- enum FrameRate
- {
- FR_Reserved = 0,
- f23_976,
- f24,
- f25,
- f29_97,
- f50 = 6,
- f59_94
- };
-
- enum AspectRatio
- {
- AR_Reserved = 0,
- a4_3 = 2,
- a16_9
- };
-
- enum AudioPresentationType
- {
- APT_Reserved = 0,
- mono,
- stereo = 3,
- multi = 6,
- combo = 12
- };
-
- enum SamplingFrequency
- {
- SF_Reserved = 0,
- kHz48,
- kHz96 = 4,
- kHz192,
- kHz48_192 = 12,
- kHz48_96 = 14
- };
-
- class BluRayOutput
- {
- private:
- char path[512];
- static const char index_bdmv[];
- static const char MovieObject_bdmv[];
- static const char PlayList_00000_mpls[];
- static const char AppInfoPlayList[];
- static const char PgStreamAttributes[];
- static const char ClipInfo_0000_clpi[];
- static const char TsTypeInfoBlock[];
-
- public:
- BluRayOutput(char path[]);
- };
-
- const char BluRayOutput::index_bdmv[] = {
- 0x49, 0x4e, 0x44, 0x58, 0x30, 0x31, 0x30, 0x30, 0x00, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x78,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x26, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
- 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x92, 0x00, 0x00, 0x00, 0x18,
- 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x01, 0x7e,
- 0x49, 0x44, 0x45, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x62, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x36, 0x10, 0x13, 0x00, 0x01,
- 0x54, 0x52, 0x20, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x2e, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x06, 0xff, 0xff, 0x42, 0x20, 0x07, 0x08, 0x08, 0x00, 0x54, 0x53, 0x00, 0x90, 0x0a, 0x54,
- 0x52, 0x20, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x2e, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
- 0x00, 0x00, 0x00, 0x01, 0x30, 0x30, 0x30, 0x30, 0x30, 0x01, 0x00, 0x00, 0x00, 0x00 };
-
- const char BluRayOutput::MovieObject_bdmv[] = {
- 0x4d, 0x4f, 0x42, 0x4a, 0x30, 0x31, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xea, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x03, 0x80, 0x00, 0x00, 0x04, 0x50, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00,
- 0x00, 0x00, 0x50, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x82,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x21, 0x81, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x09, 0x50, 0x00, 0x00, 0x01, 0x00, 0x00,
- 0x00, 0x0a, 0x00, 0x00, 0x00, 0x03, 0x50, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
- 0xff, 0xff, 0x48, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0xff, 0xff, 0x22, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x01, 0x00, 0x00,
- 0x00, 0x0a, 0x00, 0x00, 0x00, 0x04, 0x50, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
- 0x00, 0x00, 0x48, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x21, 0x01,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x21, 0x81, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x05, 0x50, 0x40, 0x00, 0x01, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
- 0x00, 0x01, 0x50, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0xff, 0xff, 0x50, 0x40,
- 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x21, 0x81, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
- const char BluRayOutput::PlayList_00000_mpls[] = {
- 0x4d, 0x50, 0x4c, 0x53, 0x30, 0x31, 0x30, 0x30 };
- const char BluRayOutput::AppInfoPlayList[] = {
- 0x00, 0x00, 0x00, 0x0e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00 };
- const char BluRayOutput::PgStreamAttributes[] = {
- 0x05, 0x90, 0x65, 0x6e, 0x67, 0x00 };
- const char BluRayOutput::ClipInfo_0000_clpi[] = {
- 0x48, 0x44, 0x4d, 0x56, 0x30, 0x31, 0x30, 0x30 };
- const char BluRayOutput::TsTypeInfoBlock[] = {
- 0x00, 0x1e, 0x80, 0x48, 0x44, 0x4d, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
- BluRayOutput::BluRayOutput(char path[])
- {
- char str[512];
- FILE* fp;
- int wrotesize;
- strcpy(this->path, path);
- // remove file
- if(remove(path) == 0)
- {
- printf("INFO: file \"%s\" was removed\n", path);
- }
- // create directories
- sprintf(str, "mkdir \"%s\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s\"\n", path);
- }
- sprintf(str, "mkdir \"%s/BDMV\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s/BDMV\"\n", path);
- }
- sprintf(str, "mkdir \"%s/BDMV/AUXDATA\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s/BDMV/AUXDATA\"\n", path);
- }
- sprintf(str, "mkdir \"%s/BDMV/BACKUP\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s/BDMV/BACKUP\"\n", path);
- }
- sprintf(str, "mkdir \"%s/BDMV/BACKUP/BDJO\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s/BDMV/BACKUP/BDJO\"\n", path);
- }
- sprintf(str, "mkdir \"%s/BDMV/BACKUP/CLIPINF\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s/BDMV/BACKUP/CLIPINF\"\n", path);
- }
- sprintf(str, "mkdir \"%s/BDMV/BACKUP/PLAYLIST\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s/BDMV/BACKUP/PLAYLIST\"\n", path);
- }
- sprintf(str, "mkdir \"%s/BDMV/BDJO\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s/BDMV/BDJO\"\n", path);
- }
- sprintf(str, "mkdir \"%s/BDMV/CLIPINF\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s/BDMV/CLIPINF\"\n", path);
- }
- sprintf(str, "mkdir \"%s/BDMV/JAR\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s/BDMV/JAR\"\n", path);
- }
- sprintf(str, "mkdir \"%s/BDMV/META\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s/BDMV/META\"\n", path);
- }
- sprintf(str, "mkdir \"%s/BDMV/PLAYLIST\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s/BDMV/PLAYLIST\"\n", path);
- }
- sprintf(str, "mkdir \"%s/BDMV/STREAM\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s/BDMV/STREAM\"\n", path);
- }
- sprintf(str, "mkdir \"%s/CERTIFICATE\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s/CERTIFICATE\"\n", path);
- }
- sprintf(str, "mkdir \"%s/CERTIFICATE/BACKUP\"\n", path);
- if(system(str) == -1)
- {
- printf("ERROR: could not create directory \"%s/CERTIFICATE/BACKUP\"\n", path);
- }
- // create files
- sprintf(str, "%s/BDMV/index.bdmv", path);
- fp = fopen(str, "wb");
- if(fp == NULL)
- {
- printf("ERROR: could not create file \"%s/BDMV/index.bdmv\"\n", path);
- }
- wrotesize = fwrite(index_bdmv, 526, sizeof(char), fp);
- fclose(fp);
- sprintf(str, "cp \"%s/BDMV/index.bdmv\" \"%s/BDMV/BACKUP/index.bdmv\"\n", path, path);
- if(system(str) == -1)
- {
- printf("ERROR: could not copy file");
- }
-
- sprintf(str, "%s/BDMV/MovieObject.bdmv", path);
- fp = fopen(str, "wb");
- if(fp == NULL)
- {
- printf("ERROR: could not create file \"%s/BDMV/MovieObject.bdmv\"\n", path);
- }
- wrotesize = fwrite(MovieObject_bdmv, 526, sizeof(char), fp);
- fclose(fp);
- sprintf(str, "cp \"%s/BDMV/MovieObject.bdmv\" \"%s/BDMV/BACKUP/MovieObject.bdmv\"\n", path, path);
- if(system(str) == -1)
- {
- printf("ERROR: could not copy file");
- }
- }
-}
-
-void help()
-{
- printf("TsRemuxCPP\n");
- printf("for C++ developers and console users\n");
- printf("\n");
- printf("Syntax: tsremuxcpp [options] <sourcefile> <outputfile (or directory)>\n");
- printf("\n");
- printf("Options\n");
- printf(" -sup <SUP file> Add a new SUPread stream\n");
- printf(" -ac3 Blu-Ray TrueHD to AC3/DTS HD to DTS\n");
- printf(" -bypass Bypass Audio Alignment\n");
- printf(" -async Use async I/O\n");
- printf(" -format <format> Output format (0: M2TS 192 byte packets, 1: TS 188 byte packets, 2: Blu-Ray, Default: 0)\n");
- printf(" -h Showing help message (this message)\n");
- printf("\n");
-}
-
-int main(int argc, char *argv[])
-{
- // read arguments
- int i;
- char sourcefile[512];
- char outputfile[512];
- char supfile[128][512];
- int ac3mode = 0;
- int bypassmode = 0;
- int asyncmode = 0;
- int format = 0;
- int supfilecounter = 0;
- for(i = 1; i < argc - 2; i++)
- {
- if(argv[i][0] == 0x2d)
- {
- if(strcmp(argv[i], "-sup") == 0)
- {
- i++;
- strcpy(supfile[supfilecounter], argv[i]);
- supfilecounter++;
- }
- else if(strcmp(argv[i], "-ac3") == 0)
- {
- ac3mode = 1;
- }
- else if(strcmp(argv[i], "-bypass") == 0)
- {
- bypassmode = 1;
- }
- else if(strcmp(argv[i], "-async") == 0)
- {
- bypassmode = 1;
- }
- else if(strcmp(argv[i], "-format") == 0)
- {
- i++;
- sscanf(argv[i], "%d", &format);
- }
- else if(strcmp(argv[i], "-h") == 0)
- {
- help();
- return(0);
- }
- else
- {
- printf("ERROR: unknown option: %s\n", argv[i]);
- return 0;
- }
- }
- }
- if(argc == 1)
- {
- help();
- return 0;
- }
- if(argc == 2)
- {
- if(strcmp(argv[1], "-h") == 0)
- help();
- else
- printf("ERROR: syntax error\n");
- return 0;
- }
-
- return 0;
-}