eMFrameClone controls which parts of a frame are copied and whether its video buffer is shared. Use it with MFFrame.MFClone() in MFormats or MFrame.FrameClone() in MPlatform.
Each call returns a new frame object. A new object does not necessarily have independent pixels or independent attached objects. Choose the clone type according to what you intend to modify.
Choosing a clone type
Use eMFC_Full before editing video and audio independently of the source. Use eMFC_Reference when you can share the source video and want to carry audio and metadata. Despite its name, eMFC_Reference copies audio; it does not create an audio-buffer reference.
With a video-reference clone, treat the shared pixels as read-only. Changes to shared pixel memory can affect the source and other frames using that memory. The clone has its own timing and format descriptors, so you can change its timestamps and supported descriptive flags, such as interlace, 3D or scaling flags. Changing descriptors does not resize or convert the underlying buffer.
Pass the clone type and pixel format on each cloning call. These are method arguments, not properties configured through PropsSet. The flags select existing content; they do not generate missing video or audio.
Content flags and combinations
The values below are bit flags or predefined combinations. Combine flags with bitwise OR. Choose either eMFC_Video or eMFC_VideoRef for video. eMFC_Props is zero, so OR-ing it with another value adds no flags.
| Member | Value | Result and intended use |
|---|---|---|
eMFC_Props | 0 / 0x000 | Copies frame timing and format properties, including M_TIME and M_AV_PROPS, without video or audio buffers. Useful for event or timing frames. |
eMFC_Video | 1 / 0x001 | Copies video into independent storage. No audio buffer; audio can be added later. Does not request string/binary or object attachments. |
eMFC_VideoRef | 2 / 0x002 | Shares the video buffer when no conversion is required. No audio buffer; audio can be added later. Does not request string/binary or object attachments. |
eMFC_Audio | 16 / 0x010 | Copies audio without a video buffer. Video cannot subsequently be added to this audio-only frame by changing its format properties. Does not request string/binary or object attachments. |
eMFC_VideoRef_Audio | 18 / 0x012 | VideoRef | Audio: shares video and copies audio. You may edit the copied audio while treating the shared pixels as read-only. |
eMFC_Data | 256 / 0x100 | Copies additional binary data and strings. Does not copy video or audio buffers. |
eMFC_Obj | 512 / 0x200 | Copies entries for named objects attached to the frame. The attached objects are not necessarily duplicated and may remain shared with the source. Does not copy video or audio buffers. |
eMFC_Data_Audio | 272 / 0x110 | Data | Audio: Copies audio, additional binary data, and strings. Does not copy video. |
eMFC_ObjData_Audio | 784 / 0x310 | Obj | Data | Audio: Copies audio, additional binary data, strings, and attached object entries. Does not copy video. Attached objects may remain shared. |
eMFC_Reference | 786 / 0x312 | VideoRef | Audio | Data | Obj: Shares the video buffer and copies audio, frame properties, additional binary data, strings, and attached object entries. Audio can be modified independently; shared video pixels must not be modified. Attached objects may remain shared. |
eMFC_Full | 785 / 0x311 | Video | Audio | Data | Obj: Copies video and audio buffers, frame properties, additional binary data, strings, and attached object entries. Attached objects may remain shared; this is not a recursive deep copy. |
Metadata and attached objects
Data means string and binary side data, not the video or audio buffers. Object attachments are exposed through IMFFrame and IMFSideData. MPlatform's MFrame also exposes these interfaces.
Omitting eMFC_Data is not a metadata-removal operation. Some cloning paths retain existing string/binary side data even when that flag is absent, including local clones without pixel conversion. The table describes what each flag requests; it is not a guarantee that every other metadata entry is removed.
A full clone is not a deep copy of every attached object. An object attachment can still refer to the same underlying object as the source. If your application modifies an attached object, arrange a separate copy using that object's own API when available.
CPU and GPU modifiers
These modifiers select the destination video storage. They do not mean that every part of the operation executes exclusively on the CPU or GPU. Combine a modifier with a content selection, or use one of the predefined combinations below.
| Modifier | Value | Meaning |
|---|---|---|
eMFC_ForceCPU | 4096 / 0x1000 | Requests CPU-memory storage for the cloned frame. Combine this modifier with a clone mode, or use a corresponding _ForceCPU value. Transferring video from GPU to CPU requires copying. |
eMFC_ForceGPU | 8192 / 0x2000 | Requests GPU-memory storage for the cloned frame. Combine this modifier with a clone mode, or use a corresponding _ForceGPU value. Requires available GPU support; otherwise, the implementation may fall back to CPU memory. |
Without a modifier, cloning normally retains the source's CPU/GPU storage kind. A transfer between CPU and GPU requires a video copy, including for a clone type containing VideoRef. A reference clone can share pixels only when the storage and format permit it. Do not specify both force modifiers.
| Predefined member | Value | Equivalent selection |
|---|---|---|
eMFC_Video_ForceCPU | 4097 / 0x1001 | Video | ForceCPU: independent CPU video; no audio. |
eMFC_VideoRef_ForceCPU | 4098 / 0x1002 | VideoRef | ForceCPU: CPU video reference where possible; copies video when a transfer is needed. No audio. |
eMFC_VideoRef_Audio_ForceCPU | 4114 / 0x1012 | VideoRef_Audio | ForceCPU: CPU video reference where possible, with copied audio. |
eMFC_Reference_ForceCPU | 4882 / 0x1312 | Reference | ForceCPU: CPU video reference where possible, copied audio and side data, and object attachments. |
eMFC_Full_ForceCPU | 4881 / 0x1311 | Full | ForceCPU: independent CPU video and audio, copied side data, and object attachments. |
eMFC_Video_ForceGPU | 8193 / 0x2001 | Video | ForceGPU: independent video in the requested GPU storage; no audio. |
eMFC_VideoRef_ForceGPU | 8194 / 0x2002 | VideoRef | ForceGPU: GPU video reference where possible; copies video when a transfer is needed. No audio. |
eMFC_VideoRef_Audio_ForceGPU | 8210 / 0x2012 | VideoRef_Audio | ForceGPU: GPU video reference where possible, with copied audio. |
eMFC_Reference_ForceGPU | 8978 / 0x2312 | Reference | ForceGPU: GPU video reference where possible, copied audio and side data, and object attachments. |
eMFC_Full_ForceGPU | 8977 / 0x2311 | Full | ForceGPU: independent video in the requested GPU storage, copied audio and side data, and object attachments. |
The GPU combinations have the same GPU-availability fallback as eMFC_ForceGPU. Inspect the returned frame with MFAVPropsGet or FrameAVPropsGet; vidProps.eGPUFlags reports its actual backing.
Pixel format and RGB orientation
The third cloning argument, _fccPixelFormat, selects the output pixel format. Pass eMFCC_Default to retain the source format. If the requested format requires pixel conversion, video is copied even for a reference selection. Compatible layout changes, such as RGB32/ARGB32 relabeling, may retain shared storage. To require independent pixels, explicitly choose eMFC_Video or eMFC_Full.
| Member | Value | Meaning |
|---|---|---|
eMFC_BottomTop_ARGB | 65536 / 0x10000 | Requests bottom-up orientation when converting non-RGB video to RGB/ARGB. Combine this flag with a clone mode. It is not a general-purpose vertical-flip operation for existing RGB/ARGB frames. |
For CPU ARGB32 buffers with nonnegative nRowBytes, negative nHeight means top-down and positive nHeight means bottom-up. RGB can also be represented with a negative stride and a shifted pointer; in that representation, the sign of nHeight alone does not determine row traversal. Read the returned fccType, nHeight and signed nRowBytes before accessing pixels. Use the returned pointer and stride together; do not assume a tightly packed or top-down buffer.
MFormats example: prepare independent CPU pixels
MFormats applications pull frames, process them and pass them to receivers in their own frame loop. This C# fragment fits inside that loop. It assumes sourceFrame is a valid MFORMATSLib.MFFrame containing video and local to the application process, and preview is an initialized MFormats preview. The caller owns both inputs and keeps them alive throughout the fragment.
This fragment does not accept out-of-process COM frames. ForceCPU selects CPU memory; calling MFClone on a frame hosted in another process does not by itself make the returned frame local to the application.
GPU-to-CPU copying can continue after MFClone returns. Call MFWaitAsync on the returned clone before reading or modifying its pixels. Neither MFAVPropsGet nor MFVideoGetBytes waits for that copying to finish.
MFORMATSLib.MFFrame clone = null;
try
{
sourceFrame.MFClone(
out clone,
MFORMATSLib.eMFrameClone.eMFC_Full_ForceCPU,
MFORMATSLib.eMFCC.eMFCC_ARGB32);
clone.MFWaitAsync();
clone.MFAVPropsGet(
out MFORMATSLib.M_AV_PROPS props,
out int audioSamples);
clone.MFVideoGetBytes(out int byteCount, out long address);
// Read or edit pixels here while clone is alive.
// Use props.vidProps.nRowBytes and nHeight for the layout.
preview.ReceiverFramePut(clone, -1, "");
}
finally
{
if (clone != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(clone);
}The returned video and audio buffers are independent of the source. Keep the clone alive while using its pixel pointer. The caller must separately release the source frame and close/release its reader and receivers when the pipeline finishes.
MPlatform example: edit a frame before explicit delivery
MPlatform normally connects source objects to receivers. When application code processes an individual MFrame, use FrameClone. Creating a clone does not replace the frame being distributed by the source; deliver the processed clone to the intended receiver explicitly.
This C# fragment runs on an application processing worker. It assumes sourceFrame and overlayFrame are valid MPLATFORMLib.MFrame objects and preview is an initialized MPlatform preview accepting explicit frame delivery. The caller owns these inputs and their surrounding pipeline lifecycle.
MPLATFORMLib.MFrame clone = null;
try
{
sourceFrame.FrameClone(
out clone,
MPLATFORMLib.eMFrameClone.eMFC_Full,
MPLATFORMLib.eMFCC.eMFCC_Default);
clone.FrameOverlay(overlayFrame, 50, 50, 0.5, "");
preview.ReceiverPutFrame("", clone);
}
finally
{
if (clone != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(clone);
}Using a full clone prevents the overlay from modifying shared source pixels. Release every returned clone deterministically, including on exceptions. These fragments release only their own clone; they do not take ownership of the supplied source, overlay or preview.
Still have questions?
Tell us what didn’t work or what you’d like clarified.