title: Implementing picture zoom effect using Rmagick and FFmpeg
body: <p>I have a picture and I need to get zoom effect on the resulting video. I almost get the desired result.. but. The resulting picture looks a bit shaky. It's because of rounding on cropping and resizing.. so  centre of the picture shifts slightly with each conversion. What can i do with that? Or maybe there is some other method to implement it?
  In the input I have 
  <strong>picture,zoom_type,zoom_percent,zoom_duration,scene_duration</strong>
  Here is part of the code which making the job:</p>
  
  <pre><code>img = Magick::ImageList.new(picture).first
  width, height = img.columns.to_f, img.rows.to_f
  img_fps = 30
  if width &gt;= height
    aspect_ratio = (width / height)
    zoom_small_size = ((height * (100 - zoom_percent)) / 100).to_f
    small_size = height
  else
    aspect_ratio = (height / width)
    zoom_small_size = ((width * (100 - zoom_percent)) / 100).to_f
    small_size = width
  end
  factor = (((small_size - zoom_small_size) / (img_fps * zoom_duration))).to_f
  while factor &lt; 2
    img_fps -= 1
    factor = ((small_size - zoom_small_size) / (img_fps * zoom_duration))
  end
  total_images = img_fps * scene_duration
  zoom_images = img_fps * zoom_duration_seed
  new_width =  width
  new_height =  height
  zoom_changed_small_size = small_size
  
  total_images.times do |i|
  if zoom_images &gt; 0 &amp;&amp; zoom_changed_small_size &gt; zoom_small_size
    img_n = img.crop(new_width, new_height, true)
    new_width = (width &lt;= height) ? (new_width - factor).round : (new_width-factor*aspect_ratio).round
    new_height = (width &gt;= height) ? (new_height-factor).round : (new_height-factor*aspect_ratio).round
    zoom_changed_small_size = (width &gt;= height) ? img_n.rows : img_n.columns
    img_n.resize_to_fill!(width, height)
    img_n.write("#{sprintf("img_%04d.jpg" % (i+1))}")
    zoom_images -= 1
    img = img_n.copy if zoom_images == 0 || zoom_changed_small_size &lt;= zoom_small_size
    img_n.destroy!
  else
    img.write("#{sprintf("img_%04d.jpg" % (i+1))}")
    puts "Writing - #{img.filename}"
  end
  end
  </code></pre>
  
  <p>Then ffmpeg -y -f image2 -r 30 -i img_%04d.jpg -crf 0 -preset ultrafast -tune stillimage -pix_fmt yuv420p out.mp4</p>