I have been searching high and low for an option to force avcodec to use unaligned memory for its AVFrame data.
Depending on the pixel format, the horizontal planes of an AVFrame->data may be padded with extra data to be aligned to memory for performance.
eg: a 1920 * 1080 video with 4 bytes per pixel will have 1920 * 4 = 7680 bytes per plane.
With avcodec if you are decoding this video it will create 7808 bytes per plane.
This adds 7808 - 7680 = 128 bytes of extra padding.
For my purposes I would like to force avcodec to use unaligned data so I can copy an entire continuous chunk of frame data instead of copying and formatting smaller pieces one at a time to a continuous chunk.
The following flag found in the headers:
/* encoding support
These flags can be passed in AVCodecContext.flags before initialization.
Note: Not everything is supported yet.
*/
/**
* Allow decoders to produce frames with data planes that are not aligned
* to CPU requirements (e.g. due to cropping).
*/
#define CODEC_FLAG_UNALIGNED 0x0001
Setting this AVCodecContext.flags to be CODEC_FLAG_UNALIGNED, the assumption is that the AVFrame->data is now unaligned, this is not the case.
I'm not sure if I am looking at the right place or using this flag correctly.
Regards,
Curious George
An important thing with ffmpeg
is to always check anything actually cares about the defined option. Doesn't look like a lot of codecs actually use this flag:
~/sources/ffmpeg-2.1.1> find libavcodec/ -name \*.c | xargs grep CODEC_FLAG_UNALIGNED
libavcodec/hevc_ps.c: !(s->avctx->flags & CODEC_FLAG_UNALIGNED)) {
libavcodec/h264_ps.c: !(h->avctx->flags & CODEC_FLAG_UNALIGNED)) {
~/sources/ffmpeg-2.1.1>