Die avcodec-Bibliothek extrahiert nicht alle Frames aus einem Video

448
Guru Govindan

Ich habe eine Bibliothek geschrieben, die mit Python verwendet werden könnte, um Frames aus einem Video in einem Puffer für die Verarbeitung zu extrahieren. Ich habe die Beispiele aus dem ffmpeg verwendet, um meine Bibliothek mit libavcodec zu erstellen. Dies und scheint bei den meisten Videos gut zu funktionieren. Aber ich sehe auf einigen Videos, wo meine Bibliothek nicht alle Frames extrahiert (weit weniger als das FPS).

Es scheint, als wären die Pakete möglicherweise nicht in Ordnung und Docoder kann damit nicht umgehen. Ich bekomme viele der folgenden Fehler

pid = 100 pes_code = 0x1e0

nal_unit_type: 9, nal_ref_idc: 0

nal_unit_type: 1, nal_ref_idc: 2

deblocking_filter_idc 7 außerhalb des gültigen Bereichs

Fehler decode_slice_header

kein Rahmen!

Ich verwende die folgenden Schritte, um den Decoder einzurichten.

 //open input file, allocate context if ((ret = avformat_open_input(&format_ctx, in_filename, 0, 0)) < 0) { PyErr_SetString(ExtractorError, "Could not open input file!"); goto end; }  if ((ret = avformat_find_stream_info(format_ctx, 0)) < 0) { PyErr_SetString(ExtractorError, "Failed to retrieve input stream information!"); goto end; }  av_dump_format(format_ctx, 0, in_filename, 0);  // Get the video index from the stream for(int i=0; i<format_ctx->nb_streams ;i++ ) { if( format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ) { video_stream_index = i; break; } }  /* if video stream not availabe */ if((video_stream_index) == -1) { PyErr_SetString(ExtractorError, "video stream to retreive fps is not found!"); return NULL; }  long duration = format_ctx->duration + (format_ctx->duration <= INT64_MAX - 5000 ? 5000 : 0);  float duration_in_secs = (float)duration / AV_TIME_BASE;  stream_mapping_size = format_ctx->nb_streams; stream_mapping = av_mallocz_array(stream_mapping_size, sizeof(*stream_mapping)); if (!stream_mapping) { ret = AVERROR(ENOMEM); goto end; }  AVCodec *pCodec = NULL; AVCodecParameters *in_codecpar = NULL; for (i = 0; i < format_ctx->nb_streams; i++) { AVStream *in_stream = format_ctx->streams[i]; in_codecpar = in_stream->codecpar;  if (in_codecpar->codec_type != AVMEDIA_TYPE_AUDIO && in_codecpar->codec_type != AVMEDIA_TYPE_VIDEO && in_codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) { stream_mapping[i] = -1; continue; }  if (in_codecpar->codec_type == AVMEDIA_TYPE_VIDEO){ pCodec = avcodec_find_decoder(in_codecpar->codec_id); stream_mapping[i] = stream_index++; break; } }  if(!pCodec){ PyErr_SetString(ExtractorError, "error, no pCodec!"); return NULL; }  // convert CodecParam to CodecCtx AVCodecContext *pCodecCtx = avcodec_alloc_context3(pCodec); if (!pCodecCtx) { PyErr_SetString(ExtractorError, "Failed to convert codecParam to CodecCtx!"); return NULL; }  ret = avcodec_parameters_to_context(pCodecCtx, in_codecpar); if (ret < 0) goto end;  //open video decoder if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) { logging("EXTRACTOR: failed to open codec through avcodec_open2\n"); return NULL; } 

Um es zu testen, habe ich den folgenden Befehl von ffmpeg verwendet, um Frames aus demselben Video zu extrahieren, und es hat gut funktioniert.

ffmpeg -i ~ / thuuz / extractor / 03000.ts -f image2 -qscale: v 7 ffmpeg-detect -% 03d.jpg -hide_banner -v leise

Bin ich nicht die richtigen Codec-Params? Bitte lassen Sie mich einige Eingaben zum Debuggen dieses Problems wissen. Danke vielmals.

0

0 Antworten auf die Frage