public OutputContext(AVIOStream ioStream) { if (!ioStream.CanWrite) { throw new ArgumentException("Can't write to stream"); } fmtContext = ffmpeg.avformat_alloc_context(); if (fmtContext == null) { throw new FFmpegException(ffmpeg.AVERROR(ffmpeg.ENOMEM), "Failed to allocate format context"); } fmtContext->pb = ioStream.ioContext; }
public InputContext(AVIOStream ioStream) { if (!ioStream.CanRead) { throw new ArgumentException("Can't read from stream"); } fmtContext = ffmpeg.avformat_alloc_context(); if (fmtContext == null) { throw new FFmpegException(ffmpeg.AVERROR(ffmpeg.ENOMEM), "Failed to allocate format context"); } fmtContext->pb = ioStream.ioContext; int ret = 0; fixed(AVFormatContext **fmtContextPtr = &fmtContext) { ret = ffmpeg.avformat_open_input(fmtContextPtr, null, null, null); } if (ret < 0) { // format context is freed on failure in avformat_open_input, no need to clean up manually throw new FFmpegException(ret, "Failed to open input"); } ret = ffmpeg.avformat_find_stream_info(fmtContext, null); if (ret < 0) { fixed(AVFormatContext **fmtContextPtr = &fmtContext) { ffmpeg.avformat_close_input(fmtContextPtr); } throw new FFmpegException(ret, "Failed to read stream information"); } }