From eae7660f3e36c8920d801492b11da0b9c356c157 Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Tue, 8 Sep 2009 20:56:50 -0700 Subject: [PATCH] test FFMPEG::Stream --- lib/ffmpeg/stream.rb | 5 +++- lib/ffmpeg/test_case.rb | 14 ++++++++++ test/test_ffmpeg_stream.rb | 57 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 test/test_ffmpeg_stream.rb diff --git a/lib/ffmpeg/stream.rb b/lib/ffmpeg/stream.rb index 45dc00b..8e9dc4c 100644 --- a/lib/ffmpeg/stream.rb +++ b/lib/ffmpeg/stream.rb @@ -127,9 +127,11 @@ class FFMPEG::Stream builder.accessor :start_time, 'int64_t' builder.accessor :quality, 'double' - end + ## + # FIFO for audio streams + attr_accessor :fifo attr_reader :format_context attr_accessor :next_pts @@ -141,6 +143,7 @@ def initialize(format_context=nil) @next_pts = FFMPEG::NOPTS_VALUE @pts = 0 @sync_pts = 0 + @fifo = nil end def inspect diff --git a/lib/ffmpeg/test_case.rb b/lib/ffmpeg/test_case.rb index 83e1ec3..4e4162c 100644 --- a/lib/ffmpeg/test_case.rb +++ b/lib/ffmpeg/test_case.rb @@ -1,11 +1,25 @@ require 'rubygems' +require 'fileutils' require 'minitest/autorun' +require 'tmpdir' + require 'ffmpeg' class FFMPEG::TestCase < MiniTest::Unit::TestCase def setup @thumbs_up = File.expand_path 'Thumbs Up!.3gp', 'test' + + @tmpdir = File.join Dir.tmpdir, "ffmpeg_test_#{$$}" + + FileUtils.mkdir_p @tmpdir + + @thumbs_out = File.join @tmpdir, + File.basename(@thumbs_up).sub(/3gp$/, 'wmv') + end + + def teardown + FileUtils.rm_rf @tmpdir end ## diff --git a/test/test_ffmpeg_stream.rb b/test/test_ffmpeg_stream.rb new file mode 100644 index 0000000..10ce235 --- /dev/null +++ b/test/test_ffmpeg_stream.rb @@ -0,0 +1,57 @@ +require 'ffmpeg/test_case' + +class TestFFMPEGStream < FFMPEG::TestCase + + def setup + super + + @fc = FFMPEG::FormatContext.new @thumbs_out, true + @s = @fc.output_stream(FFMPEG::Codec::VIDEO, 'wmv', :bit_rate => 202_396, + :width => 196, :height => 144, + :fps => FFMPEG.Rational(25, 1)) + end + + def test_codec_context + assert_equal 'msmpeg4', @s.codec_context.codec.name + end + + def test_context_defaults + @s.context_defaults FFMPEG::Codec::VIDEO + + assert_equal FFMPEG::PixelFormat::NONE, @s.codec_context.pixel_format + end + + def test_r_frame_rate + @s.r_frame_rate = FFMPEG.Rational(10, 1) + + assert_equal FFMPEG.Rational(10, 1), @s.r_frame_rate + end + + def test_r_frame_rate_equals + r = FFMPEG.Rational(10, 1) + @s.r_frame_rate = r + + assert_equal r, @s.r_frame_rate + refute_same r, @s.r_frame_rate + end + + def test_time_base + @s.time_base = FFMPEG.Rational(10, 1) + + assert_equal FFMPEG.Rational(10, 1), @s.time_base + end + + def test_time_base_equals + r = FFMPEG.Rational(10, 1) + @s.time_base = r + + assert_equal r, @s.time_base + refute_same r, @s.time_base + end + + def test_type + assert_equal :VIDEO, @s.type + end + +end +