public void CDGtoAVI(string aviFileName, string cdgFileName, string mp3FileName, double frameRate, string backgroundFileName = "") { Bitmap backgroundBmp = null; Bitmap mergedBMP = null; VideoStream aviStream = default(VideoStream); CDGFile myCDGFile = new CDGFile(cdgFileName); myCDGFile.renderAtPosition(0); Bitmap bitmap__1 = (Bitmap)myCDGFile.RGBImage; if (!string.IsNullOrEmpty(backgroundFileName)) { try { if (IsMovie(backgroundFileName)) { backgroundBmp = MovieFrameExtractor.GetBitmap(0, backgroundFileName, CDGFile.CDG_FULL_WIDTH, CDGFile.CDG_FULL_HEIGHT); } if (IsGraphic(backgroundFileName)) { backgroundBmp = CDGNet.GraphicUtil.GetCDGSizeBitmap(backgroundFileName); } } catch (Exception ex) { Console.Write(ex.Message); } } AviManager aviManager = new AviManager(aviFileName, false); if (backgroundBmp != null) { mergedBMP = GraphicUtil.MergeImagesWithTransparency(backgroundBmp, bitmap__1); aviStream = aviManager.AddVideoStream(true, frameRate, mergedBMP); mergedBMP.Dispose(); if (IsMovie(backgroundFileName)) { backgroundBmp.Dispose(); } } else { aviStream = aviManager.AddVideoStream(true, frameRate, bitmap__1); } int count = 0; double frameInterval = 1000 / frameRate; long totalDuration = myCDGFile.getTotalDuration(); double position = 0; while (position <= totalDuration) { count += 1; position = count * frameInterval; myCDGFile.renderAtPosition(Convert.ToInt64(position)); bitmap__1 = (Bitmap)myCDGFile.RGBImage; if (!string.IsNullOrEmpty(backgroundFileName)) { if (IsMovie(backgroundFileName)) { backgroundBmp = MovieFrameExtractor.GetBitmap(position / 1000, backgroundFileName, CDGFile.CDG_FULL_WIDTH, CDGFile.CDG_FULL_HEIGHT); } } if (backgroundBmp != null) { mergedBMP = GraphicUtil.MergeImagesWithTransparency(backgroundBmp, bitmap__1); aviStream.AddFrame(mergedBMP); mergedBMP.Dispose(); if (IsMovie(backgroundFileName)) { backgroundBmp.Dispose(); } } else { aviStream.AddFrame(bitmap__1); } bitmap__1.Dispose(); double percentageDone = (position / totalDuration) * 100; if (Status != null) { Status(percentageDone.ToString()); } Application.DoEvents(); } myCDGFile.Dispose(); aviManager.Close(); if (backgroundBmp != null) { backgroundBmp.Dispose(); } // Add MP3 to AVI Console.Write("|nAVI terminated, add MP3 to AVI"); AddMP3toAVI(aviFileName, mp3FileName); }
private void Play() { try { if ((mMP3Stream != 0) && Bass.BASS_ChannelIsActive(mMP3Stream) == BASSActive.BASS_ACTIVE_PLAYING) { StopPlayback(); } PreProcessFiles(); if (mCDGFileName == null || mMP3FileName == null) { MessageBox.Show("Cannot find a CDG and MP3 file to play together."); StopPlayback(); return; } mPaused = false; mStop = false; mFrameCount = 0; mCDGFile = new CDGFile(mCDGFileName); cdgpos = 0; long cdgLength = mCDGFile.getTotalDuration(); // Display progress startProgress(cdgLength); // Show frmCDGWindow ici PlayMP3Bass(mMP3FileName); DateTime startTime = DateTime.Now; DateTime endTime = startTime.AddMilliseconds(cdgLength); long millisecondsRemaining = cdgLength; while (millisecondsRemaining > 0) { if (mStop) { break; } millisecondsRemaining = (long)endTime.Subtract(DateTime.Now).TotalMilliseconds; cdgpos = cdgLength - millisecondsRemaining; while (mPaused) { endTime = DateTime.Now.AddMilliseconds(millisecondsRemaining); Application.DoEvents(); } mCDGFile.renderAtPosition(cdgpos); mFrameCount += 1; mCDGWindow.PictureBox1.Image = mCDGFile.RGBImage; Bitmap mbmp = new Bitmap(mCDGFile.RGBImage); mCDGWindow.PictureBox1.BackColor = mbmp.GetPixel(1, 1); mCDGWindow.PictureBox1.Refresh(); // TODO //float myFrameRate = (float)Math.Round(mFrameCount / (pos / 1000), 1); Application.DoEvents(); } StopPlayback(); } catch (Exception ex) { Console.Write("\n" + ex.Message); } }