Class for pushing MP4f files to the IIS Live Smooth Streaming snap-in
Exemple #1
0
        /// <summary>
        /// Read the supplied configuration and prepare the transformer for work.
        /// </summary>
        private void PrepareTransformer(EncoderConfiguration.Configuration Configuration, List <EncoderPackage> Packages)
        {
            Config = Configuration;
            TimeSpan TargetDuration = TimeSpan.FromSeconds(Config.EncoderSettings.FragmentSeconds);

            PublishPoint = Config.Upload.VideoDestinationRoot;
            if (String.IsNullOrEmpty(PublishPoint))
            {
                throw new ArgumentException("Publishing point must not be empty", "PublishUrl");
            }

            PushServer     = new IisSmoothPush(new Uri(PublishPoint));
            TrackDurations = new Dictionary <int, long>();
            TrackOffsets   = new Dictionary <int, long>();

            targetDuration = (ulong)TargetDuration.Ticks;
            Streams        = new MediaStream[Packages.Count];

            foreach (var pkg in Packages)
            {
                if (pkg.Specification.HasVideo && pkg.Specification.HasAudio)
                {
                    throw new NotSupportedException("IIS Smooth output doesn't support pre-muxed streams");
                }

                if (pkg.Specification.HasAudio)
                {
                    Streams[pkg.JobIndex]         = new MediaStream();         // for now, stream 0 is audio, and all others are video.
                    Streams[pkg.JobIndex].TrackId = pkg.JobIndex + 1;
                    Streams[pkg.JobIndex].FourCC  = "mp3a";                    // MP3
                    //Streams[pkg.JobIndex].FourCC = "mp4a"; // AAC
                    Streams[pkg.JobIndex].Height  = 0;
                    Streams[pkg.JobIndex].Width   = 0;
                    Streams[pkg.JobIndex].Bitrate = 96000;                     //pkg.Job.Bitrate; // later!
                }
                else if (pkg.Specification.HasVideo)
                {
                    Streams[pkg.JobIndex]         = new MediaStream();                   // for now, stream 0 is audio, and all others are video.
                    Streams[pkg.JobIndex].TrackId = pkg.JobIndex + 1;
                    Streams[pkg.JobIndex].FourCC  = "H264";                              // this is the M$ format, not iso (which is 'avc1')
                    Streams[pkg.JobIndex].Height  = Config.EncoderSettings.OutputHeight; // the actual size may be different due to scaling factor.
                    Streams[pkg.JobIndex].Width   = Config.EncoderSettings.OutputWidth;
                    Streams[pkg.JobIndex].Bitrate = pkg.Job.Bitrate;
                }
            }

            Mp4fFile = new FileRoot(Streams);
            Demuxer  = new MpegTS_Demux[Packages.Count];
            for (int di = 0; di < Demuxer.Length; di++)
            {
                Demuxer[di] = new MpegTS_Demux();
            }
        }
        /// <summary>
        /// Read the supplied configuration and prepare the transformer for work.
        /// </summary>
        private void PrepareTransformer(EncoderConfiguration.Configuration Configuration, List<EncoderPackage> Packages)
        {
            Config = Configuration;
            TimeSpan TargetDuration = TimeSpan.FromSeconds(Config.EncoderSettings.FragmentSeconds);

            PublishPoint = Config.Upload.VideoDestinationRoot;
            if (String.IsNullOrEmpty(PublishPoint)) throw new ArgumentException("Publishing point must not be empty", "PublishUrl");

            PushServer = new IisSmoothPush(new Uri(PublishPoint));
            TrackDurations = new Dictionary<int, long>();
            TrackOffsets = new Dictionary<int, long>();

            targetDuration = (ulong)TargetDuration.Ticks;
            Streams = new MediaStream[Packages.Count];

            foreach (var pkg in Packages) {
                if (pkg.Specification.HasVideo && pkg.Specification.HasAudio) {
                    throw new NotSupportedException("IIS Smooth output doesn't support pre-muxed streams");
                }

                if (pkg.Specification.HasAudio) {
                    Streams[pkg.JobIndex] = new MediaStream(); // for now, stream 0 is audio, and all others are video.
                    Streams[pkg.JobIndex].TrackId = pkg.JobIndex + 1;
                    Streams[pkg.JobIndex].FourCC = "mp3a"; // MP3
                    //Streams[pkg.JobIndex].FourCC = "mp4a"; // AAC
                    Streams[pkg.JobIndex].Height = 0;
                    Streams[pkg.JobIndex].Width = 0;
                    Streams[pkg.JobIndex].Bitrate = 96000; //pkg.Job.Bitrate; // later!
                } else if (pkg.Specification.HasVideo) {
                    Streams[pkg.JobIndex] = new MediaStream(); // for now, stream 0 is audio, and all others are video.
                    Streams[pkg.JobIndex].TrackId = pkg.JobIndex + 1;
                    Streams[pkg.JobIndex].FourCC = "H264"; // this is the M$ format, not iso (which is 'avc1')
                    Streams[pkg.JobIndex].Height = Config.EncoderSettings.OutputHeight; // the actual size may be different due to scaling factor.
                    Streams[pkg.JobIndex].Width = Config.EncoderSettings.OutputWidth;
                    Streams[pkg.JobIndex].Bitrate = pkg.Job.Bitrate;
                }
            }

            Mp4fFile = new FileRoot(Streams);
            Demuxer = new MpegTS_Demux[Packages.Count];
            for (int di = 0; di < Demuxer.Length; di++) {
                Demuxer[di] = new MpegTS_Demux();
            }
        }