Example #1
0
        private double R2;         // def: 0.1

        public Background0001(string discJacketFile, double r1 = 0.2, double r2 = 0.1)
        {
            this.DiscJacket         = new Canvas2(discJacketFile);
            this.BluredDiscJacket   = PictureUtils.Blur(this.DiscJacket, 5);           // 要調整
            this.MarginedDiscJacket = PictureUtils.PutMargin(this.DiscJacket);

            this.R1 = r1;
            this.R2 = r2;
        }
Example #2
0
        public void MakeVideo(WaveData wave, WorkingDir wd, Action <Canvas2> addImage)
        {
            this.DiscJacket         = new Canvas2(this.DiscJacketFile);
            this.BluredDiscJacket   = PictureUtils.Blur(this.DiscJacket, 5);           // 要調整
            this.MarginedDiscJacket = PictureUtils.PutMargin(this.DiscJacket);

            ShadowSpectraData ss = new ShadowSpectraData();
            FadeInOutData     f1 = new FadeInOutData()
            {
                MaxValue = 20
            };
            FadeInOutData f2 = new FadeInOutData();

            f1.Rate = 1.0;

            int frameNum = DoubleTools.ToInt((wave.Length * 1.0 / wave.WavHz) * AudioPicMP4Props.FPS);

            for (int frame = 0; frame < frameNum; frame++)
            {
                if (frame == 2 * AudioPicMP4Props.FPS)
                {
                    f1.TargetRate = 0.0;
                }

                if (frame == frameNum - 10 - f2.MaxValue)
                {
                    f2.TargetRate = 1.0;
                }

                f1.Approach();
                f2.Approach();

                double rate    = frame * 1.0 / (frameNum - 1);
                double invRate = 1.0 - rate;

                double r1 = 1.0 + 0.2 * rate;
                double r2 = 1.0 + 0.1 * invRate;

                D4Rect wallRect;
                D4Rect frntRect;

                {
                    D2Size size = Utils.TangentSize(
                        new D2Size(AudioPicMP4Props.VIDEO_W, AudioPicMP4Props.VIDEO_H),
                        new D2Size(this.DiscJacket.GetWidth(), this.DiscJacket.GetHeight()),
                        false
                        );

                    size.W *= r1;
                    size.H *= r1;

                    wallRect = Utils.Centering(new D2Size(AudioPicMP4Props.VIDEO_W, AudioPicMP4Props.VIDEO_H), size);
                }

                {
                    D2Size size = Utils.TangentSize(
                        new D2Size(AudioPicMP4Props.VIDEO_W, AudioPicMP4Props.VIDEO_H),
                        new D2Size(this.DiscJacket.GetWidth(), this.DiscJacket.GetHeight()),
                        true
                        );

                    size.W *= r2;
                    size.H *= r2;

                    // マージン分
                    size.W *= this.MarginedDiscJacket.GetWidth() * 1.0 / this.DiscJacket.GetWidth();
                    size.H *= this.MarginedDiscJacket.GetHeight() * 1.0 / this.DiscJacket.GetHeight();

                    frntRect = Utils.Centering(new D2Size(AudioPicMP4Props.VIDEO_W, AudioPicMP4Props.VIDEO_H), size);
                }

                Canvas2 frameImg = new Canvas2(AudioPicMP4Props.VIDEO_W, AudioPicMP4Props.VIDEO_H);

                PictureUtils.Paste(frameImg, this.BluredDiscJacket, wallRect);
                PictureUtils.Filter(frameImg, Color.Black, 0.5);                 // 要調整
                PictureUtils.Paste(frameImg, this.MarginedDiscJacket, frntRect);
                PictureUtils.Filter(frameImg, Color.Black, 0.1);                 // 要調整

                PictureUtils.Filter(frameImg, Color.Black, f1.Rate);             // 背景カーテン

                wave.SetWavPart(DoubleTools.ToInt((frame * 1.0 / AudioPicMP4Props.FPS + AudioPicMP4Props.AUDIO_DELAY_SEC) * wave.WavHz));
                SpectrumGraph0001 sg = new SpectrumGraph0001(hz => wave.GetSpectrum(hz));
                ss.Projection(sg.Spectra);
                this.DrawSpectra(frameImg, sg, ss);

                PictureUtils.Filter(frameImg, Color.Black, f2.Rate);                 // 前景カーテン

                addImage(frameImg);
            }
        }
Example #3
0
        private void MakeMovie_Main()
        {
            this.DiscJacket         = new Canvas2(this.DiscJacketFile);
            this.BluredDiscJacket   = PictureUtils.Blur(this.DiscJacket, 5);           // 要調整
            this.MarginedDiscJacket = PictureUtils.PutMargin(this.DiscJacket);

            {
                string wavFile       = this.WD.GetPath("audio.wav");
                string masterWavFile = this.WD.GetPath("audio2.wav");

                FFmpegConv.MakeWavFile(this.SourceMediaFile, wavFile);

                if (this.MasterFlag && MasterUtils.Mastering(wavFile, masterWavFile))
                {
                    this.Wave = new WaveData(masterWavFile);
                    this.FFmpeg.Audio.PutAudioFile(masterWavFile);
                }
                else
                {
                    this.Wave = new WaveData(wavFile);
                    this.FFmpeg.Audio.PutAudioFile(this.SourceMediaFile);
                }
            }

            ShadowSpectraData ss = new ShadowSpectraData();
            FadeInOutData     f1 = new FadeInOutData()
            {
                MaxValue = 20
            };
            FadeInOutData f2 = new FadeInOutData();

            f1.Rate = 1.0;

            int frameNum = DoubleTools.ToInt((this.Wave.Length * 1.0 / this.Wave.WavHz) * AudioPicMP4Props.FPS);

            for (int frame = 0; frame < frameNum; frame++)
            {
                if (frame == 2 * AudioPicMP4Props.FPS)
                {
                    f1.TargetRate = 0.0;
                }

                if (frame == frameNum - 10 - f2.MaxValue)
                {
                    f2.TargetRate = 1.0;
                }

                f1.Approach();
                f2.Approach();

                double rate    = frame * 1.0 / (frameNum - 1);
                double invRate = 1.0 - rate;

                double r1 = 1.0 + 0.2 * rate;
                double r2 = 1.0 + 0.1 * invRate;

                D4Rect wallRect;
                D4Rect frntRect;

                {
                    D2Size size = Utils.TangentSize(
                        new D2Size(AudioPicMP4Props.VIDEO_W, AudioPicMP4Props.VIDEO_H),
                        new D2Size(this.DiscJacket.GetWidth(), this.DiscJacket.GetHeight()),
                        false
                        );

                    size.W *= r1;
                    size.H *= r1;

                    wallRect = Utils.Centering(new D2Size(AudioPicMP4Props.VIDEO_W, AudioPicMP4Props.VIDEO_H), size);
                }

                {
                    D2Size size = Utils.TangentSize(
                        new D2Size(AudioPicMP4Props.VIDEO_W, AudioPicMP4Props.VIDEO_H),
                        new D2Size(this.DiscJacket.GetWidth(), this.DiscJacket.GetHeight()),
                        true
                        );

                    size.W *= r2;
                    size.H *= r2;

                    // マージン分
                    size.W *= this.MarginedDiscJacket.GetWidth() * 1.0 / this.DiscJacket.GetWidth();
                    size.H *= this.MarginedDiscJacket.GetHeight() * 1.0 / this.DiscJacket.GetHeight();

                    frntRect = Utils.Centering(new D2Size(AudioPicMP4Props.VIDEO_W, AudioPicMP4Props.VIDEO_H), size);
                }

                Canvas2 frameImg = new Canvas2(AudioPicMP4Props.VIDEO_W, AudioPicMP4Props.VIDEO_H);

                PictureUtils.Paste(frameImg, this.BluredDiscJacket, wallRect);
                PictureUtils.Filter(frameImg, Color.Black, 0.5);                 // 要調整
                PictureUtils.Paste(frameImg, this.MarginedDiscJacket, frntRect);
                PictureUtils.Filter(frameImg, Color.Black, 0.1);                 // 要調整

                PictureUtils.Filter(frameImg, Color.Black, f1.Rate);             // 背景カーテン

                this.Wave.SetWavPart(DoubleTools.ToInt((frame * 1.0 / AudioPicMP4Props.FPS + AudioPicMP4Props.AUDIO_DELAY_SEC) * this.Wave.WavHz));
                SpectrumGraph0001 sg = new SpectrumGraph0001(hz => this.Wave.GetSpectrum(hz));
                ss.Projection(sg.Spectra);
                this.DrawSpectra(frameImg, sg, ss);

                PictureUtils.Filter(frameImg, Color.Black, f2.Rate);                 // 前景カーテン

                frameImg.Save(this.FFmpeg.GetImageFile(frame), ImageFormat.Jpeg, AudioPicMP4Props.JPEG_QUALITY);

                GC.Collect();
            }

            this.FFmpeg.MakeMovie();

            File.Copy(this.FFmpeg.GetMovieFile(), this.DestMP4File);
        }