Библиотека FFmpeg удаляет кадр в видео mp4, используя фильтр 'fps' или 'framerate' - PullRequest
0 голосов
/ 28 июня 2019

После декодирования / кодирования оригинального видео mp4 с fps 25 я получил видео с fps 25 bui, если я установил видеофильтр fps = fps = 25, тогда последний кадр пропал, и я получил следующий результат (AV_LOG_TRACE):

...
[Parsed_fps_0 @ 0x7f8f2c735f80] fps=25/1
[Parsed_fps_0 @ 0x7f8f2c735f80] Read frame with in pts 1024, out pts 2
[Parsed_fps_0 @ 0x7f8f2c735f80] Read frame with in pts 1536, out pts 3
[Parsed_fps_0 @ 0x7f8f2c735f80] Set first pts to 2
[Parsed_fps_0 @ 0x7f8f2c735f80] Writing frame with pts 2 to pts 2
[Parsed_fps_0 @ 0x7f8f2c735f80] Read frame with in pts 2048, out pts 4
[Parsed_fps_0 @ 0x7f8f2c735f80] Writing frame with pts 3 to pts 3
[Parsed_fps_0 @ 0x7f8f2c735f80] Read frame with in pts 2560, out pts 5
[Parsed_fps_0 @ 0x7f8f2c735f80] Writing frame with pts 4 to pts 4
...
[Parsed_fps_0 @ 0x7f8f2c735f80] Read frame with in pts 90624, out pts 177
[Parsed_fps_0 @ 0x7f8f2c735f80] Writing frame with pts 176 to pts 176
[Parsed_fps_0 @ 0x7f8f2c735f80] Read frame with in pts 91136, out pts 178
[Parsed_fps_0 @ 0x7f8f2c735f80] Writing frame with pts 177 to pts 177
[Parsed_fps_0 @ 0x7f8f2c735f80] Dropping frame with pts 178
[Parsed_fps_0 @ 0x7f8f2c735f80] 177 frames in, 176 frames out; 1 frames dropped, 0 frames duplicated.

Я пытался установить параметры ввода / вывода, подобные этим:

//input
av_dict_set(&options, "r", "25", 0); //doesn't help
avformat_open_input(&pFormatContext, NULL, NULL, &options);
//input video graph filter fps
...
// encoder
AVOutputFormat* pOutputFormat = av_guess_format("mp4", NULL, NULL);
AVFormatContext* pFormatContext = avformat_alloc_context();
pFormatContext->oformat = pOutputFormat;
AVStream* pVideoStream = avformat_new_stream(m_pFormatContext, NULL);

AVCodec* pCodec = avcodec_find_encoder_by_name("libx264");
AVCodecContext* pCodecContext = avcodec_alloc_context3(pCodec);
pCodecContext->codec_id = pOutputFormat->video_codec;
pCodecContext->codec_type = AVMEDIA_TYPE_VIDEO;
pCodecContext->level = 51;
pCodecContext->width = 800;
pCodecContext->height = 600;
pCodecContext->time_base = (AVRational) {1, 25};
pCodecContext->framerate = av_inv_q(pCodecContext->time_base);
pCodecContext->gop_size = 12;
pCodecContext->max_b_frames = 1;
pCodecContext->qcompress = 1.0f;
pCodecContext->pix_fmt = AV_PIX_FMT_YUV420P;
//...
av_opt_set(pCodecContext->priv_data, "x264opts", "fps=25", 0); //doesn't help

pVideoStream->time_base = pCodecContext->time_base;
pVideoStream->avg_frame_rate = pCodecContext->framerate; //doesn't help
// output
av_dict_set(&options, "r", "25", 0); //doesn't help
avformat_write_header(m_pFormatContext, &options);
// flush decoder
// flush filterbuffer and encoder
av_write_trailer(pFormatContext);

Я ожидал получить видео со значением 25 без пропуска кадров.

...