Back

RMovie::Movie object methods
Method Description
movie = RMovie::Movie.new(String path_to_movie) Open a media file and Return it as an object.
  • path_to_movie - File path of media file to open. This path can also be a URL.
movie.duration Return the duration in seconds.
movie.frame_count Return the number of frames.
movie.frame_rate Return the frame rate of a video in frames per second.
movie.file_name Return the path and name of media file.
movie.comment Return the comment field from the media file.
movie.title Return the title field from the media file.
movie.author alias movie.artist Return the author field from the movie or the artist ID3 field from an mp3 file.
movie.copyright Return the copyright field from the media file.
movie.artist Return the artist ID3 field from an mp3 file.
movie.genre Return the genre ID3 field from an mp3 file.
movie.track Return the track ID3 field from an mp3 file.
movie.year Return the year ID3 field from an mp3 file.
movie.frame_height Return the height of the movie in pixels.
movie.frame_width Return the width of the movie in pixels.
movie.pixel_format Return the pixel format of the movie.
movie.bit_rate Return the bit rate of the media file in bits per second.
movie.frame_number Return the current frame index.
movie.video_codec Return the name of the video codec used to encode this movie, as a string.
movie.audio_codec Return the name of the audio codec used to encode this movie, as a string.
movie.audio_channels Return the number of audio channels in this movie as an integer.
movie.has_audio? Return boolean value indicating whether the movie has an audio stream.
movie.frame([int frame_number]) Returns a frame from the movie as an RMovie::Frame object. Returns false if the frame was not found.
  • frame_number - Frame from the movie to return. If no frame_number is specified, returns the next frame of the movie.
movie.next_key_frame Returns the next key frame from the movie as an RMovie::Frame object. Returns false if the frame was not found.
movie.export(string file_name) Exports the movie to a file. Movie format is determined by the file suffix. If export() cannot find a matching encoder then it will use MPEG. This function is incomplete right now and only supports exporting video.
  • file_name - Name of the file to export the movie into.

RMovie::Frame object methods
Method Description
frame = new RMovie::Frame Create a frame object.
frame.width Return the width of the frame.
frame.height Return the height of the frame.
frame.pts alias frame.presentation_timestamp Return the presentation time stamp of the frame.
frame.key_frame? Return true if this frame is a keyframe.
frame.resize!(int width, int height) Resize the frame.
  • width - New width of the frame (must be an even number).
  • height - New height of the frame (must be an even number)
frame.crop!(int crop_top , int crop_bottom , int crop_left , int crop_right) Crop the frame.
  • crop_top - Remove crop_top rows of pixels from the top of the frame.
  • crop_bottom - Remove crop_bottom rows of pixels from the bottom of the frame.
  • crop_left - Remove crop_left rows of pixels from the left of the frame.
  • crop_right - Remove crop_right rows of pixels from the right of the frame.

NOTE: Crop values must be even numbers.
frame.to_string Returns the frame as a packed RGB string. This string is suitable for importing into RMagick using Image.import_pixels. Example:
movie = RMovie::Movie.new("movie.avi")

frame = mov.frame(5)

frame_as_string = frame.to_string

img = Magick::Image.new(frame.width, 
			frame.height)

img.import_pixels(0, 0, frame.width, 
			frame.height, "RGB", 
			frame_as_string, 
			Magick::CharPixel)

img.write('out.jpg')
RMovie::Animated_GIF object methods
Method Description
gif = new RMovie::Animated_GIF(String output_file, width, height, frame_rate, loop_count) Create an animated gif object.
  • path_to_movie - File path of media file to open. This path can also be a URL.
  • width - Width in pixels of the gif to be generated.
  • height - Height in pixels of the gif to be generated.
  • frame_rate - Frame rate in frames per second of the gif.
  • loop_count - Number of times to repeat the animation (note, this is beyond the initial play. The gif will ALWAYS loop at least once so specifying a loop_count of '1' will give you the initial play and will loop around to play one more time.). If you don't want any looping, you can leave off this parameter. If you want to loop indefinitely, put a zero for this parameter.
gif.add_frame!(Rmovie::Frame frame) Add a frame to the animated gif
gif.close()() Close the gif and flush it to disk. (NOTE: This will happen automatically when the gif object is garbage collected.)