[FFmpeg-devel] [PATCH] qsvenc: write a53 caption data to SEI
Ivan Uskov
ivan.uskov at nablet.com
Sat Nov 7 18:32:04 CET 2015
Hello Will,
Saturday, November 7, 2015, 5:29:15 PM, you wrote:
WK> ---
WK> libavcodec/qsvenc.c | 114
WK> +++++++++++++++++++++++++++++++++++++++++++++--
WK> libavcodec/qsvenc.h | 2 +-
WK> libavcodec/qsvenc_h264.c | 2 +-
WK> 3 files changed, 113 insertions(+), 5 deletions(-)
WK> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
WK> index df1f777..0ee45f9 100644
WK> --- a/libavcodec/qsvenc.c
WK> +++ b/libavcodec/qsvenc.c
WK> @@ -30,6 +30,7 @@
WK> #include "libavutil/log.h"
WK> #include "libavutil/time.h"
WK> #include "libavutil/imgutils.h"
WK> +#include "libavcodec/bytestream.h"
WK>
WK> #include "avcodec.h"
WK> #include "internal.h"
WK> @@ -276,7 +277,7 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
WK> q->param.AsyncDepth = q->async_depth;
WK>
WK> q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
WK> - (sizeof(AVPacket) +
WK> sizeof(mfxSyncPoint) + sizeof(mfxBitstream*)));
WK> + (sizeof(AVPacket) +
WK> sizeof(mfxSyncPoint) + sizeof(mfxBitstream*) + sizeof(mfxEncodeCtrl*)));
WK> if (!q->async_fifo)
WK> return AVERROR(ENOMEM);
WK>
WK> @@ -494,6 +495,27 @@ static void print_interlace_msg(AVCodecContext *avctx, QSVEncContext *q)
WK> }
WK> }
WK>
WK> +static void freep_encoder_ctrl(mfxEncodeCtrl** enc_ptr)
WK> +{
WK> + mfxEncodeCtrl* enc_ctrl;
WK> +
WK> + if (!enc_ptr)
WK> + return;
WK> +
WK> + enc_ctrl = *enc_ptr;
WK> +
WK> + if (enc_ctrl) {
WK> + int i;
WK> + for (i = 0; i < enc_ctrl->NumPayload; i++) {
WK> + av_free(enc_ctrl->Payload[i]->Data);
WK> + av_freep(&enc_ctrl->Payload[i]);
WK> + }
WK> + av_free(enc_ctrl->Payload);
WK> + av_freep(&enc_ctrl);
WK> + }
WK> + *enc_ptr = NULL;
WK> +}
WK> +
WK> int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
WK> AVPacket *pkt, const AVFrame *frame, int *got_packet)
WK> {
WK> @@ -504,6 +526,10 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
WK> mfxSyncPoint sync = NULL;
WK> int ret;
WK>
WK> + // for A53 CC data
WK> + mfxEncodeCtrl* enc_ctrl = NULL;
WK> + AVFrameSideData *side_data = NULL;
WK> +
WK> if (frame) {
WK> ret = submit_frame(q, frame, &surf);
WK> if (ret < 0) {
WK> @@ -526,8 +552,83 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
WK> bs->Data = new_pkt.data;
WK> bs->MaxLength = new_pkt.size;
WK>
+ if (q->>a53_cc && frame) {
WK> + side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC);
WK> + if (side_data) {
Although the code looks ok by itself, I believe it is bad idea to place
H.264-specific code to the function which is common for all
encoders. I believe H.264-specific user data insertion should locates into
the qsvenc_h264.c
I.e. there is necessary some kind of 'SetEncodeCtrl' callback which points to
function into the encoder-specific module.
I believe if you will define a callback pointer QSVEncContext::SetEncodeCtrlCB,
setup it into qsv_enc_init() of the qsvenc_h264.c and call if it non-zero
from ff_qsv_encode() we will have good base to extend add user data for
MPEG2 later. Else we will get very bulky and ugly ff_qsv_encode().
I can release something but I hope you will able to catch my idea.
Please let me know if something is unclear.
--
Best regards,
Ivan mailto:ivan.uskov at nablet.com
More information about the ffmpeg-devel
mailing list