X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ffmpeg_capture.cpp;h=6e672d9d837e1ec6145dda12abc4dcd27eb22b1a;hb=ad62963eb4dc6407698e8569ae175f6d43c9b018;hp=464b4cb92d292b8b6bb80f458c92715209f6e902;hpb=73ddb883aaf76a76d8c03730e587ac396255c0c9;p=nageru diff --git a/ffmpeg_capture.cpp b/ffmpeg_capture.cpp index 464b4cb..6e672d9 100644 --- a/ffmpeg_capture.cpp +++ b/ffmpeg_capture.cpp @@ -28,6 +28,7 @@ extern "C" { #include "bmusb/bmusb.h" #include "ffmpeg_raii.h" +#include "ffmpeg_util.h" #include "flags.h" #include "image_input.h" @@ -179,25 +180,14 @@ bool FFmpegCapture::play_video(const string &pathname) return false; } - int video_stream_index = -1, audio_stream_index = -1; - AVRational video_timebase{ 1, 1 }; - for (unsigned i = 0; i < format_ctx->nb_streams; ++i) { - if (format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && - video_stream_index == -1) { - video_stream_index = i; - video_timebase = format_ctx->streams[i]->time_base; - } - if (format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && - audio_stream_index == -1) { - audio_stream_index = i; - } - } + int video_stream_index = find_stream_index(format_ctx.get(), AVMEDIA_TYPE_VIDEO); if (video_stream_index == -1) { fprintf(stderr, "%s: No video stream found\n", pathname.c_str()); return false; } const AVCodecParameters *codecpar = format_ctx->streams[video_stream_index]->codecpar; + AVRational video_timebase = format_ctx->streams[video_stream_index]->time_base; AVCodecContextWithDeleter codec_ctx = avcodec_alloc_context3_unique(nullptr); if (avcodec_parameters_to_context(codec_ctx.get(), codecpar) < 0) { fprintf(stderr, "%s: Cannot fill codec parameters\n", pathname.c_str());