2019-01-29 18:16:23 +00:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Program.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : VideoNow analyzing and decoding tools.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Main program loop.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program 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.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
// Copyright © 2011-2019 Natalia Portillo
|
|
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2019-01-29 18:50:07 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2019-01-29 18:16:23 +00:00
|
|
|
|
using System.Reflection;
|
2019-02-10 14:51:10 +00:00
|
|
|
|
using SharpAvi;
|
|
|
|
|
|
using SharpAvi.Output;
|
2019-02-10 22:40:23 +00:00
|
|
|
|
|
2019-02-10 16:25:24 +00:00
|
|
|
|
// ReSharper disable LocalizableElement
|
2019-01-29 18:16:23 +00:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.VideoNow
|
|
|
|
|
|
{
|
2019-02-10 15:39:15 +00:00
|
|
|
|
internal static class MainClass
|
2019-01-29 18:16:23 +00:00
|
|
|
|
{
|
2019-02-10 15:39:15 +00:00
|
|
|
|
const int MAX_SIZE = 635040000;
|
|
|
|
|
|
static string assemblyCopyright;
|
|
|
|
|
|
static string assemblyTitle;
|
|
|
|
|
|
static AssemblyInformationalVersionAttribute assemblyVersion;
|
|
|
|
|
|
|
2019-01-30 20:35:49 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This is some kind of header. Every 10 bytes there's an audio byte. Here it is without reordering from little
|
|
|
|
|
|
/// endian, so the first appearence is at 9th byte.
|
|
|
|
|
|
/// </summary>
|
2019-02-10 15:39:15 +00:00
|
|
|
|
static readonly byte[] FrameMarker =
|
2019-01-30 20:35:49 +00:00
|
|
|
|
{
|
2019-02-10 15:39:15 +00:00
|
|
|
|
0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81,
|
|
|
|
|
|
0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7,
|
|
|
|
|
|
0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3,
|
|
|
|
|
|
0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81,
|
|
|
|
|
|
0xC7, 0xE3, 0x81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B, 0x35, 0x1D, 0x36, 0x1F, 0x37, 0xFF, 0x00, 0x00, 0x38, 0x02, 0x39,
|
|
|
|
|
|
0x04, 0x3A, 0x06, 0x3B, 0xFF, 0x00, 0x08, 0x3C, 0x0A, 0x3D, 0x0C, 0x3E, 0x0E, 0x3F, 0xFF, 0x00, 0x11, 0x40,
|
|
|
|
|
|
0x13, 0x41, 0x15, 0x42, 0x17, 0x43, 0xFF, 0x00, 0x19, 0x44, 0x1B, 0x45, 0x1D, 0x46, 0x1F, 0x47, 0xFF, 0x00,
|
|
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
|
|
0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
|
|
0xFF, 0xFF, 0xFF, 0x00
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-01-29 18:16:23 +00:00
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
object[] attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
|
2019-02-10 15:39:15 +00:00
|
|
|
|
assemblyTitle = ((AssemblyTitleAttribute)attributes[0]).Title;
|
2019-01-29 18:16:23 +00:00
|
|
|
|
attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
|
|
|
|
|
assemblyVersion =
|
2019-01-29 18:16:23 +00:00
|
|
|
|
Attribute.GetCustomAttribute(typeof(MainClass).Assembly, typeof(AssemblyInformationalVersionAttribute))
|
|
|
|
|
|
as AssemblyInformationalVersionAttribute;
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
|
|
|
|
|
assemblyCopyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
|
2019-01-29 18:16:23 +00:00
|
|
|
|
|
|
|
|
|
|
PrintCopyright();
|
2019-01-29 18:50:07 +00:00
|
|
|
|
|
|
|
|
|
|
if(args.Length != 1)
|
|
|
|
|
|
{
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.WriteLine(Localization.Usage);
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-29 18:50:07 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!File.Exists(args[0]))
|
|
|
|
|
|
{
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.WriteLine(Localization.FileDoesNotExist);
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-29 18:50:07 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FileStream fs;
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
fs = File.Open(args[0], FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
|
|
|
|
}
|
2019-01-29 18:50:07 +00:00
|
|
|
|
catch
|
|
|
|
|
|
{
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.WriteLine(Localization.FileCannotBeOpened);
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-29 18:50:07 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-10 15:39:15 +00:00
|
|
|
|
if(fs.Length > MAX_SIZE)
|
2019-01-29 18:50:07 +00:00
|
|
|
|
{
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.WriteLine(Localization.FileIsTooBig);
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-29 18:50:07 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.WriteLine(Localization.FileName, args[0]);
|
|
|
|
|
|
Console.WriteLine(Localization.SearchingFirstFrame);
|
2019-01-29 18:50:07 +00:00
|
|
|
|
|
2019-01-29 20:42:19 +00:00
|
|
|
|
long framePosition = 0;
|
2019-02-10 15:39:15 +00:00
|
|
|
|
byte[] buffer = new byte[FrameMarker.Length];
|
2019-02-10 16:03:10 +00:00
|
|
|
|
byte[] swappedBuffer = new byte[FrameMarker.Length];
|
|
|
|
|
|
bool swapped = false;
|
2019-01-29 18:50:07 +00:00
|
|
|
|
|
|
|
|
|
|
while(framePosition < 19600)
|
|
|
|
|
|
{
|
|
|
|
|
|
fs.Position = framePosition;
|
|
|
|
|
|
fs.Read(buffer, 0, buffer.Length);
|
|
|
|
|
|
|
2019-02-10 15:39:15 +00:00
|
|
|
|
for(int ab = 8; ab < buffer.Length; ab += 10)
|
|
|
|
|
|
buffer[ab] = 0;
|
2019-01-30 20:35:49 +00:00
|
|
|
|
|
2019-02-10 15:39:15 +00:00
|
|
|
|
if(buffer.SequenceEqual(FrameMarker))
|
|
|
|
|
|
break;
|
2019-01-29 18:50:07 +00:00
|
|
|
|
|
2019-02-10 16:03:10 +00:00
|
|
|
|
fs.Position = framePosition;
|
|
|
|
|
|
fs.Read(swappedBuffer, 0, swappedBuffer.Length);
|
|
|
|
|
|
|
|
|
|
|
|
for(int ab = 9; ab < swappedBuffer.Length; ab += 10)
|
|
|
|
|
|
swappedBuffer[ab] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if(swappedBuffer.SequenceEqual(SwappedFrameMarker))
|
|
|
|
|
|
{
|
|
|
|
|
|
swapped = true;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-29 18:50:07 +00:00
|
|
|
|
framePosition++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-10 15:39:15 +00:00
|
|
|
|
for(int ab = 8; ab < buffer.Length; ab += 10)
|
|
|
|
|
|
buffer[ab] = 0;
|
2019-01-30 20:35:49 +00:00
|
|
|
|
|
2019-02-10 16:03:10 +00:00
|
|
|
|
for(int ab = 9; ab < swappedBuffer.Length; ab += 10)
|
|
|
|
|
|
swappedBuffer[ab] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if(!buffer.SequenceEqual(FrameMarker) &&
|
|
|
|
|
|
!swappedBuffer.SequenceEqual(SwappedFrameMarker))
|
2019-01-29 18:50:07 +00:00
|
|
|
|
{
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.WriteLine(Localization.NoFrameFound);
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-29 18:50:07 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.WriteLine(Localization.FirstFrameFoundAt, framePosition);
|
2019-02-10 22:40:23 +00:00
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(framePosition % 2352 == 0 ? Localization.FirstFrameIsAtSectorBoundary
|
|
|
|
|
|
: Localization.FirstFrameIsNotAtSectorBoundary);
|
|
|
|
|
|
|
2019-01-30 23:10:55 +00:00
|
|
|
|
char progress = ' ';
|
2019-01-29 20:42:19 +00:00
|
|
|
|
|
2019-02-10 15:39:15 +00:00
|
|
|
|
var aviWriter = new AviWriter(args[0] + ".avi")
|
|
|
|
|
|
{
|
|
|
|
|
|
EmitIndex1 = true, FramesPerSecond = 18
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-02-10 14:51:10 +00:00
|
|
|
|
IAviVideoStream videoStream = aviWriter.AddVideoStream(144, 80, BitsPerPixel.Bpp24);
|
|
|
|
|
|
videoStream.Codec = KnownFourCCs.Codecs.Uncompressed;
|
2019-02-10 15:39:15 +00:00
|
|
|
|
IAviAudioStream audioStream = aviWriter.AddAudioStream(2, 17640, 8);
|
2019-01-30 23:10:55 +00:00
|
|
|
|
|
2019-02-09 00:57:29 +00:00
|
|
|
|
fs.Position = framePosition;
|
|
|
|
|
|
byte[] frameBuffer = new byte[19600];
|
|
|
|
|
|
fs.Read(frameBuffer, 0, frameBuffer.Length);
|
2019-02-10 16:03:10 +00:00
|
|
|
|
|
|
|
|
|
|
int audioStart = swapped ? 9 : 8;
|
|
|
|
|
|
byte[] frameMarkerToUse = swapped ? SwappedFrameMarker : FrameMarker;
|
|
|
|
|
|
|
|
|
|
|
|
if(!swapped)
|
|
|
|
|
|
frameBuffer = SwapBuffer(frameBuffer);
|
2019-02-09 00:57:29 +00:00
|
|
|
|
|
2019-02-10 14:51:10 +00:00
|
|
|
|
var outFs = new MemoryStream();
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-09 00:57:29 +00:00
|
|
|
|
for(int i = 9; i <= frameBuffer.Length; i += 10)
|
2019-01-30 23:10:55 +00:00
|
|
|
|
{
|
2019-02-09 00:57:29 +00:00
|
|
|
|
switch(i / 10 % 4)
|
2019-01-30 23:10:55 +00:00
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
progress = '-';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-30 23:10:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
progress = '\\';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-30 23:10:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
progress = '|';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-30 23:10:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
progress = '/';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-30 23:10:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.Write($"\r{Localization.ExtractingAudio}", progress);
|
2019-02-09 00:57:29 +00:00
|
|
|
|
outFs.WriteByte(frameBuffer[i]);
|
2019-01-30 23:10:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-10 14:51:10 +00:00
|
|
|
|
byte[] videoFrame = DecodeFrame(frameBuffer);
|
|
|
|
|
|
videoStream.WriteFrame(true, videoFrame, 0, videoFrame.Length);
|
|
|
|
|
|
audioStream.WriteBlock(outFs.ToArray(), 0, (int)outFs.Length);
|
2019-02-10 01:09:55 +00:00
|
|
|
|
|
2019-01-30 23:10:55 +00:00
|
|
|
|
int totalFrames = 1;
|
2019-01-29 20:42:19 +00:00
|
|
|
|
framePosition += 19600;
|
2019-02-10 16:03:10 +00:00
|
|
|
|
buffer = new byte[frameMarkerToUse.Length];
|
2019-01-29 20:42:19 +00:00
|
|
|
|
|
|
|
|
|
|
while(framePosition + 19600 < fs.Length)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch(totalFrames % 4)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
progress = '-';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-29 20:42:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
progress = '\\';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-29 20:42:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
progress = '|';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-29 20:42:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
progress = '/';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-29 20:42:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.Write($"\r{Localization.LookingForMoreFrames}", progress);
|
2019-01-29 20:42:19 +00:00
|
|
|
|
|
2019-02-10 16:03:10 +00:00
|
|
|
|
for(int ab = audioStart; ab < buffer.Length; ab += 10)
|
2019-02-10 15:39:15 +00:00
|
|
|
|
buffer[ab] = 0;
|
2019-01-30 20:35:49 +00:00
|
|
|
|
|
2019-02-10 16:03:10 +00:00
|
|
|
|
if(!buffer.SequenceEqual(frameMarkerToUse))
|
2019-01-29 20:42:19 +00:00
|
|
|
|
{
|
2019-02-10 22:40:23 +00:00
|
|
|
|
Console.Write("\r \r");
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.WriteLine(Localization.FrameAndNextAreNotAligned, totalFrames);
|
2019-01-29 20:42:19 +00:00
|
|
|
|
long expectedFramePosition = framePosition;
|
|
|
|
|
|
|
|
|
|
|
|
while(framePosition < fs.Length)
|
|
|
|
|
|
{
|
|
|
|
|
|
fs.Position = framePosition;
|
|
|
|
|
|
fs.Read(buffer, 0, buffer.Length);
|
|
|
|
|
|
|
2019-02-10 16:03:10 +00:00
|
|
|
|
for(int ab = audioStart; ab < buffer.Length; ab += 10)
|
2019-02-10 15:39:15 +00:00
|
|
|
|
buffer[ab] = 0;
|
2019-01-30 20:35:49 +00:00
|
|
|
|
|
2019-02-10 16:03:10 +00:00
|
|
|
|
if(buffer.SequenceEqual(frameMarkerToUse))
|
2019-01-29 20:42:19 +00:00
|
|
|
|
{
|
2019-02-10 22:40:23 +00:00
|
|
|
|
Console.Write("\r \r");
|
2019-02-09 00:57:29 +00:00
|
|
|
|
|
|
|
|
|
|
fs.Position = framePosition;
|
|
|
|
|
|
frameBuffer = new byte[19600];
|
|
|
|
|
|
fs.Read(frameBuffer, 0, frameBuffer.Length);
|
2019-02-10 16:03:10 +00:00
|
|
|
|
|
|
|
|
|
|
if(!swapped)
|
|
|
|
|
|
frameBuffer = SwapBuffer(frameBuffer);
|
2019-02-09 00:57:29 +00:00
|
|
|
|
|
2019-02-10 14:51:10 +00:00
|
|
|
|
outFs = new MemoryStream();
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-09 00:57:29 +00:00
|
|
|
|
for(int i = 9; i <= frameBuffer.Length; i += 10)
|
2019-01-30 23:10:55 +00:00
|
|
|
|
{
|
2019-02-09 00:57:29 +00:00
|
|
|
|
switch(i / 10 % 4)
|
2019-01-30 23:10:55 +00:00
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
progress = '-';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-30 23:10:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
progress = '\\';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-30 23:10:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
progress = '|';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-30 23:10:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
progress = '/';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-30 23:10:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.Write($"\r{Localization.ExtractingAudio}", progress);
|
2019-02-09 00:57:29 +00:00
|
|
|
|
outFs.WriteByte(frameBuffer[i]);
|
2019-01-30 23:10:55 +00:00
|
|
|
|
}
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 14:51:10 +00:00
|
|
|
|
videoFrame = DecodeFrame(frameBuffer);
|
|
|
|
|
|
videoStream.WriteFrame(true, videoFrame, 0, videoFrame.Length);
|
|
|
|
|
|
audioStream.WriteBlock(outFs.ToArray(), 0, (int)outFs.Length);
|
2019-01-30 23:10:55 +00:00
|
|
|
|
|
2019-01-29 20:42:19 +00:00
|
|
|
|
totalFrames++;
|
2019-02-10 22:40:23 +00:00
|
|
|
|
Console.Write("\r \r");
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.WriteLine(Localization.FrameFoundAtPosition, framePosition, totalFrames,
|
2019-01-29 20:42:19 +00:00
|
|
|
|
framePosition - expectedFramePosition);
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 22:40:23 +00:00
|
|
|
|
Console.
|
|
|
|
|
|
WriteLine(framePosition % 2352 == 0 ? Localization.FrameIsAtSectorBoundary : Localization.FrameIsNotAtSectorBoundary,
|
|
|
|
|
|
totalFrames);
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-29 20:42:19 +00:00
|
|
|
|
framePosition += 19600;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
framePosition++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(framePosition % 2352 == 0)
|
|
|
|
|
|
{
|
2019-02-10 22:40:23 +00:00
|
|
|
|
Console.Write("\r \r");
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.WriteLine(Localization.FrameIsAtSectorBoundary, totalFrames);
|
2019-01-29 20:42:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-10 22:40:23 +00:00
|
|
|
|
Console.Write("\r \r");
|
2019-02-09 00:57:29 +00:00
|
|
|
|
fs.Position = framePosition;
|
|
|
|
|
|
frameBuffer = new byte[19600];
|
|
|
|
|
|
fs.Read(frameBuffer, 0, frameBuffer.Length);
|
2019-02-10 16:03:10 +00:00
|
|
|
|
|
|
|
|
|
|
if(!swapped)
|
|
|
|
|
|
frameBuffer = SwapBuffer(frameBuffer);
|
2019-02-09 00:57:29 +00:00
|
|
|
|
|
2019-02-10 14:51:10 +00:00
|
|
|
|
outFs = new MemoryStream();
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-09 00:57:29 +00:00
|
|
|
|
for(int i = 9; i <= frameBuffer.Length; i += 10)
|
2019-01-30 23:10:55 +00:00
|
|
|
|
{
|
2019-02-09 00:57:29 +00:00
|
|
|
|
switch(i / 10 % 4)
|
2019-01-30 23:10:55 +00:00
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
progress = '-';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-30 23:10:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
progress = '\\';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-30 23:10:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
progress = '|';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-30 23:10:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
progress = '/';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-01-30 23:10:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.Write($"\r{Localization.ExtractingAudio}", progress);
|
2019-02-09 00:57:29 +00:00
|
|
|
|
outFs.WriteByte(frameBuffer[i]);
|
2019-01-30 23:10:55 +00:00
|
|
|
|
}
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 14:51:10 +00:00
|
|
|
|
videoFrame = DecodeFrame(frameBuffer);
|
|
|
|
|
|
videoStream.WriteFrame(true, videoFrame, 0, videoFrame.Length);
|
|
|
|
|
|
audioStream.WriteBlock(outFs.ToArray(), 0, (int)outFs.Length);
|
2019-01-30 23:10:55 +00:00
|
|
|
|
|
2019-01-29 20:42:19 +00:00
|
|
|
|
totalFrames++;
|
|
|
|
|
|
fs.Position = framePosition;
|
|
|
|
|
|
fs.Read(buffer, 0, buffer.Length);
|
|
|
|
|
|
framePosition += 19600;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-10 22:40:23 +00:00
|
|
|
|
Console.Write("\r \r");
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.WriteLine(Localization.FramesFound, totalFrames);
|
2019-01-30 23:10:55 +00:00
|
|
|
|
|
|
|
|
|
|
fs.Close();
|
|
|
|
|
|
outFs.Close();
|
2019-02-10 14:51:10 +00:00
|
|
|
|
aviWriter.Close();
|
2019-01-29 18:16:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void PrintCopyright()
|
|
|
|
|
|
{
|
2019-02-10 15:39:15 +00:00
|
|
|
|
Console.WriteLine("{0} {1}", assemblyTitle, assemblyVersion?.InformationalVersion);
|
|
|
|
|
|
Console.WriteLine("{0}", assemblyCopyright);
|
2019-01-29 18:16:23 +00:00
|
|
|
|
Console.WriteLine();
|
|
|
|
|
|
}
|
2019-02-09 00:57:29 +00:00
|
|
|
|
|
|
|
|
|
|
static byte[] SwapBuffer(byte[] buffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] tmp = new byte[buffer.Length];
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-09 00:57:29 +00:00
|
|
|
|
for(int i = 0; i < buffer.Length; i += 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
tmp[i] = buffer[i + 1];
|
|
|
|
|
|
tmp[i + 1] = buffer[i];
|
|
|
|
|
|
}
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-09 00:57:29 +00:00
|
|
|
|
return tmp;
|
|
|
|
|
|
}
|
2019-02-10 01:09:55 +00:00
|
|
|
|
|
|
|
|
|
|
static byte[] DecodeFrame(byte[] frameBuffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
char progress = ' ';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
var videoFs = new MemoryStream();
|
2019-02-10 01:09:55 +00:00
|
|
|
|
Array.Reverse(frameBuffer);
|
|
|
|
|
|
byte r, g, b;
|
|
|
|
|
|
|
|
|
|
|
|
int index = 1;
|
|
|
|
|
|
int indexBlock2;
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 01:09:55 +00:00
|
|
|
|
for(int i = 0; i < 19200; i += 240)
|
|
|
|
|
|
{
|
|
|
|
|
|
for(int k = 0; k < 120; k += 10)
|
|
|
|
|
|
{
|
|
|
|
|
|
for(int j = 1; j < 9; j += 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
indexBlock2 = index + 120;
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 01:09:55 +00:00
|
|
|
|
switch(index / 10 % 4)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
progress = '-';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 01:09:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
progress = '\\';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 01:09:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
progress = '|';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 01:09:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
progress = '/';
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 01:09:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-10 16:25:24 +00:00
|
|
|
|
Console.Write($"\r{Localization.ExtractingVideo}", progress);
|
2019-02-10 15:39:15 +00:00
|
|
|
|
r = (byte)((frameBuffer[index] & 0xF0) + ((frameBuffer[index] & 0xF0) >> 4));
|
|
|
|
|
|
b = (byte)((frameBuffer[indexBlock2] & 0xF0) + ((frameBuffer[indexBlock2] & 0xF0) >> 4));
|
|
|
|
|
|
g = (byte)((frameBuffer[indexBlock2] & 0x0F) + ((frameBuffer[indexBlock2] & 0x0F) << 4));
|
2019-02-10 01:09:55 +00:00
|
|
|
|
videoFs.WriteByte(r);
|
|
|
|
|
|
videoFs.WriteByte(g);
|
|
|
|
|
|
videoFs.WriteByte(b);
|
|
|
|
|
|
|
|
|
|
|
|
r = (byte)((frameBuffer[indexBlock2 + 1] & 0xF0) +
|
|
|
|
|
|
((frameBuffer[indexBlock2 + 1] & 0xF0) >> 4));
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
|
|
|
|
|
b = (byte)((frameBuffer[index] & 0x0F) + ((frameBuffer[index] & 0x0F) << 4));
|
2019-02-10 01:09:55 +00:00
|
|
|
|
g = (byte)((frameBuffer[index + 1] & 0xF0) + ((frameBuffer[index + 1] & 0xF0) >> 4));
|
|
|
|
|
|
videoFs.WriteByte(r);
|
|
|
|
|
|
videoFs.WriteByte(g);
|
|
|
|
|
|
videoFs.WriteByte(b);
|
|
|
|
|
|
|
|
|
|
|
|
r = (byte)((frameBuffer[index + 1] & 0x0F) + ((frameBuffer[index + 1] & 0x0F) << 4));
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 01:09:55 +00:00
|
|
|
|
b = (byte)((frameBuffer[indexBlock2 + 1] & 0x0F) +
|
|
|
|
|
|
((frameBuffer[indexBlock2 + 1] & 0x0F) << 4));
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 01:09:55 +00:00
|
|
|
|
g = (byte)((frameBuffer[indexBlock2 + 2] & 0xF0) +
|
|
|
|
|
|
((frameBuffer[indexBlock2 + 2] & 0xF0) >> 4));
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 01:09:55 +00:00
|
|
|
|
videoFs.WriteByte(r);
|
|
|
|
|
|
videoFs.WriteByte(g);
|
|
|
|
|
|
videoFs.WriteByte(b);
|
|
|
|
|
|
|
|
|
|
|
|
r = (byte)((frameBuffer[index + 120 + 2] & 0x0F) +
|
|
|
|
|
|
((frameBuffer[index + 120 + 2] & 0x0F) << 4));
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 01:09:55 +00:00
|
|
|
|
b = (byte)((frameBuffer[index + 2] & 0xF0) + ((frameBuffer[index + 2] & 0xF0) >> 4));
|
|
|
|
|
|
g = (byte)((frameBuffer[index + 2] & 0x0F) + ((frameBuffer[index + 2] & 0x0F) << 4));
|
|
|
|
|
|
videoFs.WriteByte(r);
|
|
|
|
|
|
videoFs.WriteByte(g);
|
|
|
|
|
|
videoFs.WriteByte(b);
|
|
|
|
|
|
|
|
|
|
|
|
index += 3;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
index += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-10 15:39:15 +00:00
|
|
|
|
index += 120;
|
2019-02-10 01:09:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
frameBuffer = videoFs.ToArray();
|
2019-02-10 14:51:10 +00:00
|
|
|
|
Array.Reverse(frameBuffer);
|
2019-02-10 15:39:15 +00:00
|
|
|
|
|
2019-02-10 01:09:55 +00:00
|
|
|
|
return frameBuffer;
|
|
|
|
|
|
}
|
2019-01-29 18:16:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|