Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- avconv_qsv.c 2016-11-13 14:16:50.934989800 -0300
- +++ ffmpeg_qsv.c 2016-11-13 14:16:20.301820600 -0300
- @@ -1,18 +1,18 @@
- /*
- - * This file is part of Libav.
- + * This file is part of FFmpeg.
- *
- - * Libav is free software; you can redistribute it and/or
- + * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- - * Libav is distributed in the hope that it will be useful,
- + * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- - * License along with Libav; if not, write to the Free Software
- + * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
- @@ -26,7 +26,7 @@
- #include "libavutil/opt.h"
- #include "libavcodec/qsv.h"
- -#include "avconv.h"
- +#include "ffmpeg.h"
- static int qsv_get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
- {
- @@ -76,11 +76,11 @@
- frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data;
- frames_hwctx = frames_ctx->hwctx;
- - frames_ctx->width = s->coded_width;
- - frames_ctx->height = s->coded_height;
- + frames_ctx->width = FFALIGN(s->coded_width, 32);
- + frames_ctx->height = FFALIGN(s->coded_height, 32);
- frames_ctx->format = AV_PIX_FMT_QSV;
- - frames_ctx->sw_format = AV_PIX_FMT_NV12;
- - frames_ctx->initial_pool_size = 32;
- + frames_ctx->sw_format = s->sw_pix_fmt;
- + frames_ctx->initial_pool_size = 64;
- frames_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
- ret = av_hwframe_ctx_init(ist->hw_frames_ctx);
- @@ -94,3 +94,85 @@
- return 0;
- }
- +
- +int qsv_transcode_init(OutputStream *ost)
- +{
- + InputStream *ist;
- + const enum AVPixelFormat *pix_fmt;
- +
- + int err, i;
- + AVBufferRef *encode_frames_ref = NULL;
- + AVHWFramesContext *encode_frames;
- + AVQSVFramesContext *qsv_frames;
- +
- + /* check if the encoder supports QSV */
- + if (!ost->enc->pix_fmts)
- + return 0;
- + for (pix_fmt = ost->enc->pix_fmts; *pix_fmt != AV_PIX_FMT_NONE; pix_fmt++)
- + if (*pix_fmt == AV_PIX_FMT_QSV)
- + break;
- + if (*pix_fmt == AV_PIX_FMT_NONE)
- + return 0;
- +
- + if (strcmp(ost->avfilter, "null") || ost->source_index < 0)
- + return 0;
- +
- + /* check if the decoder supports QSV and the output only goes to this stream */
- + ist = input_streams[ost->source_index];
- + if (ist->hwaccel_id != HWACCEL_QSV || !ist->dec || !ist->dec->pix_fmts)
- + return 0;
- + for (pix_fmt = ist->dec->pix_fmts; *pix_fmt != AV_PIX_FMT_NONE; pix_fmt++)
- + if (*pix_fmt == AV_PIX_FMT_QSV)
- + break;
- + if (*pix_fmt == AV_PIX_FMT_NONE)
- + return 0;
- +
- + for (i = 0; i < nb_output_streams; i++)
- + if (output_streams[i] != ost &&
- + output_streams[i]->source_index == ost->source_index)
- + return 0;
- +
- + av_log(NULL, AV_LOG_VERBOSE, "Setting up QSV transcoding\n");
- +
- + if (!hw_device_ctx) {
- + err = qsv_device_init(ist);
- + if (err < 0)
- + goto fail;
- + }
- +
- + // This creates a dummy hw_frames_ctx for the encoder to be
- + // suitably initialised. It only contains one real frame, so
- + // hopefully doesn't waste too much memory.
- +
- + encode_frames_ref = av_hwframe_ctx_alloc(hw_device_ctx);
- + if (!encode_frames_ref) {
- + err = AVERROR(ENOMEM);
- + goto fail;
- + }
- + encode_frames = (AVHWFramesContext*)encode_frames_ref->data;
- + qsv_frames = encode_frames->hwctx;
- +
- + encode_frames->width = FFALIGN(ist->resample_width, 32);
- + encode_frames->height = FFALIGN(ist->resample_height, 32);
- + encode_frames->format = AV_PIX_FMT_QSV;
- + encode_frames->sw_format = AV_PIX_FMT_NV12;
- + encode_frames->initial_pool_size = 1;
- +
- + qsv_frames->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
- +
- + err = av_hwframe_ctx_init(encode_frames_ref);
- + if (err < 0)
- + goto fail;
- +
- + ist->dec_ctx->pix_fmt = AV_PIX_FMT_QSV;
- + ist->resample_pix_fmt = AV_PIX_FMT_QSV;
- +
- + ost->enc_ctx->pix_fmt = AV_PIX_FMT_QSV;
- + ost->enc_ctx->hw_frames_ctx = encode_frames_ref;
- +
- + return 0;
- +
- +fail:
- + av_buffer_unref(&encode_frames_ref);
- + return err;
- +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement