Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle invalid creation_time, compatibility with recent ffmpeg version #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ffmpeg/encoding_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 12 additions & 2 deletions lib/ffmpeg/movie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions spec/ffmpeg/movie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ 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
@movie.video_codec.should =~ /h264/
end

it "should know the colorspace" do
@movie.colorspace.should == "yuv420p"
@movie.colorspace.should =~ /yuv420p(\(tv, bt709\))?/
end

it "should know the resolution" do
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/ffmpeg/transcoder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down