MCPcopy Create free account
hub / github.com/byhook/ffmpeg4android / decode_video

Function decode_video

ffmpeg-single-cmd/src/main/cpp/ffmpeg_mod.c:2370–2500  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2368}
2369
2370static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int eof,
2371 int *decode_failed)
2372{
2373 AVFrame *decoded_frame;
2374 int i, ret = 0, err = 0;
2375 int64_t best_effort_timestamp;
2376 int64_t dts = AV_NOPTS_VALUE;
2377 AVPacket avpkt;
2378
2379 // With fate-indeo3-2, we're getting 0-sized packets before EOF for some
2380 // reason. This seems like a semi-critical bug. Don't trigger EOF, and
2381 // skip the packet.
2382 if (!eof && pkt && pkt->size == 0)
2383 return 0;
2384
2385 if (!ist->decoded_frame && !(ist->decoded_frame = av_frame_alloc()))
2386 return AVERROR(ENOMEM);
2387 if (!ist->filter_frame && !(ist->filter_frame = av_frame_alloc()))
2388 return AVERROR(ENOMEM);
2389 decoded_frame = ist->decoded_frame;
2390 if (ist->dts != AV_NOPTS_VALUE)
2391 dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ist->st->time_base);
2392 if (pkt) {
2393 avpkt = *pkt;
2394 avpkt.dts = dts; // ffmpeg.c probably shouldn't do this
2395 }
2396
2397 // The old code used to set dts on the drain packet, which does not work
2398 // with the new API anymore.
2399 if (eof) {
2400 void *new = av_realloc_array(ist->dts_buffer, ist->nb_dts_buffer + 1, sizeof(ist->dts_buffer[0]));
2401 if (!new)
2402 return AVERROR(ENOMEM);
2403 ist->dts_buffer = new;
2404 ist->dts_buffer[ist->nb_dts_buffer++] = dts;
2405 }
2406
2407 update_benchmark(NULL);
2408 ret = decode(ist->dec_ctx, decoded_frame, got_output, pkt ? &avpkt : NULL);
2409 update_benchmark("decode_video %d.%d", ist->file_index, ist->st->index);
2410 if (ret < 0)
2411 *decode_failed = 1;
2412
2413 // The following line may be required in some cases where there is no parser
2414 // or the parser does not has_b_frames correctly
2415 if (ist->st->codecpar->video_delay < ist->dec_ctx->has_b_frames) {
2416 if (ist->dec_ctx->codec_id == AV_CODEC_ID_H264) {
2417 ist->st->codecpar->video_delay = ist->dec_ctx->has_b_frames;
2418 } else
2419 av_log(ist->dec_ctx, AV_LOG_WARNING,
2420 "video_delay is larger in decoder than demuxer %d > %d.\n"
2421 "If you want to help, upload a sample "
2422 "of this file to ftp://upload.ffmpeg.org/incoming/ "
2423 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n",
2424 ist->dec_ctx->has_b_frames,
2425 ist->st->codecpar->video_delay);
2426 }
2427

Callers 1

process_input_packetFunction · 0.85

Calls 4

update_benchmarkFunction · 0.85
decodeFunction · 0.85
check_decode_resultFunction · 0.85
send_frame_to_filtersFunction · 0.85

Tested by

no test coverage detected