dacal
dacal

Reputation: 95

How to set codec in avformat_open_input() function?

Part of my command looks like this:

ffmpeg -hide_banner -f avfoundation -framerate 30 -video_size 3840x2160 -c:v <some codec> -pix_fmt <some pixel format> -i "0" ...

My code in which I'm trying to replicate this part of command using avlib looks like this:

AVDictionary* options = nullptr;
av_dict_set(&options, "framerate", "30", 0);
av_dict_set(&options, "video_size", "3840x2160", 0);
av_dict_set(&options, "pixel_format", <some pixel format>, 0);
av_dict_set(&options, "vcodec", <some codec>, 0);
int err = avformat_open_input(&ctx->formatContext, id.c_str(), iformat, &options);

All options are accepted except "vcodec".

Is it even possible to specify codec like this? If it is which option should I use?

I also need to mention that if I use "pix_fmt" in place of "pixel_format" that option is also unrecognised, so I tried with different names like: "v:c", "videocodec"... but nothing works and I also can't find anything in ffmpeg docs and source code.

Upvotes: 0

Views: 1027

Answers (1)

aergistal
aergistal

Reputation: 31229

vcodec is an argument used exclusively by the ffmpeg binary and it's not an input format option.

You must use avcodec_find_decoder() or avcodec_find_decoder_by_name() to select the codec.

Check-out the demuxing/decoding example, which is too large to reproduce here: https://ffmpeg.org/doxygen/trunk/demuxing_decoding_8c-example.html

Upvotes: 1

Related Questions