MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / open_input_file

Function open_input_file

doc/examples/qsv_transcode.c:133–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133static int open_input_file(char *filename)
134{
135 int ret;
136 const AVCodec *decoder = NULL;
137 AVStream *video = NULL;
138
139 if ((ret = avformat_open_input(&ifmt_ctx, filename, NULL, NULL)) < 0) {
140 fprintf(stderr, "Cannot open input file '%s', Error code: %s\n",
141 filename, av_err2str(ret));
142 return ret;
143 }
144
145 if ((ret = avformat_find_stream_info(ifmt_ctx, NULL)) < 0) {
146 fprintf(stderr, "Cannot find input stream information. Error code: %s\n",
147 av_err2str(ret));
148 return ret;
149 }
150
151 ret = av_find_best_stream(ifmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
152 if (ret < 0) {
153 fprintf(stderr, "Cannot find a video stream in the input file. "
154 "Error code: %s\n", av_err2str(ret));
155 return ret;
156 }
157 video_stream = ret;
158 video = ifmt_ctx->streams[video_stream];
159
160 switch(video->codecpar->codec_id) {
161 case AV_CODEC_ID_H264:
162 decoder = avcodec_find_decoder_by_name("h264_qsv");
163 break;
164 case AV_CODEC_ID_HEVC:
165 decoder = avcodec_find_decoder_by_name("hevc_qsv");
166 break;
167 case AV_CODEC_ID_VP9:
168 decoder = avcodec_find_decoder_by_name("vp9_qsv");
169 break;
170 case AV_CODEC_ID_VP8:
171 decoder = avcodec_find_decoder_by_name("vp8_qsv");
172 break;
173 case AV_CODEC_ID_AV1:
174 decoder = avcodec_find_decoder_by_name("av1_qsv");
175 break;
176 case AV_CODEC_ID_MPEG2VIDEO:
177 decoder = avcodec_find_decoder_by_name("mpeg2_qsv");
178 break;
179 case AV_CODEC_ID_MJPEG:
180 decoder = avcodec_find_decoder_by_name("mjpeg_qsv");
181 break;
182 default:
183 fprintf(stderr, "Codec is not supported by qsv\n");
184 return AVERROR(EINVAL);
185 }
186
187 if (!(decoder_ctx = avcodec_alloc_context3(decoder)))
188 return AVERROR(ENOMEM);
189
190 if ((ret = avcodec_parameters_to_context(decoder_ctx, video->codecpar)) < 0) {

Callers 1

mainFunction · 0.70

Calls 9

avformat_open_inputFunction · 0.85
av_find_best_streamFunction · 0.85
avcodec_alloc_context3Function · 0.85
av_guess_frame_rateFunction · 0.85
av_buffer_refFunction · 0.85
avcodec_open2Function · 0.85

Tested by

no test coverage detected