In the following code:
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?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)); decoder_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(&frame); return 0; }
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays!
+ Reply to Thread
Results 1 to 1 of 1
Thread
Similar Threads
-
invalid argument: level = ain
By CDEvans in forum EditingReplies: 4Last Post: 22nd Sep 2018, 08:04 -
Invalid Argument to function "Overlay"
By xMike in forum EditingReplies: 4Last Post: 7th Apr 2018, 10:38 -
Finalized Error - IFO File is Invalid
By codymonster in forum Camcorders (DV/HDV/AVCHD/HD)Replies: 26Last Post: 3rd Feb 2017, 07:10 -
Blu-Ray burning failing with 2 reasons.Invalid Field in CDB&Write Error
By navarannan in forum Authoring (Blu-ray)Replies: 7Last Post: 7th Sep 2016, 21:59 -
"Invalid SRT format. "06B20BF0" is invalid timing info" error with tsMuxeR
By Jijital in forum Authoring (Blu-ray)Replies: 6Last Post: 3rd Feb 2016, 00:18