Пример #1
0
        internal static unsafe void AvFormatSeekFile(AvFormatContext formatContext, double time)
        {
            int result = ffmpeg.avformat_seek_file((AVFormatContext *)formatContext.FormatPtr,
                                                   formatContext.BestAudioStreamIndex, long.MinValue, (long)time, (long)time, 0);

            FfmpegException.Try(result, "avformat_seek_file");
        }
Пример #2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="FfmpegDecoder" /> class based on a specified filename or url.
        /// </summary>
        /// <param name="url">A url containing a filename or web url. </param>
        /// <exception cref="FfmpegException">
        ///     Any ffmpeg error.
        /// </exception>
        /// <exception cref="System.NotSupportedException">
        ///     DBL format is not supported.
        ///     or
        ///     Audio Sample Format not supported.
        /// </exception>
        /// <exception cref="ArgumentNullException">uri</exception>
        public FfmpegDecoder(string url)
        {
            const int invalidArgument = unchecked ((int)0xffffffea);

            _uri = new Uri(url);
            try
            {
                _formatContext = new AvFormatContext(url);
                Initialize();
            }
            catch (FfmpegException ex)
            {
                if (ex.ErrorCode == invalidArgument && "avformat_open_input".Equals(ex.Function, StringComparison.OrdinalIgnoreCase))
                {
                    if (!TryInitializeWithFileAsStream(url))
                    {
                        throw;
                    }
                }
                else
                {
                    throw;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected void Dispose(bool disposing)
        {
            GC.SuppressFinalize(this);

            if (disposing)
            {
                if (_disposeStream && _stream != null)
                {
                    _stream.Dispose();
                    _stream = null;
                }

                if (_formatContext != null)
                {
                    _formatContext.Dispose();
                    _formatContext = null;
                }

                if (_ffmpegStream != null)
                {
                    _ffmpegStream.Dispose();
                    _ffmpegStream = null;
                }
            }
        }
Пример #4
0
        private void InitializeWithStream(Stream stream, bool disposeStream)
        {
            _stream        = stream;
            _disposeStream = disposeStream;

            _ffmpegStream  = new FfmpegStream(stream);
            _formatContext = new AvFormatContext(_ffmpegStream);
            Initialize();
        }
Пример #5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="FfmpegDecoder" /> class based on a <see cref="Stream" />.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <exception cref="FfmpegException">Any ffmpeg error.</exception>
        /// <exception cref="System.ArgumentNullException">stream</exception>
        /// <exception cref="ArgumentException">Stream is not readable.</exception>
        /// <exception cref="System.OutOfMemoryException">Could not allocate FormatContext.</exception>
        /// <exception cref="System.NotSupportedException">
        ///     DBL format is not supported.
        ///     or
        ///     Audio Sample Format not supported.
        /// </exception>
        public FfmpegDecoder(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            _ffmpegStream  = new FfmpegStream(stream);
            _formatContext = new AvFormatContext(_ffmpegStream);
            Initialize();
        }
Пример #6
0
 public unsafe AvFrame(AvFormatContext formatContext)
 {
     _formatContext = formatContext;
     _frame         = FfmpegCalls.AvFrameAlloc();
 }
Пример #7
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="FfmpegDecoder" /> class based on a specified filename or url.
 /// </summary>
 /// <param name="url">A url containing a filename or web url. </param>
 /// <exception cref="FfmpegException">
 ///     Any ffmpeg error.
 /// </exception>
 /// <exception cref="System.NotSupportedException">
 ///     DBL format is not supported.
 ///     or
 ///     Audio Sample Format not supported.
 /// </exception>
 /// <exception cref="ArgumentNullException">uri</exception>
 public FfmpegDecoder(string url)
 {
     _uri           = new Uri(url);
     _formatContext = new AvFormatContext(url);
     Initialize();
 }
Пример #8
0
        internal static unsafe bool AvReadFrame(AvFormatContext formatContext, AVPacket *packet)
        {
            int result = ffmpeg.av_read_frame((AVFormatContext *)formatContext.FormatPtr, packet);

            return(result >= 0);
        }