double FFmpegVideoDecoder::getFramesPerSecond() const { #if defined(AVFORMAT_HAS_STREAM_GET_R_FRAME_RATE) return m_pFormatCtx ? av_q2d( av_stream_get_r_frame_rate( m_pFormatCtx->streams[ m_videoStream ] ) ) : 0.0; #else return m_pFormatCtx ? av_q2d( m_pFormatCtx->streams[ m_videoStream ]->r_frame_rate ) : 0.0; #endif }
static void ff_set_framerate(ffst *ff) { AVStream *av_stream; av_stream = ff->pFormatCtx->streams[ff->videoStream]; ff->framerate = 0; ff->tc.num = 0; ff->tc.den = 1; #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(55, 0, 100) // 9cf788eca8ba (merge a75f01d7e0) { AVRational fr = av_stream->r_frame_rate; if (fr.den > 0 && fr.num > 0) { ff->framerate = av_q2d (av_stream->r_frame_rate); ff->tc.num = fr.num; ff->tc.den = fr.den; } } #else { AVRational fr = av_stream_get_r_frame_rate (av_stream); if (fr.den > 0 && fr.num > 0) { ff->framerate = av_q2d (fr); ff->tc.num = fr.num; ff->tc.den = fr.den; } } #endif if (ff->framerate < 1 || ff->framerate > 1000) { AVRational fr = av_stream->avg_frame_rate; if (fr.den > 0 && fr.num > 0) { ff->framerate = av_q2d (fr); ff->tc.num = fr.num; ff->tc.den = fr.den; } } if (ff->framerate < 1 || ff->framerate > 1000) { AVRational fr = av_stream->time_base; if (fr.den > 0 && fr.num > 0) { ff->framerate = 1.0 / av_q2d (fr); ff->tc.num = fr.den; ff->tc.den = fr.num; } } if (ff->framerate < 1 || ff->framerate > 1000) { if (!want_quiet) fprintf(stderr, "WARNING: cannot determine video-frame rate, using 25fps.\n"); ff->framerate = 25; ff->tc.num = 25; ff->tc.den = 1; } ff->tc.drop = 0; if (floor(ff->framerate * 100.0) == 2997) ff->tc.drop = 1; }