From b95e6ae2846c49f999196e575d354ca49d7f3992 Mon Sep 17 00:00:00 2001 From: Alexis Date: Thu, 19 Feb 2015 11:58:13 -0800 Subject: [PATCH] handle invalid creation_time, compatibility with recent ffmpeg version --- lib/ffmpeg/encoding_options.rb | 4 ++++ lib/ffmpeg/movie.rb | 14 ++++++++++++-- spec/ffmpeg/movie_spec.rb | 6 +++--- spec/ffmpeg/transcoder_spec.rb | 4 ++-- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/ffmpeg/encoding_options.rb b/lib/ffmpeg/encoding_options.rb index be087908..deeab936 100644 --- a/lib/ffmpeg/encoding_options.rb +++ b/lib/ffmpeg/encoding_options.rb @@ -140,6 +140,10 @@ def convert_watermark(value) "-i #{value}" end + def convert_target(value) + "-target #{value}" + end + def convert_watermark_filter(value) case value[:position].to_s when "LT" diff --git a/lib/ffmpeg/movie.rb b/lib/ffmpeg/movie.rb index 5f4fbf7d..dcd16ced 100644 --- a/lib/ffmpeg/movie.rb +++ b/lib/ffmpeg/movie.rb @@ -28,7 +28,7 @@ def initialize(path) @time = $1 ? $1.to_f : 0.0 output[/creation_time {1,}: {1,}(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/] - @creation_time = $1 ? Time.parse("#{$1}") : nil + @creation_time = parse_creation_time($1) output[/bitrate: (\d*)/] @bitrate = $1 ? $1.to_i : nil @@ -53,7 +53,7 @@ def initialize(path) if audio_stream @audio_codec, audio_sample_rate, @audio_channels, unused, audio_bitrate = audio_stream.split(/\s?,\s?/) - @audio_bitrate = audio_bitrate =~ %r(\A(\d+) kb/s\Z) ? $1.to_i : nil + @audio_bitrate = audio_bitrate =~ %r(\A(\d+) kb/s( \(default\))?\Z) ? $1.to_i : nil @audio_sample_rate = audio_sample_rate[/\d*/].to_i end @@ -132,5 +132,15 @@ def fix_encoding(output) rescue ArgumentError output.force_encoding("ISO-8859-1") end + + def parse_creation_time(raw_time) + if raw_time + begin + Time.parse(raw_time) + rescue ArgumentError => ae + FFMPEG.logger.info("Invalid creation_time #{raw_time}") + end + end + end end end diff --git a/spec/ffmpeg/movie_spec.rb b/spec/ffmpeg/movie_spec.rb index 28c33f91..f3a2e632 100644 --- a/spec/ffmpeg/movie_spec.rb +++ b/spec/ffmpeg/movie_spec.rb @@ -233,7 +233,7 @@ module FFMPEG end it "should parse video stream information" do - @movie.video_stream.should == "h264 (Main) (avc1 / 0x31637661), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 371 kb/s, 16.75 fps, 600 tbr, 600 tbn, 1200 tbc" + @movie.video_stream.should =~ /h264 \(Main\) \(avc1 \/ 0x31637661\), yuv420p(\(tv, bt709\))?, 640x480 \[SAR 1:1 DAR 4:3\], 371 kb\/s, 16.75 fps, 600 tbr, 600 tbn, 1200 tbc/ end it "should know the video codec" do @@ -241,7 +241,7 @@ module FFMPEG end it "should know the colorspace" do - @movie.colorspace.should == "yuv420p" + @movie.colorspace.should =~ /yuv420p(\(tv, bt709\))?/ end it "should know the resolution" do @@ -262,7 +262,7 @@ module FFMPEG end it "should parse audio stream information" do - @movie.audio_stream.should == "aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 75 kb/s" + @movie.audio_stream.should =~ /aac (\(LC\))? \(mp4a \/ 0x6134706D\), 44100 Hz, stereo, fltp, 75 kb\/s( \(default\))?/ end it "should know the audio codec" do diff --git a/spec/ffmpeg/transcoder_spec.rb b/spec/ffmpeg/transcoder_spec.rb index 82f7fa3a..6759da18 100644 --- a/spec/ffmpeg/transcoder_spec.rb +++ b/spec/ffmpeg/transcoder_spec.rb @@ -58,8 +58,8 @@ module FFMPEG end it "should still work" do - encoded = Transcoder.new(movie, "#{tmp_path}/awesome.mpg").run - encoded.resolution.should == "640x480" + encoded = Transcoder.new(movie, "#{tmp_path}/awesome.mpg", { target: "ntsc-dvd" }).run + encoded.resolution.should == "720x480" end after { Transcoder.timeout = @original_timeout }