public static void EncodeFlipnote() { CreateEncodeConfig(); var encoder = new FlipnoteEncoder(); var encoded = encoder.Encode(); if (encoded != null) { Directory.CreateDirectory("tmp"); encoded.Save($"tmp/{encoded.CurrentFilename}.ppm"); if (FlipnoteConfig.Split) { double bytelength = new FileInfo($"tmp/{encoded.CurrentFilename}.ppm").Length; bytelength = bytelength / 1024; Console.WriteLine(bytelength); var MB = bytelength / 1024; if (MB >= 1) { List <PPMFile> files = new List <PPMFile>(); Console.WriteLine(MB); var framesframes = encoded.Frames.ToArray().Split((int)(encoded.Frames.Length / MB + 1)); var audioaudio = encoded.Audio.SoundData.RawBGM.ToArray().Split((int)(encoded.Audio.SoundData.RawBGM.Length / MB + 1)); if (MB > 1.3) { framesframes = encoded.Frames.ToArray().Split((int)(encoded.Frames.Length / MB + 2)); audioaudio = encoded.Audio.SoundData.RawBGM.ToArray().Split((int)(encoded.Audio.SoundData.RawBGM.Length / MB + 2)); } for (int i = 0; i < framesframes.Count(); i++) { var aaa = PPMFile.Create(encoded.CurrentAuthor, framesframes.ToList()[i].ToList(), audioaudio.ToList()[i].ToArray()); aaa.Save($"out/{aaa.CurrentFilename}_{i}.ppm"); } } else { encoded.Save($"out/{encoded.CurrentFilename}.ppm"); } } else { encoded.Save($"out/{encoded.CurrentFilename}.ppm"); } var mp4try = new PPMFile(); mp4try.LoadFrom($"tmp/{encoded.CurrentFilename}.ppm"); Mp4Encoder mp4 = new Mp4Encoder(mp4try); var a = mp4.EncodeMp4("out"); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("There was a problem creating the flipnote."); Console.WriteLine("Please join the support server for further assistance with this issue"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Press any Key to continue..."); Console.ReadKey(); } Cleanup(); }
/// <summary> /// Simple Mp4 Encoder. Requires FFMpeg to be installed in path. /// </summary> /// <param name="flipnote"></param> public Mp4Encoder(PPMFile flipnote) { this.Flipnote = flipnote; }
public PPMFile Encode() { PPMFile Dummy = new PPMFile(); PPMFile encoded = new PPMFile(); LinuxNote.Encoder.Encoder encoder = new LinuxNote.Encoder.Encoder(); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("Getting Dummy..."); try { var DummyPath = Directory.GetFiles("DummyFlipnote", "*.ppm"); Dummy.LoadFrom(DummyPath[0]); Console.CursorLeft = 0; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Dummy got! "); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Could not get Dummy!"); return(null); } try { var audio = encoder.PrepareAudio(); encoder.PrepareFrames(); } catch (Exception e) { } List <PPMFrame> EncodedFrames = new List <PPMFrame>(); Directory.CreateDirectory("out"); try { Console.ForegroundColor = ConsoleColor.Gray; Console.Write("Dithering Frames..."); switch (Config.ColorMode) { case 1: EncodedFrames = encoder.BlackWhiteFrames(Config.InputFolder).ToList(); break; case 2: EncodedFrames = encoder.ThreeColorFrames(Config.InputFolder, PenColor.Red).ToList(); break; case 3: EncodedFrames = encoder.ThreeColorFrames(Config.InputFolder, PenColor.Blue).ToList(); break; case 4: EncodedFrames = encoder.FullColorFrames(Config.InputFolder).ToList(); break; case 5: EncodedFrames = encoder.AutoColorFrames(Config.InputFolder).ToList(); break; default: EncodedFrames = encoder.BlackWhiteFrames(Config.InputFolder).ToList(); break; } Console.CursorLeft = 0; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Frames Dithered! "); } catch (Exception e) { Console.CursorLeft = 0; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Could not dither Frames!"); } if (File.Exists($"{Config.InputFolder}/{Config.InputFilename}.wav")) { Console.ForegroundColor = ConsoleColor.Gray; Console.Write("Preparing Audio..."); using (WaveFileReader reader = new WaveFileReader($"{Config.InputFolder}/{Config.InputFilename}.wav")) { byte[] buffer = new byte[reader.Length]; int read = reader.Read(buffer, 0, buffer.Length); short[] sampleBuffer = new short[read / 2]; Buffer.BlockCopy(buffer, 0, sampleBuffer, 0, read); List <byte> bgm = new List <byte>(); AdpcmEncoder aencoder = new AdpcmEncoder(); for (int i = 0; i < sampleBuffer.Length; i += 2) { try { bgm.Add((byte)(aencoder.Encode(sampleBuffer[i]) | aencoder.Encode(sampleBuffer[i + 1]) << 4)); } catch (Exception e) { } } encoded = PPMFile.Create(Dummy.CurrentAuthor, EncodedFrames, bgm.ToArray()); } Console.CursorLeft = 0; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Audio Prepared! "); } else { Console.CursorLeft = 0; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("No Audio Detected "); encoded = PPMFile.Create(Dummy.CurrentAuthor, EncodedFrames, new List <byte>().ToArray()); } Random rnd = new Random(); //encoded.Thumbnail.Buffer = CreateThumbnailW64(encoded.Frames[0]); //encoded.Save($"out/{encoded.CurrentFilename}.ppm"); return(encoded); }
/// <summary> /// Initialize Audio Decoder /// </summary> /// <param name="input">The Flipnote File as input</param> public AdpcmDecoder(PPMFile input) { this.step_index = 0; this.Flipnote = input; }