private void buttonOpenVideo_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                VideoFileName = openFileDialog1.FileName;
                labelVideoFileName.Text = VideoFileName;

                DateTime start;
                double durationInSeconds;
                string ext = Path.GetExtension(VideoFileName).ToLower();
                if (ext == ".mp4" || ext == ".m4v" || ext == ".3gp")
                {
                    MP4Parser mp4Parser = new MP4Parser(VideoFileName);
                    start = mp4Parser.CreationDate;
                    durationInSeconds = mp4Parser.Duration.TotalSeconds;
                }
                else
                {
                    var fi = new FileInfo(VideoFileName);
                    start = fi.CreationTime;
                    VideoInfo vi = Utilities.GetVideoInfo(VideoFileName);
                    durationInSeconds = vi.TotalMilliseconds / TimeCode.BaseUnit;
                    if (durationInSeconds < 1)
                    {
                        MessageBox.Show("Unable to get duration");
                        durationInSeconds = 60 * 60;
                    }
                }
                dateTimePicker1.Value = start;
                timeUpDownStartTime.TimeCode = new TimeCode(start.Hour, start.Minute, start.Second, start.Millisecond);
                timeUpDownDuration.TimeCode = TimeCode.FromSeconds(durationInSeconds);
            }
        }
Exemplo n.º 2
0
        public void Mp4Test1()
        {
            string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MP4_SRT.mp4");
            var parser = new MP4Parser(fileName);

            var tracks = parser.GetSubtitleTracks();

            Assert.IsTrue(tracks.Count == 1);
            Assert.IsTrue(tracks[0].Mdia.Minf.Stbl.EndTimeCodes.Count == 2);
        }
Exemplo n.º 3
0
        private bool ImportSubtitleFromMp4(string fileName)
        {
            var mp4Parser = new MP4Parser(fileName);
            var mp4SubtitleTracks = mp4Parser.GetSubtitleTracks();
            if (mp4SubtitleTracks.Count == 0)
            {
                MessageBox.Show(this._language.NoSubtitlesFound);
                return false;
            }
            else if (mp4SubtitleTracks.Count == 1)
            {
                this.LoadMp4Subtitle(fileName, mp4SubtitleTracks[0]);
                return true;
            }
            else
            {
                using (var subtitleChooser = new MatroskaSubtitleChooser())
                {
                    subtitleChooser.Initialize(mp4SubtitleTracks);
                    if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
                    {
                        this.LoadMp4Subtitle(fileName, mp4SubtitleTracks[subtitleChooser.SelectedIndex]);
                        return true;
                    }
                }

                return false;
            }
        }
