MayaFlux 0.2.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 392 of file VideoStreamContext.cpp.

394{
395 if (!codec_context || stream_index < 0)
396 return;
397
398 out.attributes["video_codec"] = std::string(avcodec_get_name(codec_context->codec_id));
399 if (codec_context->codec && codec_context->codec->long_name)
400 out.attributes["video_codec_long_name"] = std::string(codec_context->codec->long_name);
401 out.attributes["video_width"] = width;
402 out.attributes["video_height"] = height;
403 out.attributes["video_frame_rate"] = frame_rate;
404 out.attributes["video_total_frames"] = total_frames;
405 out.attributes["video_bit_rate"] = codec_context->bit_rate;
406
407 const char* pix_fmt_name = av_get_pix_fmt_name(codec_context->pix_fmt);
408 if (pix_fmt_name)
409 out.attributes["video_pixel_format"] = std::string(pix_fmt_name);
410
411 if (codec_context->color_range != AVCOL_RANGE_UNSPECIFIED)
412 out.attributes["video_color_range"] = static_cast<int>(codec_context->color_range);
413 if (codec_context->colorspace != AVCOL_SPC_UNSPECIFIED)
414 out.attributes["video_colorspace"] = static_cast<int>(codec_context->colorspace);
415 if (codec_context->color_trc != AVCOL_TRC_UNSPECIFIED)
416 out.attributes["video_color_trc"] = static_cast<int>(codec_context->color_trc);
417 if (codec_context->color_primaries != AVCOL_PRI_UNSPECIFIED)
418 out.attributes["video_color_primaries"] = static_cast<int>(codec_context->color_primaries);
419
420 AVStream* stream = demux.get_stream(stream_index);
421 if (!stream)
422 return;
423
424 if (stream->sample_aspect_ratio.num > 0 && stream->sample_aspect_ratio.den > 0) {
425 out.attributes["video_sar_num"] = stream->sample_aspect_ratio.num;
426 out.attributes["video_sar_den"] = stream->sample_aspect_ratio.den;
427 }
428
429 AVDictionaryEntry* tag = nullptr;
430 while ((tag = av_dict_get(stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX)))
431 out.attributes[std::string("video_stream_") + tag->key] = std::string(tag->value);
432}
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_index, total_frames, and width.

+ Here is the call graph for this function: