diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index 9b1f1ea6..c42cc386 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -559,44 +559,43 @@ void FFmpegReader::Open() { AVStream* st = pFormatCtx->streams[i]; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { // Only inspect the first video stream - for (AVPacketSideDataType type = AV_PKT_DATA_PARAM_CHANGE; - type < AV_PKT_DATA_NB; - type = static_cast(type + 1)) { - - size_t size = 0; - uint8_t *data = av_stream_get_side_data(st, type, &size); - - if (!data || size == 0) - continue; - - // Handle rotation metadata - if (type == AV_PKT_DATA_DISPLAYMATRIX && - size >= 9 * sizeof(int32_t) && - !info.metadata.count("rotate")) { + for (int j = 0; j < st->nb_side_data; j++) { + AVPacketSideData *sd = &st->side_data[j]; + // Handle rotation metadata (unchanged) + if (sd->type == AV_PKT_DATA_DISPLAYMATRIX && + sd->size >= 9 * sizeof(int32_t) && + !info.metadata.count("rotate")) + { double rotation = -av_display_rotation_get( - reinterpret_cast(data)); + reinterpret_cast(sd->data)); if (std::isnan(rotation)) rotation = 0; info.metadata["rotate"] = std::to_string(rotation); - } + } // Handle spherical video metadata - else if (type == AV_PKT_DATA_SPHERICAL) { + else if (sd->type == AV_PKT_DATA_SPHERICAL) { + // Always mark as spherical info.metadata["spherical"] = "1"; + // Cast the raw bytes to an AVSphericalMapping const AVSphericalMapping* map = - reinterpret_cast(data); + reinterpret_cast(sd->data); + // Projection enum → string const char* proj_name = av_spherical_projection_name(map->projection); - info.metadata["spherical_projection"] = proj_name ? proj_name : "unknown"; + info.metadata["spherical_projection"] = proj_name + ? proj_name + : "unknown"; - auto to_deg = [](int32_t v) { - return static_cast(v) / 65536.0; + // Convert 16.16 fixed-point to float degrees + auto to_deg = [](int32_t v){ + return (double)v / 65536.0; }; info.metadata["spherical_yaw"] = std::to_string(to_deg(map->yaw)); info.metadata["spherical_pitch"] = std::to_string(to_deg(map->pitch)); info.metadata["spherical_roll"] = std::to_string(to_deg(map->roll)); } - } + } break; } }