public void AudioSourceGetAudioStartOutOfRange() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); AudioSource source = index.AudioSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 1); source.GetAudio(-1, 10); }
public void AudioSourceAndAPIFunctions() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); AudioSource source = index.AudioSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 1); Assert.AreEqual(SampleFormat.float_t, source.SampleFormat); Assert.AreEqual(48000, source.SampleRate); Assert.AreEqual(32, source.BitsPerSample); Assert.AreEqual(2, source.Channels); Assert.AreEqual(3, source.ChannelLayout); Assert.AreEqual(3446272, source.NumberOfSamples); Assert.AreEqual(0, source.FirstTime); Assert.AreEqual(71.768, source.LastTime); /* * There's no reliable way to test GetAudio, unfortunately. * byte[] buffer = source.GetAudio(0, 100000); using (var md5 = MD5.Create()) { Assert.AreEqual("D0-55-BB-E0-35-DA-B4-1E-70-EA-D2-DE-DE-BF-13-DC", BitConverter.ToString(md5.ComputeHash(buffer))); } * */ }
public void VideoSourceAndAPIFunctions() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); VideoSource source = index.VideoSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 0); Assert.AreEqual(30000, source.FPSNumerator); Assert.AreEqual(15712911, source.RFFNumerator); Assert.AreEqual(2157, source.NumberOfFrames); Assert.AreEqual(409440, source.SampleAspectRatioNumerator); Assert.AreEqual(0, source.Crop.Left); Assert.IsFalse(source.TopFieldFirst); Assert.AreEqual(0, source.FirstTime); Assert.AreEqual(71.939, source.LastTime); }
public void AudioTrackAndAPIFunctions() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); AudioSource source = index.AudioSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 1); Track track = source.Track; Assert.AreEqual(TrackType.Audio, track.TrackType); Assert.AreEqual(1, track.TimeBaseNumerator); Assert.AreEqual(4490, track.NumberOfFrames); try { track.GetFrameInfo(20); // It won't pass this. Assert.Fail(); } catch { } }
public void AudioSourceInvalidOperationException() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); AudioSource source = index.AudioSource("h264_720p_hp_3.1_600kbps_aac_mp3_dual_audio_harry_potter.mkv", 1); }
public void VideoTrackAndAPIFunctions() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); VideoSource source = index.VideoSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 0); Track track = source.Track; Assert.AreEqual(TrackType.Video, track.TrackType); Assert.AreEqual(1, track.TimeBaseNumerator); Assert.AreEqual(2157, track.NumberOfFrames); FrameInfo frameinfo = track.GetFrameInfo(20); Assert.AreEqual(667000000, frameinfo.PTS); Assert.AreEqual(1, frameinfo.RepeatPicture); Assert.AreEqual(false, frameinfo.KeyFrame); track.WriteTimecodes("timecodes.txt"); using (var md5 = MD5.Create()) using (var stream = File.OpenRead("timecodes.txt")) { Assert.AreEqual("53-20-BD-47-0A-01-1A-E4-13-E9-1E-C1-C6-21-69-EC", BitConverter.ToString(md5.ComputeHash(stream))); } }
public void AudioSourceFileNotFoundException() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); AudioSource source = index.AudioSource("this file doesn't exist.avi", 1); }
public void VideoSourceSetOutputFormatInvalid() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); VideoSource source = index.VideoSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 0); var list = new List<int>(); list.Add(FFMS2.GetPixelFormat("none")); source.SetOutputFormat(list, 100, 100, Resizer.Bilinear); }
public void IndexGetFirstTrackOfTypeNotAvailable() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); index.GetFirstTrackOfType(TrackType.Data); }
public void IndexBelongsToFile() { Indexer indexer = new Indexer("h264_720p_hp_3.1_600kbps_aac_mp3_dual_audio_harry_potter.mkv"); indexer.Index().WriteIndex("h264_720p_hp_3.1_600kbps_aac_mp3_dual_audio_harry_potter.ffindex"); Index indexFromFile = new Index("h264_720p_hp_3.1_600kbps_aac_mp3_dual_audio_harry_potter.ffindex"); Assert.IsTrue(indexFromFile.BelongsToFile("h264_720p_hp_3.1_600kbps_aac_mp3_dual_audio_harry_potter.mkv")); Assert.IsFalse(indexFromFile.BelongsToFile("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv")); }
public void GenericTrackAndAPIFunctions() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); Track track = index.GetTrack(2); Assert.AreEqual(TrackType.Subtitle, track.TrackType); Assert.AreEqual(1, track.TimeBaseNumerator); Assert.AreEqual(0, track.NumberOfFrames); }
public void FrameObjectDisposedCaseTwo() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); VideoSource source = index.VideoSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 0); Frame frame = source.GetFrame(10); source.SetInputFormat(ColorSpace.RGB); // frame is now invalid char dummy = frame.FrameType; }
public void FrameObjectDisposedCaseSix() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); VideoSource source = index.VideoSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 0); Frame frame = source.GetFrame(10); source = null; index = null; GC.Collect(); // frame is now invalid GC.WaitForPendingFinalizers(); char dummy = frame.FrameType; }
public void FrameObjectDisposedCaseOne() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); VideoSource source = index.VideoSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 0); Frame frameone = source.GetFrame(10); Frame frametwo = source.GetFrame(11); // frameone is now invalid int dummy = frameone.EncodedResolution.Width; }
public void FrameObjectDisposedCaseFour() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); VideoSource source = index.VideoSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 0); Frame frame = source.GetFrame(10); List<int> targetFormats = new List<int>(); targetFormats.Add(FFMS2.GetPixelFormat("bgra")); source.SetOutputFormat(targetFormats, frame.EncodedResolution.Width, frame.EncodedResolution.Height, Resizer.Lanczos); // frame is now invalid char dummy = frame.FrameType; }
public void VideoSourceArgumentException() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); VideoSource source = index.VideoSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 10); }
public void VideoSourceGetFrameIntOutOfRange() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); VideoSource source = index.VideoSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 0); source.GetFrame(3000); }
public void IndexGetTrackOutOfRange() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); index.GetTrack(6); }
public void VideoSourceSetOutputFormatWidthOutOfRange() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); VideoSource source = index.VideoSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 0); source.SetOutputFormat(new List<int>(), 0, 10, Resizer.Lanczos); }
public void ReadIndex() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); Assert.IsTrue(index.BelongsToFile("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv")); }
public void VideoSourceUTF8() { Index index = new Index("おはよう.ffindex"); VideoSource source = index.VideoSource("おはよう.mkv", 0); }
public void ReadIndexFileNotFound() { Index index = new Index("this file doesn't exist.avi"); }
public void ReadIndexUTF8() { Index index = new Index("おはよう.ffindex"); Assert.IsTrue(index.BelongsToFile("おはよう.mkv")); }
public void TrackWriteTimecodesIOException() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); VideoSource source = index.VideoSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 0); source.Track.WriteTimecodes(Path.Combine("this directory doesn't exist", "timecodes.txt")); }
public void AudioSourceUTF8() { Index index = new Index("おはよう.ffindex"); AudioSource source = index.AudioSource("おはよう.mkv", 1); }
public void TrackWriteTimecodesUTF8() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); VideoSource source = index.VideoSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 0); source.Track.WriteTimecodes("おはよう.txt"); Assert.IsTrue(File.Exists("おはよう.txt")); }
private void buttonConfirm_Click(object sender, EventArgs e) { var audioFile = boxAudioFile.Text; string indexFile; try { if (!File.Exists(audioFile)) throw new FileNotFoundException(); panelIndexingProgress.BringToFront(); labelIndexingProgress.Text = "Hashing..."; using (var md5 = MD5.Create()) using (var stream = File.OpenRead(audioFile)) { var filename = new UTF8Encoding().GetBytes(Path.GetFileNameWithoutExtension(audioFile)); var buffer = new byte[4096]; filename.CopyTo(buffer, 0); stream.Read(buffer, filename.Length, 4096 - filename.Length); var hash = BitConverter.ToString(md5.ComputeHash(buffer)); indexFile = Path.Combine(Path.GetTempPath(), hash + ".ffindex"); } if (File.Exists(indexFile)) { try { var index = new Index(indexFile); if (index.BelongsToFile(audioFile)) { DialogResult = DialogResult.OK; GeneratedFilter = new DubFilter(audioFile, indexFile, (DubMode)comboDubMode.SelectedIndex); Close(); return; } } catch { // ignored } File.Delete(indexFile); } labelIndexingProgress.Text = "Indexing..."; progressIndexingProgress.Value = 0; progressIndexingProgress.Style = ProgressBarStyle.Continuous; _worker = new BackgroundWorker { WorkerSupportsCancellation = true, WorkerReportsProgress = true }; _worker.ProgressChanged += (o, args) => { progressIndexingProgress.Value = args.ProgressPercentage; }; _worker.DoWork += (bw, workArgs) => { var indexer = new Indexer(audioFile, Source.Lavf); indexer.UpdateIndexProgress += (ind, updateArgs) => { _worker.ReportProgress((int) (((double) updateArgs.Current/updateArgs.Total)*100)); indexer.CancelIndexing = _worker.CancellationPending; }; try { var index = indexer.Index(); try { index.GetFirstIndexedTrackOfType(TrackType.Audio); } catch (KeyNotFoundException) { throw new InvalidDataException("That file doesn't have any audio!"); } index.WriteIndex(indexFile); } catch (OperationCanceledException) { workArgs.Cancel = true; } }; _worker.RunWorkerCompleted += (o, args) => { this.InvokeIfRequired(() => { panelIndexingProgress.SendToBack(); }); if (args.Error != null) { this.InvokeIfRequired(() => { SetFile(string.Empty); if ( MessageBox.Show(args.Error.Message, "ERROR", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.Cancel) Close(); }); return; } if (args.Cancelled) { DialogResult = DialogResult.Cancel; } else { DialogResult = DialogResult.OK; GeneratedFilter = new DubFilter(audioFile, indexFile, (DubMode)comboDubMode.SelectedIndex); } this.InvokeIfRequired(Close); }; _worker.RunWorkerAsync(); } catch (Exception err) { if (MessageBox.Show(err.Message, "ERROR", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.Cancel) Close(); } }
public void FrameAndAPIFunctions() { Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex"); VideoSource source = index.VideoSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 0); Frame frame = source.GetFrame(20); List<int> targetFormats = new List<int>(); targetFormats.Add(FFMS2.GetPixelFormat("bgra")); source.SetOutputFormat(targetFormats, frame.EncodedResolution.Width, frame.EncodedResolution.Height, Resizer.Lanczos); frame = source.GetFrame(20); Assert.AreEqual(704, frame.EncodedResolution.Width); Assert.AreEqual(0, frame.EncodedPixelFormat); Assert.AreEqual(704, frame.Resolution.Width); Assert.AreEqual(FFMS2.GetPixelFormat("bgra"), frame.PixelFormat); Assert.AreEqual(false, frame.KeyFrame); Assert.AreEqual(0, frame.RepeatPicture); Assert.AreEqual(false, frame.InterlacedFrame); Assert.AreEqual('P', frame.FrameType); Assert.AreEqual(ColorSpace.BT470BG, frame.ColorSpace); Assert.AreEqual(ColorRange.MPEG, frame.ColorRange); Bitmap bitmap = frame.Bitmap; bitmap.Save("frame.png", System.Drawing.Imaging.ImageFormat.Png); using (var md5 = MD5.Create()) using (var stream = File.OpenRead("frame.png")) { Assert.AreEqual("36-7F-6A-D6-7A-12-12-EB-8E-4A-3F-DC-D0-F6-F6-13", BitConverter.ToString(md5.ComputeHash(stream))); } source.SetInputFormat(ColorSpace.RGB); frame = source.GetFrame(20); Assert.AreEqual(ColorSpace.RGB, frame.ColorSpace); source.ResetInputFormat(); frame = source.GetFrame(20); Assert.AreEqual(ColorSpace.BT470BG, frame.ColorSpace); }