MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / ffmpeg_open

Function ffmpeg_open

libhb/stream.c:5253–5359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5251// Support for reading media files via the ffmpeg libraries.
5252
5253static int ffmpeg_open( hb_stream_t *stream, hb_title_t *title, int scan )
5254{
5255 AVFormatContext *info_ic = NULL;
5256
5257 av_log_set_level( AV_LOG_ERROR );
5258
5259 // Increase probe buffer size
5260 // The default (5MB) is not big enough to successfully scan
5261 // some files with large PNGs
5262 AVDictionary * av_opts = NULL;
5263 av_dict_set( &av_opts, "probesize", "15000000", 0 );
5264
5265 // FFMpeg has issues with seeking. After av_find_stream_info, the
5266 // streams are left in an indeterminate position. So a seek is
5267 // necessary to force things back to the beginning of the stream.
5268 // But then the seek fails for some stream types. So the safest thing
5269 // to do seems to be to open 2 AVFormatContext. One for probing info
5270 // and the other for reading.
5271 if ( avformat_open_input( &info_ic, stream->path, NULL, &av_opts ) < 0 )
5272 {
5273 av_dict_free( &av_opts );
5274 return 0;
5275 }
5276 // libav populates av_opts with the things it didn't recognize.
5277 AVDictionaryEntry *t = NULL;
5278 while ((t = av_dict_get(av_opts, "", t, AV_DICT_IGNORE_SUFFIX)) != NULL)
5279 {
5280 hb_log("ffmpeg_open: unknown option '%s'", t->key);
5281 }
5282 av_dict_free( &av_opts );
5283
5284 if (title->color_prim == HB_COLR_PRI_UNSET &&
5285 title->color_transfer == HB_COLR_TRA_UNSET &&
5286 title->color_matrix == HB_COLR_MAT_UNSET)
5287 {
5288 // Read the video track color info
5289 // before it's overwritten with the stream info
5290 // in avformat_find_stream_info
5291 for (int i = 0; i < info_ic->nb_streams; ++i)
5292 {
5293 AVStream *st = info_ic->streams[i];
5294
5295 if ( st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
5296 !(st->disposition & AV_DISPOSITION_ATTACHED_PIC) &&
5297 avcodec_find_decoder(st->codecpar->codec_id))
5298 {
5299 AVCodecParameters *codecpar = st->codecpar;
5300 title->color_prim = codecpar->color_primaries;
5301 title->color_transfer = codecpar->color_trc;
5302 title->color_matrix = codecpar->color_space;
5303 title->color_range = codecpar->color_range;
5304 break;
5305 }
5306 }
5307 }
5308
5309 if ( avformat_find_stream_info( info_ic, NULL ) < 0 )
5310 goto fail;

Callers 1

hb_stream_openFunction · 0.85

Calls 2

hb_logFunction · 0.85
hb_errorFunction · 0.85

Tested by

no test coverage detected