Permalink
Browse files

Add trimming feature - Cut starting(seek_time) up to ending(duration)…

… of the video.
  • Loading branch information...
1 parent 1a7db76 commit 996d8b72dba1ed12dc32d12ed3f2ecd45c64dfd1 Lalit K. Shandilya committed Jul 9, 2014
Showing with 18 additions and 1 deletion.
  1. +4 −0 lib/ffmpeg/movie.rb
  2. +14 −1 lib/ffmpeg/transcoder.rb
View
@@ -107,6 +107,10 @@ def screenshot(output_file, options = EncodingOptions.new, transcoder_options =
Transcoder.new(self, output_file, options.merge(screenshot: true), transcoder_options).run &block
end
+ def trim(output_file, start_trim, end_trim, &block)
+ Transcoder.new(self, output_file, start_trim, end_trim).run_trim &block
+ end
+
protected
def aspect_from_dar
return nil unless dar
@@ -4,6 +4,15 @@
module FFMPEG
class Transcoder
@@timeout = 30
+ @@trim_video = false
+
+ def self.trim_video=(trim)
+ @@trim_video = trim
+ end
+
+ def self.trim_video
+ @@trim_video
+ end
def self.timeout=(time)
@@timeout = time
@@ -54,7 +63,11 @@ def encoded
private
# frame= 4855 fps= 46 q=31.0 size= 45306kB time=00:02:42.28 bitrate=2287.0kbits/
def transcode_movie
- @command = "#{FFMPEG.ffmpeg_binary} -y -i #{Shellwords.escape(@movie.path)} #{@raw_options} #{Shellwords.escape(@output_file)}"
+ if @@trim_video
+ @command = "#{FFMPEG.ffmpeg_binary} -ss #{@raw_options.seek_time} -i #{Shellwords.escape(@movie.path)} -t #{@raw_options.duration} -acodec copy -vcodec copy -async 1 -y #{Shellwords.escape(@output_file)}"
+ else
+ @command = "#{FFMPEG.ffmpeg_binary} -y -i #{Shellwords.escape(@movie.path)} #{@raw_options} #{Shellwords.escape(@output_file)}"
+ end
FFMPEG.logger.info("Running transcoding...\n#{@command}\n")
@output = ""

0 comments on commit 996d8b7

Please sign in to comment.