Ejemplo n.º 1
0
        /// <summary>
        /// Gets the media info.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        public Task<MediaInfo> GetMediaInfo(MediaInfoRequest request, CancellationToken cancellationToken)
        {
            var extractChapters = request.MediaType == DlnaProfileType.Video && request.ExtractChapters;

            var inputFiles = MediaEncoderHelpers.GetInputArgument(FileSystem, request.InputPath, request.Protocol, request.MountedIso, request.PlayableStreamFileNames);

            var probeSize = EncodingUtils.GetProbeSizeArgument(inputFiles.Length);
            string analyzeDuration;

            if (request.AnalyzeDurationSections > 0)
            {
                analyzeDuration = "-analyzeduration " +
                                  (request.AnalyzeDurationSections*1000000).ToString(CultureInfo.InvariantCulture);
            }
            else
            {
                analyzeDuration = EncodingUtils.GetAnalyzeDurationArgument(inputFiles.Length);
            }

            probeSize = probeSize + " " + analyzeDuration;
            probeSize = probeSize.Trim();

            return GetMediaInfoInternal(GetInputArgument(inputFiles, request.Protocol), request.InputPath, request.Protocol, extractChapters,
                probeSize, request.MediaType == DlnaProfileType.Audio, request.VideoType, cancellationToken);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the media info.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        public Task<Model.MediaInfo.MediaInfo> GetMediaInfo(MediaInfoRequest request, CancellationToken cancellationToken)
        {
            var extractChapters = request.MediaType == DlnaProfileType.Video && request.ExtractChapters;

            var inputFiles = MediaEncoderHelpers.GetInputArgument(FileSystem, request.InputPath, request.Protocol, request.MountedIso, request.PlayableStreamFileNames);

            return GetMediaInfoInternal(GetInputArgument(inputFiles, request.Protocol), request.InputPath, request.Protocol, extractChapters,
                GetProbeSizeArgument(inputFiles, request.Protocol), request.MediaType == DlnaProfileType.Audio, request.VideoType, cancellationToken);
        }
        public async Task ProbeStream(MediaSourceInfo mediaSourceInfo, string probeUrl, string source, CancellationToken cancellationToken)
        {

            _logger.Info("[TVHclient] Probe stream for {0}", source);
            _logger.Info("[TVHclient] Probe URL: {0}", probeUrl);
            
            MediaInfoRequest req = new MediaInfoRequest

            {

                MediaType = MediaBrowser.Model.Dlna.DlnaProfileType.Video,

                InputPath = probeUrl,

                Protocol = MediaProtocol.Http,

                ExtractChapters = false,

                VideoType = VideoType.VideoFile,

            };



            var originalRuntime = mediaSourceInfo.RunTimeTicks;

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            MediaInfo info = await _mediaEncoder.GetMediaInfo(req, cancellationToken).ConfigureAwait(false);

            stopWatch.Stop();

            TimeSpan ts = stopWatch.Elapsed;

            string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);

            _logger.Info("[TVHclient] Probe RunTime " + elapsedTime);



            if (info != null)
            {

                mediaSourceInfo.Bitrate = info.Bitrate;

                mediaSourceInfo.Container = info.Container;

                mediaSourceInfo.Formats = info.Formats;

                mediaSourceInfo.MediaStreams = info.MediaStreams;

                mediaSourceInfo.RunTimeTicks = info.RunTimeTicks;

                mediaSourceInfo.Size = info.Size;

                mediaSourceInfo.Timestamp = info.Timestamp;

                mediaSourceInfo.Video3DFormat = info.Video3DFormat;

                mediaSourceInfo.VideoType = info.VideoType;

                mediaSourceInfo.RequiresClosing = true;

                mediaSourceInfo.RequiresOpening = true;

                mediaSourceInfo.SupportsDirectPlay = true;

                mediaSourceInfo.SupportsDirectStream = true;

                mediaSourceInfo.SupportsTranscoding = true;





                mediaSourceInfo.DefaultSubtitleStreamIndex = null;



                if (!originalRuntime.HasValue)
                {

                    mediaSourceInfo.RunTimeTicks = null;

                }

                var audioStream = mediaSourceInfo.MediaStreams.FirstOrDefault(i => i.Type == MediaBrowser.Model.Entities.MediaStreamType.Audio);



                if (audioStream == null || audioStream.Index == -1)
                {

                    mediaSourceInfo.DefaultAudioStreamIndex = null;

                }

                else
                {

                    mediaSourceInfo.DefaultAudioStreamIndex = audioStream.Index;

                }

            }

            else
            {

                _logger.Error("[TVHclient] Cannot probe {0} stream", source);

            }

        }