Exemplo n.º 4
0
        private void pointSyncViaOtherSubtitleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var pointSync = new SyncPointsSync())
            {
                this.openFileDialog1.Title = this._language.OpenOtherSubtitle;
                this.openFileDialog1.FileName = string.Empty;
                this.openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
                if (this.openFileDialog1.ShowDialog() == DialogResult.OK && File.Exists(this.openFileDialog1.FileName))
                {
                    var sub = new Subtitle();
                    var file = new FileInfo(this.openFileDialog1.FileName);
                    var fileName = file.FullName;
                    var extension = file.Extension.ToLowerInvariant();

                    // TODO: Check for mkv etc
                    if (extension == ".sub")
                    {
                        if (this.IsVobSubFile(fileName, false))
                        {
                            MessageBox.Show(this._language.NoSupportHereVobSub);
                            return;
                        }
                    }

                    if (extension == ".sup")
                    {
                        if (FileUtil.IsBluRaySup(fileName))
                        {
                            MessageBox.Show(this._language.NoSupportHereBluRaySup);
                            return;
                        }
                        else if (FileUtil.IsSpDvdSup(fileName))
                        {
                            MessageBox.Show(this._language.NoSupportHereDvdSup);
                            return;
                        }
                    }

                    if (extension == ".mkv" || extension == ".mks")
                    {
                        using (var matroska = new MatroskaFile(fileName))
                        {
                            if (matroska.IsValid)
                            {
                                var subtitleList = matroska.GetTracks(true);
                                if (subtitleList.Count > 1)
                                {
                                    using (var subtitleChooser = new MatroskaSubtitleChooser())
                                    {
                                        subtitleChooser.Initialize(subtitleList);
                                        if (this._loading)
                                        {
                                            subtitleChooser.Icon = (Icon)this.Icon.Clone();
                                            subtitleChooser.ShowInTaskbar = true;
                                            subtitleChooser.ShowIcon = true;
                                        }

                                        if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
                                        {
                                            sub = this.LoadMatroskaSubtitleForSync(subtitleList[subtitleChooser.SelectedIndex], matroska);
                                        }
                                    }
                                }
                                else if (subtitleList.Count > 0)
                                {
                                    sub = this.LoadMatroskaSubtitleForSync(subtitleList[0], matroska);
                                }
                                else
                                {
                                    MessageBox.Show(this._language.NoSubtitlesFound);
                                    return;
                                }
                            }
                        }
                    }

                    if (extension == ".divx" || extension == ".avi")
                    {
                        MessageBox.Show(this._language.NoSupportHereDivx);
                        return;
                    }

                    if ((extension == ".mp4" || extension == ".m4v" || extension == ".3gp") && file.Length > 10000)
                    {
                        var mp4Parser = new MP4Parser(fileName);
                        var mp4SubtitleTracks = mp4Parser.GetSubtitleTracks();
                        if (mp4SubtitleTracks.Count == 0)
                        {
                            MessageBox.Show(this._language.NoSubtitlesFound);
                            return;
                        }
                        else if (mp4SubtitleTracks.Count == 1)
                        {
                            sub = LoadMp4SubtitleForSync(mp4SubtitleTracks[0]);
                        }
                        else
                        {
                            using (var subtitleChooser = new MatroskaSubtitleChooser())
                            {
                                subtitleChooser.Initialize(mp4SubtitleTracks);
                                if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
                                {
                                    sub = LoadMp4SubtitleForSync(mp4SubtitleTracks[0]);
                                }
                            }
                        }
                    }

                    if (file.Length > 1024 * 1024 * 10 && sub.Paragraphs.Count == 0)
                    {
                        // max 10 mb
                        var text = string.Format(this._language.FileXIsLargerThan10MB + Environment.NewLine + Environment.NewLine + this._language.ContinueAnyway, fileName);
                        if (MessageBox.Show(this, text, this.Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                        {
                            return;
                        }
                    }

                    sub.Renumber();
                    if (sub.Paragraphs.Count == 0)
                    {
                        Encoding enc;
                        SubtitleFormat f = sub.LoadSubtitle(fileName, out enc, null);
                        if (f == null)
                        {
                            this.ShowUnknownSubtitle();
                            return;
                        }
                    }

                    pointSync.Initialize(this._subtitle, this._fileName, this.VideoFileName, this._videoAudioTrackNumber, fileName, sub);
                    this.mediaPlayer.Pause();
                    if (pointSync.ShowDialog(this) == DialogResult.OK)
                    {
                        this._subtitleListViewIndex = -1;
                        this.MakeHistoryForUndo(this._language.BeforePointSynchronization);
                        this._subtitle.Paragraphs.Clear();
                        foreach (var p in pointSync.FixedSubtitle.Paragraphs)
                        {
                            this._subtitle.Paragraphs.Add(p);
                        }

                        this._subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(this.CurrentFrameRate);
                        this.ShowStatus(this._language.PointSynchronizationDone);
                        this.ShowSource();
                        this.SubtitleListview1.Fill(this._subtitle, this._subtitleAlternate);
                    }

                    this.VideoFileName = pointSync.VideoFileName;
                }
            }
        }
        /// <summary>
        /// The add ware form_ shown.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void AddWareForm_Shown(object sender, EventArgs e)
        {
            this.Refresh();
            var audioTrackNames = new List<string>();
            var mkvAudioTrackNumbers = new Dictionary<int, int>();
            int numberOfAudioTracks = 0;
            if (this.labelVideoFileName.Text.Length > 1 && File.Exists(this.labelVideoFileName.Text))
            {
                if (this.labelVideoFileName.Text.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase))
                { // Choose for number of audio tracks in matroska files
                    MatroskaFile matroska = null;
                    try
                    {
                        matroska = new MatroskaFile(this.labelVideoFileName.Text);
                        if (matroska.IsValid)
                        {
                            foreach (var track in matroska.GetTracks())
                            {
                                if (track.IsAudio)
                                {
                                    numberOfAudioTracks++;
                                    if (track.CodecId != null && track.Language != null)
                                    {
                                        audioTrackNames.Add("#" + track.TrackNumber + ": " + track.CodecId.Replace("\0", string.Empty) + " - " + track.Language.Replace("\0", string.Empty));
                                    }
                                    else
                                    {
                                        audioTrackNames.Add("#" + track.TrackNumber);
                                    }

                                    mkvAudioTrackNumbers.Add(mkvAudioTrackNumbers.Count, track.TrackNumber);
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (matroska != null)
                        {
                            matroska.Dispose();
                        }
                    }
                }
                else if (this.labelVideoFileName.Text.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase) || this.labelVideoFileName.Text.EndsWith(".m4v", StringComparison.OrdinalIgnoreCase))
                { // Choose for number of audio tracks in mp4 files
                    try
                    {
                        var mp4 = new MP4Parser(this.labelVideoFileName.Text);
                        var tracks = mp4.GetAudioTracks();
                        int i = 0;
                        foreach (var track in tracks)
                        {
                            i++;
                            if (track.Name != null && track.Mdia != null && track.Mdia.Mdhd != null && track.Mdia.Mdhd.LanguageString != null)
                            {
                                audioTrackNames.Add(i + ":  " + track.Name + " - " + track.Mdia.Mdhd.LanguageString);
                            }
                            else if (track.Name != null)
                            {
                                audioTrackNames.Add(i + ":  " + track.Name);
                            }
                            else
                            {
                                audioTrackNames.Add(i.ToString(CultureInfo.InvariantCulture));
                            }
                        }

                        numberOfAudioTracks = tracks.Count;
                    }
                    catch
                    {
                    }
                }

                if (Configuration.Settings.General.UseFFmpegForWaveExtraction)
                { // don't know how to extract audio number x via FFmpeg...
                    numberOfAudioTracks = 1;
                    this._audioTrackNumber = 0;
                }

                // Choose audio track
                if (numberOfAudioTracks > 1)
                {
                    using (var form = new ChooseAudioTrack(audioTrackNames, this._audioTrackNumber))
                    {
                        if (form.ShowDialog(this) == DialogResult.OK)
                        {
                            this._audioTrackNumber = form.SelectedTrack;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.Cancel;
                            return;
                        }
                    }
                }

                // check for delay in matroska files
                if (this.labelVideoFileName.Text.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase))
                {
                    MatroskaFile matroska = null;
                    try
                    {
                        matroska = new MatroskaFile(this.labelVideoFileName.Text);
                        if (matroska.IsValid)
                        {
                            this._delayInMilliseconds = (int)matroska.GetTrackStartTime(mkvAudioTrackNumbers[this._audioTrackNumber]);
                        }
                    }
                    catch
                    {
                        this._delayInMilliseconds = 0;
                    }
                    finally
                    {
                        if (matroska != null)
                        {
                            matroska.Dispose();
                        }
                    }
                }

                this.buttonRipWave_Click(null, null);
            }
            else if (this._wavFileName != null)
            {
                this.FixWaveOnly();
            }
        }
Exemplo n.º 6
0
        private static VideoInfo TryReadVideoInfoViaMp4(string fileName)
        {
            var info = new VideoInfo { Success = false };

            try
            {
                var mp4Parser = new MP4Parser(fileName);
                if (mp4Parser.Moov != null && mp4Parser.VideoResolution.X > 0)
                {
                    info.Width = mp4Parser.VideoResolution.X;
                    info.Height = mp4Parser.VideoResolution.Y;
                    info.TotalMilliseconds = mp4Parser.Duration.TotalSeconds;
                    info.VideoCodec = "MP4";
                    info.FramesPerSecond = mp4Parser.FrameRate;
                    info.Success = true;
                }
            }
            catch
            {
            }
            return info;
        }