[Libav-user] 971129 - I get invalid argument error in avcodec_send_packet
hamidi
hamidi at gmail.com
Mon Feb 18 20:00:44 EET 2019
In the following code:
int CplayerDlg::play()
{
FILE *fp = fopen("video_files/1010.brf", "rb");
ASSERT(fp);
RecordFrame rf;
RecordHeader hdr;
ASSERT(fread(&rf, sizeof(rf), 1, fp) == 1);
ASSERT(rf.frameType == FRAME_TYPE_HEADER);
ASSERT(fread(&hdr, sizeof(hdr), 1, fp) == 1);
GetDlgItem(IDC_DIM)->SetWindowText(format("%dx%d", hdr.width, hdr.height));
GetDlgItem(IDC_CODEC_ID)->SetWindowText(format("%d", hdr.codecId));
GetDlgItem(IDC_PIXEL_FORMAT)->SetWindowText(format("%d", hdr.pixelFormat));
GetDlgItem(IDC_TIMEBASE)->SetWindowText(format("%d/%d",
hdr.timebaseNum, hdr.timebaseDen));
AVHWDeviceType type = av_hwdevice_find_type_by_name("dxva2");
ASSERT(type != AV_HWDEVICE_TYPE_NONE);
AVCodec *decoder = avcodec_find_decoder(AV_CODEC_ID_H264);
ASSERT(decoder);
for (int i = 0;; i++)
{
const AVCodecHWConfig *config = avcodec_get_hw_config(decoder, i);
ASSERT(config);
if (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX &&
config->device_type == type)
{
hw_pix_fmt = config->pix_fmt;
break;
}
}
AVCodecContext *decoder_ctx = avcodec_alloc_context3(decoder);
ASSERT(decoder_ctx);
decoder_ctx->get_format = get_hw_format;
ASSERT(!av_hwdevice_ctx_create(&hw_device_ctx, type, NULL, NULL, 0));
ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx);
ASSERT(!avcodec_open2(decoder_ctx, decoder, NULL));
AVPacket packet;
av_init_packet(&packet);
char buf[100000];
AVFrame *frame = av_frame_alloc();
ASSERT(frame);
while (true)
{
ASSERT(fread(&rf, sizeof(rf), 1, fp) == 1);
ASSERT(rf.frameType == FRAME_TYPE_STREAM);
ASSERT(fread(buf, rf.frameSize, 1, fp) == 1);
packet.data = (uint8_t *) buf;
packet.size = rf.frameSize;
packet.flags = rf.flags;
packet.dts = packet.pts = rf.timestamp;
ASSERT(!avcodec_send_packet(decoder_ctx, &packet));
ASSERT(!avcodec_receive_frame(decoder_ctx, frame));
}
fclose(fp);
av_frame_free(&packet);
return 0;
}
I get error -22 in avcodec_send_packet. The format of the file is
custom, but the format of frames is the same as what I've got previously
from an IP camera (H264). I inspired the code from hw_decode.c from
ffmpeg sources. What I've missed?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20190218/b91a9b2e/attachment.html>
More information about the Libav-user
mailing list