MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ extract_stream_metadata()

void MayaFlux::IO::VideoStreamContext::extract_stream_metadata ( const FFmpegDemuxContext demux,
FileMetadata out 
) const

Populate stream-specific fields into an existing FileMetadata.

Appends codec name, pixel format, dimensions, frame rate, bit_rate, etc.

Parameters
demuxThe demux context that owns the format_context.
outMetadata struct to append into.

Definition at line 397 of file VideoStreamContext.cpp.

399{
400 if (!codec_context || stream_index < 0)
401 return;
402
403 out.attributes["video_codec"] = std::string(avcodec_get_name(codec_context->codec_id));
404 if (codec_context->codec && codec_context->codec->long_name)
405 out.attributes["video_codec_long_name"] = std::string(codec_context->codec->long_name);
406 out.attributes["video_width"] = width;
407 out.attributes["video_height"] = height;
408 out.attributes["video_frame_rate"] = frame_rate;
409 out.attributes["video_total_frames"] = total_frames;
410 out.attributes["video_bit_rate"] = codec_context->bit_rate;
411
412 const char* pix_fmt_name = av_get_pix_fmt_name(codec_context->pix_fmt);
413 if (pix_fmt_name)
414 out.attributes["video_pixel_format"] = std::string(pix_fmt_name);
415
416 if (codec_context->color_range != AVCOL_RANGE_UNSPECIFIED)
417 out.attributes["video_color_range"] = static_cast<int>(codec_context->color_range);
418 if (codec_context->colorspace != AVCOL_SPC_UNSPECIFIED)
419 out.attributes["video_colorspace"] = static_cast<int>(codec_context->colorspace);
420 if (codec_context->color_trc != AVCOL_TRC_UNSPECIFIED)
421 out.attributes["video_color_trc"] = static_cast<int>(codec_context->color_trc);
422 if (codec_context->color_primaries != AVCOL_PRI_UNSPECIFIED)
423 out.attributes["video_color_primaries"] = static_cast<int>(codec_context->color_primaries);
424
425 AVStream* stream = demux.get_stream(stream_index);
426 if (!stream)
427 return;
428
429 if (stream->sample_aspect_ratio.num > 0 && stream->sample_aspect_ratio.den > 0) {
430 out.attributes["video_sar_num"] = stream->sample_aspect_ratio.num;
431 out.attributes["video_sar_den"] = stream->sample_aspect_ratio.den;
432 }
433
434 AVDictionaryEntry* tag = nullptr;
435 while ((tag = av_dict_get(stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX)))
436 out.attributes[std::string("video_stream_") + tag->key] = std::string(tag->value);
437}
Core::GlobalStreamInfo stream
Definition Config.cpp:36
double frame_rate
Average frame rate (fps).
uint32_t height
Source height in pixels.
uint32_t width
Source width in pixels.
AVCodecContext * codec_context
Owned; freed in destructor.

References MayaFlux::IO::FileMetadata::attributes, codec_context, frame_rate, MayaFlux::IO::FFmpegDemuxContext::get_stream(), height, stream, stream_index, total_frames, and width.

+ Here is the call graph for this function: