System designTroubleshooting

imaqWriteAVIFrame incompatible image size: fix the buffer

Why imaqWriteAVIFrame rejects frames with 'incompatible image size' or writes black AVIs, and how to fill the image from a real grab before you write.

LumaSpec Vision9 min read Share on LinkedIn

On this page 10 sections
  1. 01What the writer actually checks
  2. 02Why imaqCreateImage returns (0, 0)
  3. 03Why imaqsetImageSize gives you black frames
  4. 04Likely causes, in order of probability
  5. 05The fix: acquire into the image, then write
  6. 06Two documented writer rules: image type and even height
  7. 07Worked example: does the file size add up
  8. 08When the grabber itself is the legacy problem
  9. 09Checks before you ship the recorder
  10. 10Questions

Your grabber runs, the writer accepts every frame, and the clip plays solid black — or the very first write fails with 'incompatible image size'. Both symptoms have one root: the image you passed to the writer holds no acquired frame. This guide is for engineers recording frame-grabber video from C code that uses the imaq function set. You will see why a freshly created image reports 0 × 0 pixels, why forcing its size makes the error disappear and the video go black, and how to wire acquisition so every written frame carries real pixels. A worked PAL example gives you the file-size arithmetic to prove a clip is complete before you ship the recorder.

What the writer actually checks

Before storing a frame, the writer compares your image with the AVI stream it opened. Width and height must be non-zero and equal to the stream's dimensions, and the pixel format must be one of the two it stores. 'Incompatible image size' pins the failure to the first check: the image you passed reports no usable dimensions, typically (0, 0).

That is not a settings problem in the writer — it is a statement about your buffer. The image exists as an object, but no acquisition has ever filled it, so the writer refuses to size a video around it. The fix is not a different size. It is giving the image a frame.

Why imaqCreateImage returns (0, 0)

imaqCreateImage builds a header: pixel type, border size, ownership. It allocates no pixels and stores no dimensions. Everything else arrives when data is copied into the image — and the call that copies is the acquisition itself. A grab or snap into that image writes the sensor data and sets the image's width and height to the acquisition window in one step. A (0, 0) reading straight after creation is normal, not a bug.

The fault appears one step later, when the code writes that untouched image. If creation itself fails instead of returning an empty header, that is a different problem — diagnose frame grabber buffer allocation errors covers allocation failures.

Why imaqsetImageSize gives you black frames

imaqsetImageSize changes the header's dimensions and nothing else. It does not allocate pixels, convert formats or copy a byte of video. After you set (640, 480) by hand, the writer's dimension check passes, every frame is accepted, and each stored frame is a header-sized block with no pixel content behind it: black. The file grows with duration exactly as a live recording would, because the frames exist — only their content is empty.

File size cannot reveal the black frames either. Uncompressed, every frame stores all its pixels, black ones included, so a full-length black clip and a full-length live clip are the same size on disk. Judge frames by pixel values, never by bytes.

Likely causes, in order of probability

Work down the table; the first three rows account for most cases, and each test takes under a minute.

Rank Likely cause Test Fix
1 No grab or snap ran before the first write Log width and height right after your acquire step; (0, 0) means it never ran Acquire one frame into the image before opening the writer
2 Acquisition fills a different image than the writer receives Print the image handle at the grab and at the write; they must be identical Write the exact image the grab filled
3 A resize call papers over the empty buffer Search the recording path for a set-size call between create and write Remove it and acquire into the image instead
4 Pixel type the writer does not store, such as 16-bit gray or planar color Read the image type back and compare with the two accepted formats Convert or copy every frame into an accepted type before writing
5 Odd frame height: pixels exist, some players show black Width and height modulo 2 Even line count in the acquisition window
6 Ring buffer reused before the write completed Mid-clip frames torn or half stale Write inside the grab callback, or copy the frame out first

Rows 1 and 2 are the buffer hand-off that current interfaces make explicit too: frame grabber image acquisition for Camera Link and CoaXPress walks through how a frame grabber hands buffers to your code.

The fix: acquire into the image, then write

  1. Create the image in the pixel type you will write: 8-bit grayscale for a mono grabber, 32-bit RGB for color. Raw transport bytes and pixel planes are different things — image bytes vs pixel data: decode before processing explains the distinction.
  2. Configure the session and start acquisition: video standard PAL, acquisition window sized for your scene.
  3. Grab or snap one frame into that image before you open the AVI. The call copies sensor data in and sets the image size to the window in the same step.
  4. Read the width and height back from the image. Non-zero, and equal to your acquisition window, means the buffer is real; on a full PAL window that is 576 lines by 768 pixels for square-pixel capture, or 720 pixels at ITU-R BT.601 sampling.
  5. Open the writer at that width, height and type, then write each frame immediately after its grab — always the same image, always in order. Recording continuously? Grab into a ring and write each buffer while it is still yours, the pattern in save an image sequence from a frame grabber with a ring buffer.
  6. Close the writer when the loop ends. The index players rely on is written at close, so a skipped close can leave a full file unplayable; if the file exists but holds no frames at all, empty camera recording file: check writer setup and cleanup works that failure.

