protected void updateSourceMedia(SourceMedia sourceMedia, Android.Net.Uri uri)
        {
            sourceMedia.uri = uri;
            sourceMedia.size = TranscoderUtils.GetSize(this, uri);
            sourceMedia.duration = getMediaDuration(uri) / 1000f;

            try
            {
                MediaExtractor mediaExtractor = new MediaExtractor();
                mediaExtractor.SetDataSource(this, uri, null);
                sourceMedia.tracks = new List<MediaTrackFormat>(mediaExtractor.TrackCount);

                for (int track = 0; track < mediaExtractor.TrackCount; track++)
                {
                    MediaFormat mediaFormat = mediaExtractor.GetTrackFormat(track);
                    var mimeType = mediaFormat.GetString(MediaFormat.KeyMime);
                    if (mimeType == null)
                    {
                        continue;
                    }

                    if (mimeType.StartsWith("video"))
                    {
                        VideoTrackFormat videoTrack = new VideoTrackFormat(track, mimeType);
                        videoTrack.width = getInt(mediaFormat, MediaFormat.KeyWidth);
                        videoTrack.height = getInt(mediaFormat, MediaFormat.KeyHeight);
                        videoTrack.duration = getLong(mediaFormat, MediaFormat.KeyDuration);
                        videoTrack.frameRate = MediaFormatUtils.GetFrameRate(mediaFormat, new Java.Lang.Integer(-1)).IntValue();
                        videoTrack.keyFrameInterval = MediaFormatUtils.GetIFrameInterval(mediaFormat, new Java.Lang.Integer(-1)).IntValue();
                        videoTrack.rotation = getInt(mediaFormat, TrackMetadataUtil.KEY_ROTATION, 0);
                        videoTrack.bitrate = getInt(mediaFormat, MediaFormat.KeyBitRate);
                        sourceMedia.tracks.Add(videoTrack);
                    }
                    else if (mimeType.StartsWith("audio"))
                    {
                        AudioTrackFormat audioTrack = new AudioTrackFormat(track, mimeType);
                        audioTrack.channelCount = getInt(mediaFormat, MediaFormat.KeyChannelCount);
                        audioTrack.samplingRate = getInt(mediaFormat, MediaFormat.KeySampleRate);
                        audioTrack.duration = getLong(mediaFormat, MediaFormat.KeyDuration);
                        audioTrack.bitrate = getInt(mediaFormat, MediaFormat.KeyBitRate);
                        sourceMedia.tracks.Add(audioTrack);
                    }
                    else
                    {
                        sourceMedia.tracks.Add(new GenericTrackFormat(track, mimeType));
                    }
                }
            }
            catch (IOException ex)
            {
                System.Diagnostics.Debug.WriteLine($"Failed to extract sourceMedia: {ex.Message}");
            }

            sourceMedia.NotifyChange();
        }
Beispiel #2
0
        private static String printVideoMetadata(Context context, MediaFormat mediaFormat)
        {
            if (mediaFormat == null)
            {
                return("\n");
            }
            StringBuilder stringBuilder = new StringBuilder();

            if (mediaFormat.ContainsKey(MediaFormat.KeyMime))
            {
                stringBuilder.AppendLine(context.GetString(Resource.String.stats_mime_type, mediaFormat.GetString(MediaFormat.KeyMime)));
            }
            if (mediaFormat.ContainsKey(MediaFormat.KeyWidth))
            {
                stringBuilder.AppendLine(context.GetString(Resource.String.stats_width, mediaFormat.GetInteger(MediaFormat.KeyWidth)));
            }
            if (mediaFormat.ContainsKey(MediaFormat.KeyHeight))
            {
                stringBuilder.AppendLine(context.GetString(Resource.String.stats_height, mediaFormat.GetInteger(MediaFormat.KeyHeight)));
            }
            if (mediaFormat.ContainsKey(MediaFormat.KeyBitRate))
            {
                stringBuilder.AppendLine(context.GetString(Resource.String.stats_bitrate, mediaFormat.GetInteger(MediaFormat.KeyBitRate)));
            }
            if (mediaFormat.ContainsKey(MediaFormat.KeyDuration))
            {
                stringBuilder.AppendLine(context.GetString(Resource.String.stats_duration, mediaFormat.GetLong(MediaFormat.KeyDuration)));
            }
            if (mediaFormat.ContainsKey(MediaFormat.KeyFrameRate))
            {
                stringBuilder.AppendLine(context.GetString(Resource.String.stats_frame_rate, MediaFormatUtils.GetFrameRate(mediaFormat, new Java.Lang.Integer(0)).IntValue()));
            }
            if (mediaFormat.ContainsKey(MediaFormat.KeyIFrameInterval))
            {
                stringBuilder.AppendLine(context.GetString(Resource.String.stats_key_frame_interval, MediaFormatUtils.GetIFrameInterval(mediaFormat, new Java.Lang.Integer(0)).IntValue()));
            }
            if (mediaFormat.ContainsKey(KEY_ROTATION))
            {
                stringBuilder.AppendLine(context.GetString(Resource.String.stats_rotation, mediaFormat.GetInteger(KEY_ROTATION)));
            }
            return(stringBuilder.ToString());
        }