Пример #1
0
        public IEnumerable <MediaPacket> ReadPacket()
        {
            using (MediaPacket packet = new MediaPacket())
            {
                int ret;
                do
                {
                    ret = ReadPacket(packet);
                    if (ret < 0 && ret != ffmpeg.AVERROR_EOF)
                    {
                        throw new FFmpegException(ret);
                    }
                    yield return(packet);

                    packet.Clear();
                } while (ret >= 0);
            }
        }
Пример #2
0
 /// <summary>
 /// TODO: add SubtitleFrame support
 /// </summary>
 /// <param name="frame"></param>
 /// <returns></returns>
 public virtual IEnumerable <MediaPacket> EncodeFrame(MediaFrame frame)
 {
     SendFrame(frame).ThrowIfError();
     RemoveSideData(frame);
     using (MediaPacket packet = new MediaPacket())
     {
         while (true)
         {
             int ret = ReceivePacket(packet);
             if (ret == ffmpeg.AVERROR(ffmpeg.EAGAIN) || ret == ffmpeg.AVERROR_EOF)
             {
                 break;
             }
             ret.ThrowIfError();
             yield return(packet);
         }
     }
 }
Пример #3
0
 /// <summary>
 /// decode packet to get frame.
 /// TODO: add SubtitleFrame support
 /// <para>
 /// <see cref="SendPacket(MediaPacket)"/> and <see cref="ReceiveFrame(MediaFrame)"/>
 /// </para>
 /// </summary>
 /// <param name="packet"></param>
 /// <returns></returns>
 public virtual IEnumerable <MediaFrame> DecodePacket(MediaPacket packet)
 {
     if (SendPacket(packet) >= 0)
     {
         // if codoc type is video, create new video frame
         // else if codoc type is audio, create new audio frame
         // else throw a exception (e.g. codec type is subtitle)
         // TODO: add subtitle supported
         using (MediaFrame frame =
                    Type == AVMediaType.AVMEDIA_TYPE_VIDEO ?
                    new VideoFrame() :
                    Type == AVMediaType.AVMEDIA_TYPE_AUDIO ?
                    (MediaFrame) new AudioFrame() :
                    throw new FFmpegException(FFmpegException.NotSupportFrame))
         {
             while (ReceiveFrame(frame) >= 0)
             {
                 yield return(frame);
             }
         }
     }
 }
Пример #4
0
 public int ReceivePacket([Out] MediaPacket packet)
 {
     return(ffmpeg.avcodec_receive_packet(pCodecContext, packet));
 }
Пример #5
0
 public int ReadPacket([Out] MediaPacket packet)
 {
     return(ffmpeg.av_read_frame(pFormatContext, packet));
 }