mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-12 10:15:22 +00:00
af1761f7b5
This makes sure the actual stream parameters are used, which is
important mainly for hardware decoding+filtering cases, which would
previously require various weird workarounds to handle the fact that a
fake software graph has to be constructed, but never used.
This should also improve behaviour in rare cases where
avformat_find_stream_info() does not provide accurate information.
This merges Libav commit a3a0230
. It was previously skipped.
The code in flush_encoders() which sets up a "fake" format wasn't in
Libav. I'm not sure if it's a good idea, but it tends to give
behavior closer to the old one in certain corner cases.
The vp8-size-change gives different result, because now the size of
the first frame is used. libavformat reported the size of the largest
frame for some reason.
The exr tests now use the sample aspect ratio of the first frame. For
some reason libavformat determines 0/1 as aspect ratio, while the
decoder returns the correct one.
The ffm and mxf tests change the field_order values. I'm assuming
another libavformat/decoding mismatch.
Signed-off-by: wm4 <nfxjfg@googlemail.com>
110 lines
3.0 KiB
C
110 lines
3.0 KiB
C
/*
|
|
* This file is part of FFmpeg.
|
|
*
|
|
* 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.
|
|
*
|
|
* 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 FFmpeg; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
#include <mfx/mfxvideo.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "libavutil/dict.h"
|
|
#include "libavutil/hwcontext.h"
|
|
#include "libavutil/hwcontext_qsv.h"
|
|
#include "libavutil/mem.h"
|
|
#include "libavutil/opt.h"
|
|
#include "libavcodec/qsv.h"
|
|
|
|
#include "ffmpeg.h"
|
|
|
|
char *qsv_device = NULL;
|
|
|
|
static int qsv_get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
|
|
{
|
|
InputStream *ist = s->opaque;
|
|
|
|
return av_hwframe_get_buffer(ist->hw_frames_ctx, frame, 0);
|
|
}
|
|
|
|
static void qsv_uninit(AVCodecContext *s)
|
|
{
|
|
InputStream *ist = s->opaque;
|
|
av_buffer_unref(&ist->hw_frames_ctx);
|
|
}
|
|
|
|
static int qsv_device_init(InputStream *ist)
|
|
{
|
|
int err;
|
|
AVDictionary *dict = NULL;
|
|
|
|
if (qsv_device) {
|
|
err = av_dict_set(&dict, "child_device", qsv_device, 0);
|
|
if (err < 0)
|
|
return err;
|
|
}
|
|
|
|
err = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_QSV,
|
|
ist->hwaccel_device, dict, 0);
|
|
if (err < 0) {
|
|
av_log(NULL, AV_LOG_ERROR, "Error creating a QSV device\n");
|
|
goto err_out;
|
|
}
|
|
|
|
err_out:
|
|
if (dict)
|
|
av_dict_free(&dict);
|
|
|
|
return err;
|
|
}
|
|
|
|
int qsv_init(AVCodecContext *s)
|
|
{
|
|
InputStream *ist = s->opaque;
|
|
AVHWFramesContext *frames_ctx;
|
|
AVQSVFramesContext *frames_hwctx;
|
|
int ret;
|
|
|
|
if (!hw_device_ctx) {
|
|
ret = qsv_device_init(ist);
|
|
if (ret < 0)
|
|
return ret;
|
|
}
|
|
|
|
av_buffer_unref(&ist->hw_frames_ctx);
|
|
ist->hw_frames_ctx = av_hwframe_ctx_alloc(hw_device_ctx);
|
|
if (!ist->hw_frames_ctx)
|
|
return AVERROR(ENOMEM);
|
|
|
|
frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data;
|
|
frames_hwctx = frames_ctx->hwctx;
|
|
|
|
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 = 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);
|
|
if (ret < 0) {
|
|
av_log(NULL, AV_LOG_ERROR, "Error initializing a QSV frame pool\n");
|
|
return ret;
|
|
}
|
|
|
|
ist->hwaccel_get_buffer = qsv_get_buffer;
|
|
ist->hwaccel_uninit = qsv_uninit;
|
|
|
|
return 0;
|
|
}
|