Ejemplo n.º 1
0
        private void plSheet_DragDrop(object sender, DragEventArgs e)
        {
            try
            {
                int droppedRowIndex;

                {
                    Point pt = this.plSheet.PointToClient(new Point(e.X, e.Y));
                    DataGridView.HitTestInfo hit = this.plSheet.HitTest(pt.X, pt.Y);
                    droppedRowIndex = hit.RowIndex;
                }

                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false);

                if (Gnd.i.plCountMax < files.Length)
                {
                    throw new Exception("入力ファイル大杉.1");
                }

                files = Utils.droppedFilesFilter(files);

                if (Gnd.i.plCountMax < files.Length)
                {
                    throw new Exception("入力ファイル大杉.2");
                }

                if (files.Length == 0)
                {
                    throw new Exception("入力ファイル無し");
                }

                List <MediaInfo> mis = new List <MediaInfo>();

                foreach (string file in files)
                {
                    mis.Add(MediaInfo.create(file));
                }

                Gnd.i.oc.add(delegate
                {
                    if (droppedRowIndex < 0 || plSheet.RowCount < droppedRowIndex)
                    {
                        droppedRowIndex = plSheet.RowCount;
                    }

                    plSheet.RowCount += mis.Count;

                    for (int rowidx = plSheet.RowCount - 1; ; rowidx--)
                    {
                        int rRowidx = rowidx - mis.Count;

                        if (rRowidx < droppedRowIndex)
                        {
                            break;
                        }

                        plSheetSetRow(rowidx, plSheetGetRow(rRowidx));
                    }
                    for (int index = 0; index < mis.Count; index++)
                    {
                        plSheetSetRow(droppedRowIndex + index, mis[index]);
                    }
                    Utils.adjustColumnsWidth(plSheet);
                });
            }
            catch (Exception ex)
            {
                Gnd.i.logger.writeLine("plSheet-dd-error: " + ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// プレイリスト中の未変換 ogg, ogv を一気に変換する。
        /// mainTimerTick の中から呼ばれること!
        /// </summary>
        private void convBypass(int needConvOcxIndex)
        {
            List <ConvBypassEntry> entries = new List <ConvBypassEntry>();

            if (Gnd.i.convBypassまとめて実行)
            {
                for (int rowidx = 0; rowidx < plSheet.RowCount; rowidx++)
                {
                    MediaInfo mi = plSheetGetRow(rowidx);

                    if (mi.status == Consts.MediaStatus_e.NEED_CONVERSION && Utils.isOgxPath(mi.file))
                    {
                        entries.Add(new ConvBypassEntry()
                        {
                            rowidx = rowidx,
                            mi     = mi,
                        });
                    }
                }
            }
            else
            {
                entries.Add(new ConvBypassEntry()
                {
                    rowidx = needConvOcxIndex,
                    mi     = plSheetGetRow(needConvOcxIndex),
                });
            }

            {
                OperationCenter convOcBk = Gnd.i.convOc;
                Gnd.i.convOc = new OperationCenter();

                BusyDlg.perform(delegate
                {
                    foreach (ConvBypassEntry cbe in entries)
                    {
                        using (Conv conv = new Conv(cbe.mi.file, Path.Combine(Gnd.i.mediaDir, StringTools.zPad(cbe.mi.serial, 10))))
                        {
                            while (conv.completed == false)
                            {
                                Gnd.i.convOc.eachTimerTick();
                            }
                            cbe.mi.status = Consts.MediaStatus_e.READY;
                            completedConvToMediaInfo(conv, cbe.mi);
                            cbe.proced = true;
                        }
                    }
                },
                                this,
                                entries.Count == 1
                                );

                Gnd.i.convOc = convOcBk;
            }

            foreach (ConvBypassEntry cbe in entries)
            {
                if (cbe.proced)
                {
                    plSheetSetRow(cbe.rowidx, cbe.mi);

                    if (cbe.rowidx == 0 && Gnd.i.autoPlayTop)                     // 自動再生
                    {
                        int playingIndex = getPlayingIndex();

                        if (playingIndex == -1)                         // ? 未再生
                        {
                            Gnd.i.lastPlayedSerial = cbe.mi.serial;
                            Gnd.i.client.sendLine("ES!");
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public MediaInfo plSheetGetRow(int rowidx)
 {
     return(MediaInfo.decode(plSheet.Rows[rowidx].Cells[plSheet.ColumnCount - 1].Value.ToString()));
 }
Ejemplo n.º 4
0
        private ConvFileRet_e ConvFile(string file)
        {
            if (this.Cancelled)             // ★★★ 中止チェック
            {
                throw new Exception("要求により、中止しました。(ConvFile)");
            }

            Gnd.BusyDlg.SetMessage(GetLocalFileUI(file) + " を処理しています。パス名=" + file);

            string ext = Path.GetExtension(file);

            Gnd.ConvLog.Writeln("ext: " + ext);

            if (AudioMovieExts.Contains(ext) == false)
            {
                Gnd.ConvLog.Writeln("登録されている動画・音楽ファイルの拡張子ではありません。");
                return(ConvFileRet_e.OTHER_FILE);
            }

            DirectoryTools.DeletePath(WorkDatDir);
            Directory.CreateDirectory(WorkDatDir);

            try
            {
                string destFile = StringTools.Combine(WorkDatDir, "0001" + ext);

                Gnd.ConvLog.Writeln("< " + file);
                Gnd.ConvLog.Writeln("> " + destFile);

                File.Copy(file, destFile);

                if (File.Exists(destFile) == false)
                {
                    throw new Exception("ファイルのコピーに失敗しました。(対象ファイルにアクセス出来ない?)");
                }
            }
            catch (Exception e)
            {
                Gnd.ConvLog.Writeln(e);
                return(ConvFileRet_e.ERROR);
            }

            Run_ffprobe("0001" + ext + " 2> 0002.txt");

            MediaInfo mi = new MediaInfo(StringTools.Combine(WorkDatDir, "0002.txt"));

            foreach (MediaInfo.AudioStream stream in mi.AudioStreams)
            {
                Gnd.ConvLog.Writeln("音声ストリーム.mapIndex=" + stream.MapIndex);
            }

            foreach (MediaInfo.VideoStream stream in mi.VideoStreams)
            {
                Gnd.ConvLog.Writeln("映像ストリーム.mapIndex=" + stream.MapIndex);
            }

            if (mi.AudioStreams.Count == 0 && mi.VideoStreams.Count == 0)
            {
                Gnd.ConvLog.Writeln("映像・音声ストリームが無いため、多分これは動画・音楽ファイルではありません。");
                return(ConvFileRet_e.OTHER_FILE);
            }
            if (mi.AudioStreams.Count == 0)
            {
                Gnd.ConvLog.Writeln("音声ストリームが無いため、動画・音楽ファイルと見なしません。");
                return(ConvFileRet_e.OTHER_FILE);
            }

            Gnd.ConvLog.Writeln("PROC-AUDIO");

            int audioProcessedCount = 0;

            for (int index = 0; index < mi.AudioStreams.Count; index++)
            {
                string lWavFile = index + ".wav";
                string wavFile  = StringTools.Combine(WorkDatDir, lWavFile);

                try
                {
                    Gnd.ConvLog.Writeln("音声ストリームを処理します。index=" + index + ", mapIndex=" + mi.AudioStreams[index].MapIndex);

                    // ステレオにする。
                    Run_ffmpeg("-i 0001" + ext + " -map 0:" + mi.AudioStreams[index].MapIndex + " -ac 2 " + lWavFile);

                    if (File.Exists(wavFile) == false)
                    {
                        throw new Exception("音声ストリームの抽出に失敗しました。");                         // -> ConvFileRet_e.ERROR
                    }
                    File.Delete(StringTools.Combine(WorkDatDir, "0003.wav"));
                    File.Delete(StringTools.Combine(WorkDatDir, "0004.report"));
                    File.Delete(StringTools.Combine(WorkDatDir, "0004.report-main"));

                    Gnd.ConvLog.Writeln("音量を均一化します。");

                    try
                    {
                        Run_WavMaster("/E " + Consts.EV_MASTER_CANCEL + " " + lWavFile + " 0003.wav 0004.report-main > 0004.report");

                        if (File.Exists(StringTools.Combine(WorkDatDir, "0004.report-main")) == false)                         // -> ConvFileRet_e.ERROR
                        {
                            File.Delete(wavFile);
                            throw new Exception("0004.report-main does not exist.");
                        }
                        if (File.Exists(StringTools.Combine(WorkDatDir, "0004.report")) == false)                         // -> ConvFileRet_e.ERROR
                        {
                            File.Delete(wavFile);
                            throw new Exception("0004.report does not exist.");
                        }
                    }
                    finally
                    {
                        try
                        {
                            Gnd.ConvLog.Writeln("WAV-MASTER REPORT BEGIN");

                            using (StreamReader rfs = new StreamReader(StringTools.Combine(WorkDatDir, "0004.report"), StringTools.ENCODING_SJIS))
                            {
                                for (; ;)
                                {
                                    string line = rfs.ReadLine();

                                    if (line == null)
                                    {
                                        break;
                                    }

                                    Gnd.ConvLog.Writeln(line);
                                }
                            }
                            Gnd.ConvLog.Writeln("WAV-MASTER REPORT END");
                        }
                        catch
                        {
                            Gnd.ConvLog.Writeln("WAV-MASTER REPORT ERROR");
                        }
                    }

                    if (File.Exists(StringTools.Combine(WorkDatDir, "0003.wav")) == false)
                    {
                        throw new Exception("音量の均一化はキャンセルされました。(多分、処理不要)");                         // -> 継続
                    }
                    Gnd.ConvLog.Writeln("音量を均一化しました。");

                    File.Delete(wavFile);
                    File.Move(
                        StringTools.Combine(WorkDatDir, "0003.wav"),
                        wavFile
                        );

                    Gnd.ConvLog.Writeln("音声ストリームの処理に成功しました。");

                    audioProcessedCount++;
                }
                catch (Exception e)
                {
                    Gnd.ConvLog.Writeln(e);
                }
                if (this.Cancelled)
                {
                    throw new Exception("要求により、中止しました。(PROC-AUDIO)");
                }

                if (File.Exists(wavFile) == false)
                {
                    Gnd.ConvLog.Writeln("Conv_Error: 音声ストリームの処理に問題が発生しました。");
                    return(ConvFileRet_e.ERROR);
                }
            }

            Gnd.ConvLog.Writeln("audioProcessedCount: " + audioProcessedCount);

            if (audioProcessedCount == 0)
            {
                Gnd.ConvLog.Writeln("音量均一化を実行した音声ストリームはありません。");
                return(ConvFileRet_e.NOT_PROCESSED);
            }

            Gnd.ConvLog.Writeln("PROC-AUDIO OK");
            Gnd.ConvLog.Writeln("MAKE-DEST");

            if (StringTools.IsSame(ext, ".wav", true) && mi.AudioStreams.Count == 1)
            {
                string rFile = Path.Combine(WorkDatDir, "0.wav");
                string wFile = Path.Combine(WorkDatDir, "0005.wav");

                Gnd.ConvLog.Writeln("SIMPLE_COPY");
                Gnd.ConvLog.Writeln("< " + rFile);
                Gnd.ConvLog.Writeln("> " + wFile);

                File.Copy(rFile, wFile);

                Gnd.ConvLog.Writeln("SIMPLE_COPY_DONE");
            }
            else
            {
                List <string> args           = new List <string>();
                bool          hasVideoStream = 1 <= mi.VideoStreams.Count;

                if (hasVideoStream)
                {
                    args.Add("-i");
                    args.Add("0001" + ext);
                }
                for (int index = 0; index < mi.AudioStreams.Count; index++)                 // 音楽
                {
                    args.Add("-i");
                    args.Add(index + ".wav");
                }
                int fileIndex = 0;

                if (hasVideoStream)
                {
                    for (int index = 0; index < mi.VideoStreams.Count; index++)                     // 動画
                    {
                        args.Add("-map");
                        args.Add(fileIndex + ":" + mi.VideoStreams[index].MapIndex);
                    }
                    fileIndex++;
                }
                for (int index = 0; index < mi.AudioStreams.Count; index++)                 // 音楽
                {
                    args.Add("-map");
                    args.Add(fileIndex + ":0");
                    fileIndex++;
                }
                if (hasVideoStream)
                {
                    args.Add("-vcodec");
                    args.Add("copy");
                }
                args.Add(ExtOptions.GetOption(ext));
                args.Add("0005" + ext);

                Run_ffmpeg(string.Join(" ", args));
            }

            if (File.Exists(StringTools.Combine(WorkDatDir, "0005" + ext)) == false)
            {
                Gnd.ConvLog.Writeln("Conv_Error: 動画・音楽ファイルの再生成に失敗しました。");
                return(ConvFileRet_e.ERROR);
            }

            Gnd.ConvLog.Writeln("MAKE-DEST OK");

            try
            {
                string rFile    = StringTools.Combine(WorkDatDir, "0005" + ext);
                string destFile = FileTools.GetCounteredPath(file, RDir, WDir);

                Gnd.ConvLog.Writeln("COPY-DEST");
                Gnd.ConvLog.Writeln("< " + rFile);
                Gnd.ConvLog.Writeln("> " + destFile);

                // 出力ファイルのクリア
                {
                    DirectoryTools.DeletePath(destFile);
                    Directory.CreateDirectory(destFile);
                    Directory.Delete(destFile);
                }

                if (File.Exists(destFile))
                {
                    throw new Exception("ファイルのコピーに失敗しました。(出力ファイルをクリア出来ません)");
                }

#if true
                File.Copy(rFile, destFile);
                File.Delete(rFile);
#else // 権限とか圧縮状態とか引き継いでしまうので、没..
                File.Move(rFile, destFile);
#endif

                if (File.Exists(destFile) == false)
                {
                    throw new Exception("ファイルのコピーに失敗しました。(出力ファイルを生成出来ません)");
                }

                if (File.Exists(rFile))
                {
                    throw new Exception("ファイルのコピーに失敗しました。(rFile exists)");
                }
            }
            catch (Exception e)
            {
                Gnd.ConvLog.Writeln(e);
                return(ConvFileRet_e.ERROR);
            }

            Gnd.ConvLog.Writeln("COPY-DEST OK");

            return(ConvFileRet_e.SUCCESSFUL);
        }
Ejemplo n.º 5
0
        private bool plSheet_eachTimerTick()         // ret: ? 繰り返し呼び出すべき
        {
            if (plSheet.RowCount == 0)
            {
                pse_index = -1;                 // コンバートを先頭から行わせるため..
                return(false);
            }
            pse_index++;
            pse_index %= plSheet.RowCount;

            MediaInfo mi       = plSheetGetRow(pse_index);
            bool      modified = false;

            switch (mi.status)
            {
            case Consts.MediaStatus_e.UNKNOWN:
                mi.status = Consts.MediaStatus_e.NEED_CONVERSION;
                modified  = true;
                break;

            case Consts.MediaStatus_e.NEED_CONVERSION:
                if (Utils.isOgxPath(mi.file))
                {
                    if (pse_convBypassFreezeMtCount < mtCount)
                    {
                        //pse_convBypassFreezeMtCount = mtCount + 50; // + convBypass_抑止期間(mtCount)

                        convBypass(pse_index);
                        return(false);                                // plSheet は mi も含めて既に変更されているはずなので、
                    }
                }
                else if (Gnd.i.conv == null)
                {
                    Gnd.i.conv = new Conv(mi.file, Path.Combine(Gnd.i.mediaDir, StringTools.zPad(mi.serial, 10)));
                    mi.status  = Consts.MediaStatus_e.CONVERTING;
                    modified   = true;
                }
                break;

            case Consts.MediaStatus_e.CONVERTING:
                // conv == null ってことは無いはずだけど一応..
                if (Gnd.i.conv != null && Gnd.i.conv.completed)
                {
                    mi.status = Consts.MediaStatus_e.READY;
                    completedConvToMediaInfo(Gnd.i.conv, mi);

                    Gnd.i.conv.Dispose();
                    Gnd.i.conv = null;
                    modified   = true;

                    if (pse_index == 0 && Gnd.i.autoPlayTop)                             // 自動再生
                    {
                        int playingIndex = getPlayingIndex();

                        if (playingIndex == -1)                                 // ? 未再生
                        {
                            Gnd.i.lastPlayedSerial = mi.serial;
                            Gnd.i.client.sendLine("ES!");
                        }
                    }
                }
                break;

            case Consts.MediaStatus_e.READY:
                // noop
                break;

            case Consts.MediaStatus_e.PLAYING:
                // noop
                break;

            case Consts.MediaStatus_e.ERROR:
                // noop
                break;

            default:
                throw null;
            }
            if (modified)
            {
                plSheetSetRow(pse_index, mi);

                //Utils.adjustColumnsWidth(plSheet); // ここでやると、超ちらつく
                plAdjColsCountDown = 10;

                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
        private MediaInfo mainSheetGetRow(int rowidx)
        {
            DataGridViewRow row = this.mainSheet.Rows[rowidx];

            return(MediaInfo.decode(row.Cells[4].Value.ToString()));
        }
Ejemplo n.º 7
0
        private void playListMonitorEachTimer()
        {
            if (this.mainSheet.RowCount == 0)
            {
                return;
            }

            plmIndex++;
            plmIndex %= this.mainSheet.RowCount;

            MediaInfo mi = mainSheetGetRow(plmIndex);

            switch (mi.status)
            {
            case Consts.MediaStatus_e.UNKNOWN:
            {
                string ext = Path.GetExtension(mi.file);

                if (StringTools.equalsIgnoreCase(ext, ".ogg"))                                 // ? そのまま行ける音楽ファイル
                {
                    mi.ogxFile = Utils.getOgxFile(mi.index, Consts.MediaType_e.AUDIO);

                    try
                    {
                        File.Copy(mi.file, mi.ogxFile);

                        if (File.Exists(mi.ogxFile) == false)
                        {
                            throw new Exception("ファイルにアクセス出来ません。(音楽ファイル_Direct)");
                        }
                    }
                    catch (Exception e)
                    {
                        Gnd.i.logger.writeLine("そのまま行ける音楽ファイルのコピーに失敗しました。" + e);

                        mi.status       = Consts.MediaStatus_e.ERROR;
                        mi.errorMessage = Utils.getMessage(e);
                    }
                }
                else if (StringTools.equalsIgnoreCase(ext, ".ogv"))                                 // ? そのまま行ける動画ファイル
                {
                    mi.ogxFile = Utils.getOgxFile(mi.index, Consts.MediaType_e.MOVIE);

                    try
                    {
                        File.Copy(mi.file, mi.ogxFile);

                        if (File.Exists(mi.ogxFile) == false)
                        {
                            throw new Exception("ファイルにアクセス出来ません。(動画ファイル_Direct)");
                        }
                    }
                    catch (Exception e)
                    {
                        Gnd.i.logger.writeLine("そのまま行ける動画ファイルのコピーに失敗しました。" + e);

                        mi.status       = Consts.MediaStatus_e.ERROR;
                        mi.errorMessage = Utils.getMessage(e);
                    }
                }
                else if (Conv.curr == null)
                {
                    Conv.curr = new Conv(mi.file, mi.index);

                    mi.status = Consts.MediaStatus_e.CONVERTING;
                }
                else
                {
                    mi.status = Consts.MediaStatus_e.NEED_CONVERSION;
                }
            }
            break;

            case Consts.MediaStatus_e.NEED_CONVERSION:
            {
                if (Conv.curr == null)
                {
                    Conv.curr = new Conv(mi.file, mi.index);

                    mi.status = Consts.MediaStatus_e.CONVERTING;
                }
            }
            break;

            case Consts.MediaStatus_e.CONVERTING:
            {
                if (Conv.curr != null && Conv.curr.isEnded())
                {
                    if (Conv.curr.hasError())
                    {
                        mi.status       = Consts.MediaStatus_e.ERROR;
                        mi.errorMessage = Conv.curr.getErrorMessage();
                    }
                    else
                    {
                        mi.status  = Consts.MediaStatus_e.READY;
                        mi.ogxFile = Conv.curr.getOgxFile();
                        mi.type    = Conv.curr.getMediaType();
                    }
                    Conv.curr = null;
                }
            }
            break;

            case Consts.MediaStatus_e.READY:
            {
                // noop
            }
            break;

            case Consts.MediaStatus_e.PLAYING:
            {
                // noop
            }
            break;

            case Consts.MediaStatus_e.ERROR:
            {
                // noop
            }
            break;

            default:
                throw null;
            }
            mainSheetSetRow(plmIndex, mi);
        }
Ejemplo n.º 8
0
        public void Main()
        {
            FileTools.Delete(Ground.I.WorkDir);
            FileTools.CreateDir(Ground.I.WorkDir);
            FileTools.CreateDir(Path.Combine(Ground.I.WorkDir, "bin"));

            string audioExt = Path.GetExtension(Ground.I.AudioFile);
            string imageExt = Path.GetExtension(Ground.I.ImageFile);

            if (IsFairExt(audioExt) == false)
            {
                throw new Exception("音楽ファイルの拡張子に問題があります。");
            }

            if (IsFairExt(imageExt) == false)
            {
                throw new Exception("画像ファイルの拡張子に問題があります。");
            }

            audioExt = audioExt.ToLower();
            imageExt = imageExt.ToLower();

            foreach (string file in Directory.GetFiles(ffmpegUtils.GetBinDir(Ground.I.ffmpegDir)))
            {
                File.Copy(file, Path.Combine(Ground.I.WorkDir, "bin", Path.GetFileName(file)));
            }

            File.Copy(Ground.I.ImgToolsFile, Path.Combine(Ground.I.WorkDir, "ImgTools.exe"));
            File.Copy(Ground.I.BmpToCsvFile, Path.Combine(Ground.I.WorkDir, "BmpToCsv.exe"));
            File.Copy(Ground.I.MasterFile, Path.Combine(Ground.I.WorkDir, "Master.exe"));
            File.Copy(Ground.I.AudioFile, Path.Combine(Ground.I.WorkDir, "audio" + audioExt));
            File.Copy(Ground.I.ImageFile, Path.Combine(Ground.I.WorkDir, "image" + imageExt));

            string homeDir = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(Ground.I.WorkDir);
            try
            {
                Run("bin\\ffprobe.exe audio" + audioExt);

                MediaInfo mi = new MediaInfo();
                mi.SetOutputFile("stderr.tmp");

                ProcMain.WriteLog("TotalTimeCentisecond: " + mi.TotalTimeCentisecond);
                ProcMain.WriteLog("AudioStreamCount: " + mi.AudioStreamCount);
                ProcMain.WriteLog("VideoStreamCount: " + mi.VideoStreamCount);
                ProcMain.WriteLog("AudioStreamIndex: " + mi.AudioStreamIndex);

                if (mi.TotalTimeCentisecond == -1L)
                {
                    throw new Exception("再生時間を取得できませんでした。");
                }

                // 9 * 3600 * 100 * (30 as FPS_MAX) == 97200000 == 8 桁

                if (9 * 3600 * 100 < mi.TotalTimeCentisecond)                 // ? 9 hour <
                {
                    throw new Exception("再生時間が長すぎます。");
                }

                if (mi.AudioStreamCount == 0)
                {
                    throw new Exception("音楽ストリームがありません。");
                }

                if (mi.VideoStreamCount != 0)
                {
                    //throw new Exception("動画ファイルです。"); // mjepgかもしれない!
                    ProcMain.WriteLog("動画ファイルかもしれませんが続行します。");
                }
                if (mi.AudioStreamCount == -1)
                {
                    throw new Exception("音楽ストリームを取得できませんでした。");
                }

                ConvImageJpeg("image" + imageExt, "image2.jpg", "image_mid_");

                int pictureCount = (int)((mi.TotalTimeCentisecond / 100.0) * Ground.I.FramePerSecond + 1);

                for (int count = 1; count <= pictureCount; count++)
                {
                    File.Copy("image2.jpg", string.Format("picture_{0:D8}.jpg", count));
                }

                Run("bin\\ffmpeg.exe -r " + Ground.I.FramePerSecond + " -i picture_%%08d.jpg video.mp4");

                if (File.Exists("video.mp4") == false)
                {
                    throw new Exception("映像ファイルの生成に失敗しました。");
                }

                if (Ground.I.MasteringFlag)
                {
                    ProcMain.WriteLog("音量調整を開始します。");

                    if (this.Mastering(audioExt))
                    {
                        ProcMain.WriteLog("音量調整:成功");

                        // 音楽ファイル_切り替え
                        {
                            audioExt            = "_m.wav";
                            mi.AudioStreamCount = 1;
                            mi.AudioStreamIndex = 0;
                        }
                    }
                    else
                    {
                        ProcMain.WriteLog("音量調整:不要(または失敗)");
                    }

                    ProcMain.WriteLog("音量調整を終了します。");
                }
                else
                {
                    ProcMain.WriteLog("音量調整をスキップします。");
                }

                Run("bin\\ffmpeg.exe -i video.mp4 -i audio" + audioExt + " -map 0:0 -map 1:" + mi.AudioStreamIndex + " -vcodec copy -codec:a copy movie.mp4");

                // コーデックが処理出来なかった場合、出力ファイルが空になる模様
                // .wav など

                if (CommonUtils.NoFileOrEmptyFile("movie.mp4"))
                {
                    ProcMain.WriteLog("動画ファイルの生成に失敗しました。⇒ オプションを変えて再試行します。");
                    File.Delete("movie.mp4");

                    // -codec:a copy を除去
                    // -ab 160k を追加
                    Run("bin\\ffmpeg.exe -i video.mp4 -i audio" + audioExt + " -map 0:0 -map 1:" + mi.AudioStreamIndex + " -vcodec copy -ab 160k movie.mp4");

                    if (CommonUtils.NoFileOrEmptyFile("movie.mp4"))
                    {
                        throw new Exception("動画ファイルの生成に失敗しました。");
                    }
                }

                {
                    long audioFileSize  = new FileInfo("audio" + audioExt).Length;
                    long imageFileSize  = new FileInfo("image" + imageExt).Length;
                    long image2FileSize = new FileInfo("image2.jpg").Length;
                    long movieFileSize  = new FileInfo("movie.mp4").Length;

                    ProcMain.WriteLog("audio file size   : " + audioFileSize);
                    ProcMain.WriteLog("image file A size : " + imageFileSize);
                    ProcMain.WriteLog("image file B size : " + image2FileSize);
                    ProcMain.WriteLog("movie file size   : " + movieFileSize);

                    ProcMain.WriteLog("file size rate    : " + (movieFileSize * 1.0 / audioFileSize));
                    ProcMain.WriteLog("file size rate +A : " + (movieFileSize * 1.0 / (audioFileSize + imageFileSize)));
                    ProcMain.WriteLog("file size rate +B : " + (movieFileSize * 1.0 / (audioFileSize + image2FileSize)));
                }

                if (Ground.I.ApproveGuest)
                {
                    Run("ECHO Y|CACLS movie.mp4 /P Users:F Guest:F");
                }

                File.Move("movie.mp4", Ground.I.MovieFile);
            }
            finally
            {
                Directory.SetCurrentDirectory(homeDir);
            }
        }
Ejemplo n.º 9
0
        private void recvedEvent(string line)
        {
            if (line == "X")
            {
                xRecved = true;
                return;
            }

            // ---- 最大化 ----

            if (line == "M")
            {
                int  playingIndex = getPlayingIndex();
                bool moviePlaying = false;

                if (playingIndex != -1)
                {
                    MediaInfo mi = PlayListWin.self.plSheetGetRow(playingIndex);

                    if (mi.type == Consts.MediaType_e.MOVIE)
                    {
                        moviePlaying    = true;
                        _maximizeSerial = mi.serial;
                    }
                }
                if (moviePlaying)
                {
                    _n2w.sendLine("C");
                    _n2w.sendLine("D");
                }
                _n2w.sendLine("R");
                _n2w.sendLine("EM-2");

                if (moviePlaying)
                {
                    _n2w.sendLine("EM-3");
                }
                else
                {
                    _n2w.sendLine("EM-3.2");
                }

                return;
            }
            if (line.StartsWith("Curr="))
            {
                _seekRate = (double)int.Parse(line.Substring(5)) / IntTools.IMAX;
                return;
            }
            if (line.StartsWith("Rect="))
            {
                List <string> tokens = StringTools.tokenize(line.Substring(5), ",");
                int           c      = 0;

                Gnd.i.screen_l = int.Parse(tokens[c++]);
                Gnd.i.screen_t = int.Parse(tokens[c++]);
                Gnd.i.screen_w = int.Parse(tokens[c++]);
                Gnd.i.screen_h = int.Parse(tokens[c++]);

                // adjust
                {
                    Gnd.i.screen_w = Math.Max(Gnd.i.screen_w, Consts.SCREEN_W_MIN);
                    Gnd.i.screen_h = Math.Max(Gnd.i.screen_h, Consts.SCREEN_H_MIN);
                }
                return;
            }
            if (line == "M-2")
            {
                for (int index = 0; index < Gnd.i.monitors.getCount(); index++)
                {
                    Monitors.Monitor m = Gnd.i.monitors.get(index);

                    if (
                        Gnd.i.screen_l == m.l &&
                        Gnd.i.screen_t == m.t &&
                        Gnd.i.screen_w == m.w &&
                        Gnd.i.screen_h == m.h
                        )
                    {
                        int l = Gnd.i.normScreen_l;
                        int t = Gnd.i.normScreen_t;
                        int w = Gnd.i.normScreen_w;
                        int h = Gnd.i.normScreen_h;

                        // old

                        /*
                         * w = Math.Min(w, Gnd.i.screen_w - 1);
                         * h = Math.Min(h, Gnd.i.screen_h - 1);
                         *
                         * int l = m.l + (m.w - w) / 2;
                         * int t = m.t + (m.h - h) / 2;
                         *
                         * t = Math.Max(m.t + 30, t); // ウィンドウがデカすぎても上部バーが見えるように。
                         */

                        _n2w.sendLine("L" + l);
                        _n2w.sendLine("Y" + t);
                        _n2w.sendLine("W" + w);
                        _n2w.sendLine("H" + h);
                        _n2w.sendLine("M");
                        _n2w.sendLine("r1");

                        // 2回目 -- r1によって位置が正しく設定されないことがあるため。
                        {
                            _n2w.sendLine("L" + l);
                            _n2w.sendLine("Y" + t);
                            _n2w.sendLine("W" + w);
                            _n2w.sendLine("H" + h);
                            _n2w.sendLine("M");
                        }
                        return;
                    }
                }
                Monitors.Monitor currMon = null;

                for (int index = 0; index < Gnd.i.monitors.getCount(); index++)
                {
                    Monitors.Monitor m = Gnd.i.monitors.get(index);

                    if (
                        Gnd.i.screen_l < m.r &&
                        Gnd.i.screen_t < m.b &&
                        m.l < Gnd.i.screen_r &&
                        m.t < Gnd.i.screen_b
                        )
                    {
                        currMon = m;
                        break;
                    }
                }
                if (currMon == null)
                {
                    currMon = Gnd.i.monitors.get(0);
                }

                if (Gnd.i.screen_w != -1)                 // 2bs? -- 未設定ってことは無いと思うけど..
                {
                    Gnd.i.normScreen_l = Gnd.i.screen_l;
                    Gnd.i.normScreen_t = Gnd.i.screen_t;
                    Gnd.i.normScreen_w = Gnd.i.screen_w;
                    Gnd.i.normScreen_h = Gnd.i.screen_h;
                }
                _n2w.sendLine("r0");
                _n2w.sendLine("L" + currMon.l);
                _n2w.sendLine("Y" + currMon.t);
                _n2w.sendLine("W" + currMon.w);
                _n2w.sendLine("H" + currMon.h);
                _n2w.sendLine("M");
                return;
            }
            if (line == "M-3")
            {
                int miIndex = getIndexBySerial(_maximizeSerial);
                _maximizeSerial = -1;

                if (miIndex == -1)
                {
                    return;                     // エラー
                }
                MediaInfo mi = PlayListWin.self.plSheetGetRow(miIndex);

                if (mi.type != Consts.MediaType_e.MOVIE)
                {
                    return;                     // エラー
                }
                int startTime = IntTools.toInt(_seekRate * mi.time);
                startTime = IntTools.toRange(startTime, 0, mi.time - 2000);                 // 2秒の余裕 <- 動画の長さより長いと不安定になる。

                _n2w.sendLine("I" + mi.serial);
                _n2w.sendLine("W" + mi.w);
                _n2w.sendLine("H" + mi.h);
                _n2w.sendLine("T" + startTime);
                _n2w.sendLine("t" + mi.time);
                _n2w.sendLine("P");
                return;
            }
            if (line == "M-3.2")
            {
                _n2w.sendLine("+");
                return;
            }

            // ---- 連続再生 ----

            if (line == "B" || line == "R")
            {
                int playingIndex = getPlayingIndex();

                if (playingIndex != -1)
                {
                    MediaInfo mi = PlayListWin.self.plSheetGetRow(playingIndex);

                    if (mi.type == Consts.MediaType_e.AUDIO ? line == "B" : line == "R")
                    {
                        if (Gnd.i.ignoreBRTimeSec < DateTimeToSec.Now.getSec())
                        {
                            Gnd.i.ignoreBRTimeSec = DateTimeToSec.Now.getSec() + 20L;                             // マージン適当, 20秒以上もBR受信し続けたら、もう事故だろう..
                            _n2w.sendLine("E-IgnBR");

                            doPlayNext(playingIndex);
                        }
                    }
                }
                return;
            }
            if (line == "-IgnBR")
            {
                Gnd.i.ignoreBRTimeSec = -1L;
                return;
            }

            // ---- 再生ボタン ----

            if (line == "S" || line == "S!" || line == "S/")
            {
                int playingIndex = getPlayingIndex();

                if (line == "S/")                 // 強制的に停止する。
                {
                    if (playingIndex == -1)
                    {
                        // 2bs -- 停止
                        {
                            _n2w.sendLine("F");
                            _n2w.sendLine("+");
                        }
                        return;
                    }
                }
                if (line == "S!")                 // 強制的に再生する。
                {
                    playingIndex = -1;
                }

                if (playingIndex != -1)                 // ? 再生中 -> 停止
                {
                    {
                        MediaInfo mi = PlayListWin.self.plSheetGetRow(playingIndex);
                        mi.status = Consts.MediaStatus_e.READY;
                        PlayListWin.self.plSheetSetRow(playingIndex, mi);
                    }

                    _n2w.sendLine("F");
                    _n2w.sendLine("+");
                }
                else                 // ? 停止中 -> 再生
                {
                    int index = getIndexBySerial(Gnd.i.lastPlayedSerial);

                    if (index == -1)
                    {
                        for (index = 0; index < PlayListWin.self.getPlSheet().RowCount; index++)
                        {
                            MediaInfo mi = PlayListWin.self.plSheetGetRow(index);

                            if (mi.status == Consts.MediaStatus_e.READY)
                            {
                                break;
                            }
                        }
                    }
                    doPlay(index);
                }
                return;
            }

            // ---- シークバー操作 ----

            if (line.StartsWith("Seek="))
            {
                int playingIndex = getPlayingIndex();

                if (playingIndex != -1)
                {
                    MediaInfo mi = PlayListWin.self.plSheetGetRow(playingIndex);

                    if (mi.type == Consts.MediaType_e.MOVIE)
                    {
                        double rate      = (double)int.Parse(line.Substring(5)) / IntTools.IMAX;
                        int    startTime = IntTools.toInt(rate * mi.time);

                        _n2w.sendLine("I" + mi.serial);
                        _n2w.sendLine("W" + mi.w);
                        _n2w.sendLine("H" + mi.h);
                        _n2w.sendLine("T" + startTime);
                        _n2w.sendLine("t" + mi.time);
                        _n2w.sendLine("P");
                    }
                }
                return;
            }

            // ---- 情報レスポンス ----

            if (line.StartsWith("Volume="))
            {
                Gnd.i.volume = int.Parse(line.Substring(7));
                return;
            }

            // スクリーンのサイズ Rect= は上の方で、、

            // ----

            if (line.StartsWith("!"))             // エラーの通知
            {
                Gnd.i.logger.writeLine("SCREEN_ERROR: " + line.Substring(1));
                return;
            }
            if (line == "Booting")
            {
                _n2w.sendLine("i" + (Gnd.i.instantMessagesDisabled ? 1 : 0));

                if (Gnd.i.monitors.contains(Gnd.i.screen_l, Gnd.i.screen_t, Gnd.i.screen_w, Gnd.i.screen_h))
                {
                    _n2w.sendLine("r0");
                }

                _n2w.sendLine("L" + Gnd.i.screen_l);
                _n2w.sendLine("Y" + Gnd.i.screen_t);
                _n2w.sendLine("W" + Gnd.i.screen_w);
                _n2w.sendLine("H" + Gnd.i.screen_h);
                _n2w.sendLine("M");

                _n2w.sendLine("v" + Gnd.i.volume);

                refreshDoubleMovie();

                _n2w.sendLine("+");                 // 壁紙表示
                return;
            }
            if (line == "Resized")
            {
                int  playingIndex = getPlayingIndex();
                bool moviePlaying = false;

                if (playingIndex != -1)
                {
                    MediaInfo mi = PlayListWin.self.plSheetGetRow(playingIndex);

                    if (mi.type == Consts.MediaType_e.MOVIE)
                    {
                        moviePlaying    = true;
                        _maximizeSerial = mi.serial;
                    }
                }
                if (moviePlaying)
                {
                    _n2w.sendLine("C");
                    _n2w.sendLine("D");
                }

                // resize screen
                {
                    _n2w.sendLine("L" + Gnd.i.screen_l);
                    _n2w.sendLine("Y" + Gnd.i.screen_t);
                    _n2w.sendLine("W" + Gnd.i.screen_w);
                    _n2w.sendLine("H" + Gnd.i.screen_h);
                    _n2w.sendLine("M");
                }

                if (moviePlaying)
                {
                    _n2w.sendLine("EM-3");
                }
                else
                {
                    _n2w.sendLine("EM-3.2");
                }

                return;
            }
            if (line == "XP")             // 終了
            {
                _n2w.sendLine("V");
                _n2w.sendLine("R");
                _n2w.sendLine("EX");
                return;
            }
        }
Ejemplo n.º 10
0
        public void doResizeScreen(int w, int h)
        {
            int monIndex = Gnd.i.monitors.whereIs(
                Gnd.i.screen_l,
                Gnd.i.screen_t,
                Gnd.i.screen_w,
                Gnd.i.screen_h
                );

            if (monIndex == -1)
            {
                monIndex = 0;
            }

            Monitors.Monitor m = Gnd.i.monitors.get(monIndex);

            // ウィンドウをリサイズ可能にしたら、モニタより大きく設定できなくなった。ので、その対応。適当だけど..
            {
                w = Math.Min(w, m.w - Consts.SCREEN_MARGIN);
                h = Math.Min(h, m.h - Consts.SCREEN_MARGIN);
            }

            Gnd.i.screen_l = m.l;
            Gnd.i.screen_t = m.t + 30;             // ウィンドウ上部のバーが見えるように..
            Gnd.i.screen_w = w;
            Gnd.i.screen_h = h;

            // ----

            int  playingIndex = getPlayingIndex();
            bool moviePlaying = false;

            if (playingIndex != -1)
            {
                MediaInfo mi = PlayListWin.self.plSheetGetRow(playingIndex);

                if (mi.type == Consts.MediaType_e.MOVIE)
                {
                    moviePlaying    = true;
                    _maximizeSerial = mi.serial;
                }
            }
            if (moviePlaying)
            {
                _n2w.sendLine("C");
                _n2w.sendLine("D");
            }

            // resize screen
            {
                _n2w.sendLine("L" + Gnd.i.screen_l);
                _n2w.sendLine("Y" + Gnd.i.screen_t);
                _n2w.sendLine("W" + Gnd.i.screen_w);
                _n2w.sendLine("H" + Gnd.i.screen_h);
                _n2w.sendLine("M");
                _n2w.sendLine("r1");                 // フルスクリーンの時にやられる可能性があるので、、

                // 2回目 -- r1によって位置が正しく設定されないことがあるため。
                {
                    _n2w.sendLine("L" + Gnd.i.screen_l);
                    _n2w.sendLine("Y" + Gnd.i.screen_t);
                    _n2w.sendLine("W" + Gnd.i.screen_w);
                    _n2w.sendLine("H" + Gnd.i.screen_h);
                    _n2w.sendLine("M");
                }
            }

            if (moviePlaying)
            {
                _n2w.sendLine("EM-3");
            }
            else
            {
                _n2w.sendLine("EM-3.2");
            }
        }