From 95369097a57de7f11fb472ecfaef577bf1f00c8e Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Wed, 17 Jul 2024 14:57:54 +0530 Subject: [PATCH] Merge metadata streams --- mobile/lib/models/ffmpeg/ffprobe_props.dart | 32 +++++++++++++++++++-- mobile/lib/utils/ffprobe_util.dart | 2 +- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/mobile/lib/models/ffmpeg/ffprobe_props.dart b/mobile/lib/models/ffmpeg/ffprobe_props.dart index a7c0dbd872..027d0377ee 100644 --- a/mobile/lib/models/ffmpeg/ffprobe_props.dart +++ b/mobile/lib/models/ffmpeg/ffprobe_props.dart @@ -14,7 +14,7 @@ import "package:photos/models/location/location.dart"; class FFProbeProps { Map? prodData; Location? location; - DateTime? creationTime; + DateTime? creationTimeUTC; String? bitrate; String? majorBrand; String? fps; @@ -45,7 +45,7 @@ class FFProbeProps { return buffer.toString(); } - static fromJson(Map? json) { + static parseData(Map? json) { final Map parsedData = {}; final FFProbeProps result = FFProbeProps(); @@ -76,6 +76,7 @@ class FFProbeProps { break; case FFProbeKeys.creationTime: parsedData[stringKey] = _formatDate(json[key] ?? ""); + result.creationTimeUTC = _getUTCDateTime(json[key] ?? ""); break; case FFProbeKeys.durationMicros: parsedData[stringKey] = formatPreciseDuration( @@ -112,7 +113,20 @@ class FFProbeProps { } // iterate through the streams final List streams = json["streams"]; + final List newStreams = []; + final Map metadata = {}; for (final stream in streams) { + if (stream['type'] == 'metadata') { + for (final key in stream.keys) { + if (key == FFProbeKeys.frameCount && stream[key]?.toString() == "1") { + continue; + } + metadata[key] = stream[key]; + } + metadata.remove(FFProbeKeys.index); + } else { + newStreams.add(stream); + } for (final key in stream.keys) { if (key == FFProbeKeys.rFrameRate) { result.fps = _formatFPS(stream[key]); @@ -126,6 +140,10 @@ class FFProbeProps { } } } + if (metadata.isNotEmpty) { + newStreams.add(metadata); + } + parsedData["streams"] = newStreams; result.prodData = parsedData; return result; } @@ -171,6 +189,16 @@ class FFProbeProps { return formatDateTime(newDate, 'en_US', false); } + static DateTime? _getUTCDateTime(String value) { + final dateInUtc = DateTime.tryParse(value); + if (dateInUtc == null) return null; + final epoch = DateTime.fromMillisecondsSinceEpoch(0, isUtc: true); + if (dateInUtc == epoch) return null; + return DateTime.fromMicrosecondsSinceEpoch( + dateInUtc.microsecondsSinceEpoch, + ); + } + // input example: '00:00:05.408000000' or '5.408000' static Duration? _parseDuration(String? value) { if (value == null) return null; diff --git a/mobile/lib/utils/ffprobe_util.dart b/mobile/lib/utils/ffprobe_util.dart index 289bf5962b..6da87d8fd6 100644 --- a/mobile/lib/utils/ffprobe_util.dart +++ b/mobile/lib/utils/ffprobe_util.dart @@ -17,7 +17,7 @@ class FFProbeUtil { final properties = await getMetadata(mediaInformation); try { - return FFProbeProps.fromJson(properties); + return FFProbeProps.parseData(properties); } catch (e, stackTrace) { _logger.severe( "Error parsing FFProbe properties: $properties",