Manually combine 2 images as interlaced video frame

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
^rooker
Site Admin
Posts: 1483
Joined: Fri Aug 29, 2003 8:39 pm

Manually combine 2 images as interlaced video frame

Post by ^rooker »

I'm currently developing a testvideo for automatically detecting field/frame inserts/drops in order to test video A/D converters.

Therefore I needed to manually create images to use as fields.

I'm using ImageMagick to do this. Unfortunately, their information about handling video images is not too much, and mostly involves de-interlacing. So here's how to combine 2 images into a single frame:

1) You need a set of 2 images.
Let's call them:
- top.png
- bottom.png

2) Drop every 2nd line:
Our images have full PAL resolution (since they were manually drawn) and not half the height, like the final field images will have.

First step is to drop every 2nd line and replace it with "black":
The "horizontal2" pattern (=a black line, every 2nd line) must be offset by 1 pixel in order to leave the top line intact (=top field) and mask every even line (=bottom field). So we add "roll +0+1":

Code: Select all

convert top.png -size 720x576 pattern:horizontal2 -compose multiply -roll +0+1 -composite top-field.png
The bottom field has its odd lines masked black:

Code: Select all

convert bottom.png -size 720x576 pattern:horizontal2 -compose multiply -composite bottom-field.png
3) Now merge those 2 images into one frame, by using "black" as transparent:

Code: Select all

convert top-field.png bottom-field.png -compose screen -composite frame.png
That's it! :)
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
User avatar
peter_b
Chatterbox
Posts: 383
Joined: Tue Nov 12, 2013 2:05 am

Opposite: split frame into fields

Post by peter_b »

Here's how you do the exact opposite:
Splitting an interlaced image frame into its 2 half-height-resolution fields.
(imagemagick 6.6.9.7 - Ubuntu Precise 12.04)

Assuming the source image is TFF (top-field-first).

Top (odd lines)

Code: Select all

$ convert interlaced-original.png -roll +0+1 -sample 100%x50% two.png
Bottom (even lines)

Code: Select all

$ convert interlaced-original.png -sample 100%x50% one.png
User avatar
peter_b
Chatterbox
Posts: 383
Joined: Tue Nov 12, 2013 2:05 am

Bash: Script splitting video image in fields

Post by peter_b »

Code: Select all

#!/bin/bash

FILE_IN="$1"
NAME="${FILE_IN%.*}"


CMD="convert \"$FILE_IN\" -roll +0+1 -sample 100%x50% $NAME-top.png"
echo "$CMD"
eval "$CMD"
CMD="convert \"$FILE_IN\" -sample 100%x50% $NAME-bottom.png"
echo "$CMD"
eval "$CMD"
Post Reply