Ejemplo n.º 1
0
        /// <summary>
        /// Starts the processing.
        /// </summary>
        void StartProcessing()
        {
            movie = new Movie();
            movie.sourceStream = File.OpenRead(srcPath);

            dstStream = File.OpenWrite(dstPath);
            remux     = new AviRemux();

            // create and initialize demux for the source data
            movie.demux = Demux.forSource(movie.sourceStream);
            movie.demux.Init(movie.sourceStream);

            // create video stream and decoder too. without a decoder we can't access pixels to compare
            if (!movie.demux.hasVideo)
            {
                throw new MpException("Remux needs video stream inside an AVI");
            }
            movie.videoDecoder = VideoDecoder.CreateFor(movie.demux.videoStreamInfo);
            movie.videoDecoder.Init(out framebuffer, movie.demux);

            // create a remux. this will write into dstStream
            bool outputHasAudio = movie.demux.hasAudio && !discardAudio;

            remux.Init(dstStream, movie.demux.videoStreamInfo, outputHasAudio ? movie.demux.audioStreamInfo : null);

            // create a duplicate finder. most of the options control how the frames are actually compared
            options.otherStreamsAvailable = outputHasAudio;
            dupFinder = new DuplicateFrameFinder(movie.videoDecoder, framebuffer, 0, movie.demux.videoStreamInfo.frameCount, options);

            // if we want a to log the duplicate indexes into a file, then clear the file first
            if (!string.IsNullOrEmpty(logDuplicatesPath))
            {
                File.WriteAllText(logDuplicatesPath, "# Duplicate frame index for " + srcPath + "\n");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Extracts raw audio from the movie.
        /// Usable only for reasonable sized streams, because byte[] is returned.
        /// </summary>
        /// <returns>The raw audio</returns>
        /// <param name="src">File contents</param>
        /// <param name="demuxUsed">Demux used</param>
        public static byte[] ExtractRawAudio(Stream sourceStream, out Demux demux)
        {
            demux = Demux.forSource (sourceStream);
            demux.Init (sourceStream);
            if (!demux.hasAudio)
                return null;

            byte[] bigBuf = new byte[demux.audioStreamInfo.lengthBytes];
            demux.ReadAudioSamples (out bigBuf, demux.audioStreamInfo.sampleCount);
            return bigBuf;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Extracts raw audio from the movie.
        /// Usable only for reasonable sized streams, because byte[] is returned.
        /// </summary>
        /// <returns>The raw audio</returns>
        /// <param name="src">File contents</param>
        /// <param name="demuxUsed">Demux used</param>
        public static byte[] ExtractRawAudio(Stream sourceStream, out Demux demux)
        {
            demux = Demux.forSource(sourceStream);
            demux.Init(sourceStream);
            if (!demux.hasAudio)
            {
                return(null);
            }

            byte[] bigBuf = new byte[demux.audioStreamInfo.lengthBytes];
            demux.ReadAudioSamples(out bigBuf, demux.audioStreamInfo.sampleCount);
            return(bigBuf);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Extracts raw video from the movie.
        /// Usable only for reasonable sized streams, because byte[] is returned.
        /// </summary>
        /// <returns>The raw video</returns>
        /// <param name="src">File contents</param>
        /// <param name="demuxUsed">Demux used</param>
        public static byte[] ExtractRawVideo(Stream sourceStream, out Demux demux)
        {
            demux = Demux.forSource(sourceStream);
            demux.Init(sourceStream);
            if (!demux.hasVideo)
            {
                return(null);
            }

            byte[] bigBuf       = new byte[demux.videoStreamInfo.lengthBytes];
            int    bigBufOffset = 0;
            int    bytesRead    = 0;

            do
            {
                byte[] buf;
                bytesRead = demux.ReadVideoFrame(out buf);
                System.Array.Copy(buf, 0, bigBuf, bigBufOffset, bytesRead);
                bigBufOffset += bytesRead;
            } while(bytesRead > 0);
            return(bigBuf);
        }
Ejemplo n.º 5
0
 public abstract void Init(out AudioClip audioClip, Demux demux, LoadOptions loadOptions = null);
Ejemplo n.º 6
0
        /// <summary>
        /// Extracts raw video from the movie.
        /// Usable only for reasonable sized streams, because byte[] is returned.
        /// </summary>
        /// <returns>The raw video</returns>
        /// <param name="src">File contents</param>
        /// <param name="demuxUsed">Demux used</param>
        public static byte[] ExtractRawVideo(Stream sourceStream, out Demux demux)
        {
            demux = Demux.forSource (sourceStream);
            demux.Init (sourceStream);
            if (!demux.hasVideo)
                return null;

            byte[] bigBuf = new byte[demux.videoStreamInfo.lengthBytes];
            int bigBufOffset = 0;
            int bytesRead = 0;
            do {
                byte[] buf;
                bytesRead = demux.ReadVideoFrame (out buf);
                System.Array.Copy (buf, 0, bigBuf, bigBufOffset, bytesRead);
                bigBufOffset += bytesRead;
            } while(bytesRead > 0);
            return bigBuf;
        }
Ejemplo n.º 7
0
 public abstract void Init(out Texture2D framebuffer, Demux demux, LoadOptions loadOptions = null);
Ejemplo n.º 8
0
 public abstract void Init(out Texture2D framebuffer, Demux demux, LoadOptions loadOptions = null);
Ejemplo n.º 9
0
 public abstract void Init(out AudioClip audioClip, Demux demux, LoadOptions loadOptions = null);
Ejemplo n.º 10
0
        /// <summary>
        /// Loads movie with audio. It will be ready for playback
        /// </summary>
        /// <param name="source">Source</param>
        /// <param name="targetFramebuffer">Target framebuffer</param>
        /// <param name="targetAudioBuffer">Target audio buffer</param>
        /// <param name="loadOptions">Load options</param>
        public static Movie Load(MovieSource source, out Texture2D targetFramebuffer, out AudioClip targetAudioBuffer, LoadOptions loadOptions = null)
        {
            if (loadOptions == null)
            {
                loadOptions = LoadOptions.Default;
            }

            if (source.stream == null && source.url == null)
            {
                throw new MpException("Either source.stream or source.url must be provided");
            }

            targetFramebuffer = null;
            targetAudioBuffer = null;

            var movie = new Movie();

            movie.sourceStream = source.stream;             // can be NULL

            // create and initialize demux for the source data
            if (source.url != null)
            {
                movie.demux = loadOptions.demuxOverride != null ? loadOptions.demuxOverride : Streamer.forUrl(source.url);
                ((Streamer)movie.demux).Connect(source.url, loadOptions);
            }
            else
            {
                movie.demux = loadOptions.demuxOverride != null ? loadOptions.demuxOverride : Demux.forSource(source.stream);
                movie.demux.Init(source.stream, loadOptions);
            }

            if (movie.demux.hasVideo && !loadOptions.skipVideo)
            {
                movie.videoDecoder = VideoDecoder.CreateFor(movie.demux.videoStreamInfo);
                movie.videoDecoder.Init(out targetFramebuffer, movie.demux, loadOptions);
            }
            if (movie.demux.hasAudio && !loadOptions.skipAudio)
            {
                movie.audioDecoder = AudioDecoder.CreateFor(movie.demux.audioStreamInfo);
                movie.audioDecoder.Init(out targetAudioBuffer, movie.demux, loadOptions);
            }
            return(movie);
        }