Useful Stuff

Videos from MOV to MP4 with Picture-in-Picture (PIP)

2016-02-28 13:50

When I was working on R1's RPM measurements, I found it would be easyer to show some things, instead of describing them.

So used an iPhone to tape the robot in action and the oscilloscope output.

I'm sure the video format Apple uses is excellent (I have no clue, whatsoever about video formats, etc.), but

Also for better demonstration:


Since I'm lacking any artistic talent, I'm not a video amateur. What was nedded is some kind of video converting and editing process that

Browsing the web for something that fits and tinkering around a bit, I found a process that uses


These programs have tons of functions. But what I need is pretty limited:

  1. We have to prepare the raw iPhone clips

    I'm using VirtualDub for:

    • converting from iPhone MOV format to AVI (AviSynth only handles? ... correct AVIs!)
      (Open the MOV in VirtualDub and "Save As AVI...")
    • while we are here we also can crop the clips to the frames we want and resize them for PIP
      (adding the "Video|Filter|Resize")

  2. For the PIP effect I use AviSynth

    You can use AviSynth as a pre-processor for VirtualDub:

    • Write a *.avs file, like this one:
      main = DirectShowSource(".\Robotics_R1_RPMs_TR9904_01.avi")
      pipm = DirectShowSource(".\Robotics_R1_RPMs_TR9904_02.avi")
      Overlay(main, pipm, x=640, y=360)
      Where the coordinates are the upper left corner of the pipm overlay in main.

      My numbers are based on:

      • main being 1280x720
      • pipm being 640x360
      • PIP overlay in the lower right quadrant

    • open the *.avs file in VirtualDub

      AviSynth's result will be displayed in VirtualDub.

    • While we are still in VirtualDub, we can post-process the clip (e.g. resize it, etc.).
    • Save the result as AVI.

  3. Convert to target format

    With this step I ran into a few problems.

    If I try to convert directly from AVI to MOV or MP4, the resulting clip had sound only, but no video.

    What finally worked for me was:

    1. convert AVI to MPEG
      c:\>ffmpeg -i Robot_Scope_overlay.avi -q:v 1 Robot_Scope.mpeg

      or if you want to scale you clip in this step (like I did to 640x..., -1 keeps the aspect ratio)

      c:\>ffmpeg -i Robot_Scope_overlay.avi -q:v 1 -vf scale=640:-1 Robot_Scope.mpeg

    2. convert MPEG to MP4 (MOV worked the same way)
      c:\>ffmpeg -i Robot_Scope.mpeg Robot_Scope.mp4

    My resulting MP4 video is only ~950kB for 8s.