static void Main(string[] args) { var reader = new MvdReader(); var writer = new MvdWriter(); MotoVideo video = reader.ReadVideo(@"C:\LSR\art\frontend\help\help.mvd"); writer.WriteVideo(video, @"C:\LSR\art\frontend\help\help.mvd.out"); }
/// <summary> /// Writes a video to the provided stream. /// </summary> /// <param name="video">The video to write</param> /// <param name="stream">The stream to write the track to</param> public void WriteVideo(MotoVideo video, Stream stream) { this.stream = stream; using (writer = new BinaryWriter(stream)) { writer.Write(MotoVideo.fileMagic); writer.Write((int)video.frames.Count); writer.Write(video.width); writer.Write(video.height); writer.Write(video.bitDepth); foreach (var frame in video.frames) { writer.Write(frame.bytes); } } }
/// <summary> /// Reads a video from the provided stream. /// </summary> /// <param name="stream">The stream to read the video from</param> /// <returns>The video as an object</returns> /// <exception cref="InvalidDataException">Thrown when the video file is formatted incorrectly.</exception> public MotoVideo ReadVideo(Stream stream) { this.stream = stream; var video = new MotoVideo(); using (reader = new BinaryReader(stream)) { var videoHeader = reader.ReadBytes(20); // TODO: equality check for file magic. //if (!videoHeader.Equals(MotoVideo.fileMagic)) throw new InvalidDataException("MVD file has incorrct header!"); var numFrames = ReadInt(); video.numFrames = numFrames; var width = ReadInt(); var height = ReadInt(); video.width = width; video.height = height; var bitDepth = ReadInt(); video.bitDepth = bitDepth; var frameSize = width * height * (bitDepth / 8); for (var fr = 0; fr < numFrames; fr++) { var frame = new MotoVideoFrame(width, height, bitDepth); frame.bytes = reader.ReadBytes(frameSize); if (frame.bytes.Length != frameSize) { throw new InvalidDataException($"Invalid size on frame {fr}!"); } video.frames.Add(frame); } } return(video); }
static void Main(string[] args) { var timer = new Stopwatch(); timer.Start(); var reader = new MvdReader(); MotoVideo video = reader.ReadVideo(@"C:\LSR\art\frontend\help\help.mvd"); timer.Stop(); Console.WriteLine("Loaded and parsed, took {0}ms", timer.ElapsedMilliseconds, video.numFrames); video.GetInfo(); Directory.CreateDirectory("dump"); timer.Restart(); var i = 0; foreach (var frame in video.frames) { frame.DumpFrame("dump/" + i.ToString().PadLeft(4, '0') + ".raw"); i++; } timer.Stop(); Console.WriteLine("Dumping {1} frames took {0}ms", timer.ElapsedMilliseconds, video.numFrames); }
/// <summary> /// Writes a video to a file with the provided filename. /// </summary> /// <param name="video">The video to write</param> /// <param name="filename">The filename to write the track to</param> public void WriteVideo(MotoVideo video, string filename) { var fileStream = File.Open(filename, FileMode.Create); WriteVideo(video, fileStream); }