Two documented writer rules: image type and even height

The writer stores 8-bit grayscale and 32-bit RGB images and rejects other formats with its own type error, as the function's documentation notes on incompatible image types. A mono analog grabber delivers 8-bit gray and fits directly; convert 16-bit or planar color frames before writing.

Playback adds a second rule: keep the frame height even. Some decoders render an odd-height file as black even though every pixel is stored, a behavior the knowledge base documents for AVI files that play back black. PAL's 576 lines are even, so a full window is safe; round any region-of-interest crop to an even line count. If a file will not open at all — rather than opening black — that is a container or decoder problem, and video capture backend fallback: diagnose AVI open errors works through it.

Worked example: does the file size add up

bytes per frame = width × height × bytes per pixel clip size ≈ frames × bytes per frame + container overhead

Take a full square-pixel PAL window at 8-bit gray. Width × height: 768 × 576 = 442,368 bytes per frame, about 442 kB. PAL runs at 25 frames per second, so one second of video is 442,368 × 25 = 11,059,200 bytes — roughly 11.1 MB/s, or 663 MB per minute (11,059,200 × 60 = 663,552,000). A 10-second clip stores 250 × 442,368 = 110,592,000 bytes, about 111 MB.

Use the number twice. If your uncompressed 10-second clip lands near 111 MB, all 250 frames were written — now sample pixels to prove they are live, because black frames cost the same bytes. If the clip holds a few kB, the writes were rejected or never called, and the causes table above is your next stop.

When the grabber itself is the legacy problem

A PCI grabber of that generation runs on the driver stack it shipped with. On a current 64-bit Windows build, loading that driver is usually the first failure, and no recording code revives a driver its vendor no longer maintains. If this recorder is part of a new line, move acquisition to a current interface and keep the same discipline: create the image, grab into it, write it.

Staying card-based, the Hikrobot MV-GE1104 is a 4-port GigE frame grabber.

Frame grabbersHikrobot MV-GE1104 4-port GigE frame grabberMV-GE1104
Interface
GigE
Ports
4 ports
$699.00View partBuild a system with it

If your cameras take power over the network cable, the Hikrobot MV-GE2002P is a dual-port PoE NIC in a full height card.

Frame grabbersHikrobot MV-GE2002P Dual-port PoE NIC, full height V2.0MV-GE2002P
Interface
GigE
Ports
2 ports
$249.00View partBuild a system with it

Either card leaves the recording loop unchanged: the SDK copies each frame into your image, and the writer receives buffers that already hold pixels. Browse the frame grabbers category for the current range, filter by interface and ports in the accessories finder, and pick a current area scan camera from the camera finder. The configurator assembles camera, card and cables into one checked parts list.

Checks before you ship the recorder

  • One image handle from create to write — the grab and the writer see the same buffer.
  • Width and height read back non-zero after the first grab and equal the acquisition window.
  • No resize call anywhere in the recording path.
  • Image type is 8-bit gray or 32-bit RGB, matching the stream you opened.
  • Line count of the acquisition window is even.
  • Every write call's return code is logged, so the first rejection names itself.
  • After close: file size within a few percent of frames × bytes per frame, and a mid-clip frame decodes with non-zero pixels.

If the arithmetic does not close for your window and frame rate, the contact page is the direct line to our applications team.

Questions

Is it a problem that imaqCreateImage returns a (0,0) image?

No. The call builds an empty image header — type, border and ownership only. Width and height fill in when an acquisition copies pixels into the image, so (0,0) is normal right after creation. It becomes a fault only when that untouched image reaches the AVI writer, which reports the size mismatch instead of inventing dimensions.

Which image types does the AVI writer accept?

The documented set is 8-bit grayscale and 32-bit RGB. A mono analog grabber delivers 8-bit gray and fits directly. If your session produces 16-bit gray or planar color, convert or copy every frame into an accepted type before the write call, and open the AVI with the same width, height and type you will write.

Why does my AVI play black in some players but not others?

Check the frame height. Some decoders render odd-height files as black even though every pixel is stored correctly. Keep the line count even: a full PAL window at 576 lines is safe, and any region-of-interest crop should be rounded to an even height too. The pixels are there; the player just refuses the odd geometry.

How large will an uncompressed PAL recording be?

About 442 kB per frame at 768 × 576 in 8-bit gray. At 25 fps that is 442,368 × 25 = 11,059,200 bytes per second, so roughly 11.1 MB/s or 663 MB per minute uncompressed. If your clip is far smaller than frames × frame size, the writes were rejected — black uncompressed frames still occupy full size.

Does compression change how I diagnose black frames?

Yes. Without compression every frame stores all its pixels, so file size cannot separate black from live. With a codec, black frames compress to almost nothing, so a clip far below the expected size is a strong first clue. Confirm by decoding one mid-clip frame and checking its pixel values before trusting the recording.