Skip to content
elthariel edited this page Apr 27, 2013 · 3 revisions

Encoding with Intel QuickSync / Media SDK Notes.

This pages holds a few informations about encoding parameters and the data structures associated to it. It might contains a tutorial at some point.

Pay attention that this document is a WIP and many fo these informations are just fragments of my memory.

Basic workflow

  • Initialize the session. At this point you can ask for a specific version of the API or for a specific implementation (HW/SW).
  • Set the allocators if this is relevant ? (at this stage there's no formal proof that this API is relevant at all) You HAVE to set the allocator just after you initialize the session or the de-initialization of the session will crash.
  • Allocate and fill all the data structures with encoding parameters
  • Call mfxVideoENCODE_Init, check whether it's happy or not. We'll document a few parameters set that are known to work as a starting point. If ENCODE_Init is happy, you parameters are correct and supported by the underlying implementation.
  • Now you SHOULD call , to obtain a few values that will be usefull later, like the maximum size of one bitstream output buffer. The (yet known) output parameters are listed below.
  • Call MFXVideoENCODE_QueryIOSurf and allocate a pool of mfxFrameSurface1 as large as suggested. Pay attention to alignment. width/height should be multiple of 16 and all the pointer of surface must be aligned on 32 Bytes boundaries.
  • You can now start the encoding loop.
    • Declare a mfxSyncPoint variable, set it to 0;
    • Find a frame that is not locked in the pool
    • Allocate a bitstream structure with a buffer of BufferSizeInKB
    • Call EncodeAsync with the frame/bitstream/syncpoint pointers
    • Check the return code and the syncPoint value and act accordingly :
      • status == MFX_ERR_MORE_DATA -> The encoder justs needs more data before producing bitstream. This is not really an error. Keep feeding it.
      • status == MFX_ERR_NONE, syncPoint should be now != 0. Perform a SyncOperation on the syncpoint. If you waits 'long enough' and it returns no error, there's data to consume in the bitstream
      • status not one of the above : You're in trouble, try re-opening the associated devices, Resetting the encoder, etc.
  • Profit !

Data structures

mfxVideoParams

typedef struct _mfxVideoParam {
  mfxU32 reserved[3];
  mfxU16 reserved3;
  mfxU16 AsyncDepth;
  union {
    mfxInfoMFX mfx;
    mfxInfoVPP vpp;
  }
  mfxU16 Protected;
  mfxU16 IOPattern;
  mfxExtBuffer **ExtParam;
  mfxU16 NumExtParam;
  mfxU16 reserved2;
} mfxVideoParam;

mfxInfoMFX

/* Transcoding Info */
typedef struct {
    mfxU32  reserved[7];

    mfxU16  reserved4;
    mfxU16  BRCParamMultiplier;

    mfxFrameInfo    FrameInfo;
    mfxU32  CodecId;
    mfxU16  CodecProfile;
    mfxU16  CodecLevel;
    mfxU16  NumThread;

    union {
        struct {   /* MPEG-2/H.264 Encoding Options */
            mfxU16  TargetUsage;

            mfxU16  GopPicSize;
            mfxU16  GopRefDist;
            mfxU16  GopOptFlag;
            mfxU16  IdrInterval;

            mfxU16  RateControlMethod;
            union {
                mfxU16  InitialDelayInKB; 
                mfxU16  QPI;
                mfxU16  Accuracy;
            };
            mfxU16  BufferSizeInKB; // output parameter.
            union {
                mfxU16  TargetKbps;
                mfxU16  QPP;
            };
            union {
                mfxU16  MaxKbps;
                mfxU16  QPB;
                mfxU16  Convergence;
            };

            mfxU16  NumSlice;
            mfxU16  NumRefFrame;
            mfxU16  EncodedOrder;
        };
        struct {   /* H.264, MPEG-2 and VC-1 Decoding Options */
            mfxU16  DecodedOrder;
            mfxU16  ExtendedPicStruct;
            mfxU16  TimeStampCalc;
            mfxU16  SliceGroupsPresent;
            mfxU16  reserved2[9];
        };
        struct {   /* JPEG Decoding Options */
            mfxU16  JPEGChromaFormat;
            mfxU16  Rotation;
            mfxU16  JPEGColorFormat;
            mfxU16  reserved3[10];
        };
        struct {   /* JPEG Encoding Options */
            mfxU16  Interleaved;
            mfxU16  Quality;
            mfxU16  RestartInterval;
            mfxU16  reserved5[10];
        };
    };
} mfxInfoMFX;
Clone this wiki locally