/// <summary> /// create by format name,e.g. "mp4" ".mp4" /// </summary> /// <param name="name"></param> public OutFormat(string name) { unsafe { name = name.Trim().TrimStart('.'); if (!string.IsNullOrEmpty(name)) { void * ofmtOpaque = null; AVOutputFormat *oformat; while ((oformat = ffmpeg.av_muxer_iterate(&ofmtOpaque)) != null) { OutFormat format = new OutFormat(oformat); // e.g. format.Name == "mov,mp4,m4a,3gp,3g2,mj2" string[] names = format.Name.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in names) { if (item == name.ToLower()) { pOutputFormat = oformat; return; } } } } throw new FFmpegException(ffmpeg.AVERROR_MUXER_NOT_FOUND); } }
/// <summary> /// write to file. /// <para><see cref="ffmpeg.avformat_alloc_output_context2(AVFormatContext**, AVOutputFormat*, string, string)"/></para> /// <para><see cref="ffmpeg.avio_open(AVIOContext**, string, int)"/></para> /// </summary> /// <param name="file"></param> /// <param name="oformat"></param> /// <param name="options"></param> public MediaWriter(string file, OutFormat oformat = null, MediaDictionary options = null) { fixed(AVFormatContext **ppFormatContext = &pFormatContext) { ffmpeg.avformat_alloc_output_context2(ppFormatContext, oformat, null, file).ThrowIfError(); } base.Format = oformat ?? new OutFormat(pFormatContext->oformat); if ((pFormatContext->oformat->flags & ffmpeg.AVFMT_NOFILE) == 0) { ffmpeg.avio_open2(&pFormatContext->pb, file, ffmpeg.AVIO_FLAG_WRITE, null, options).ThrowIfError(); } }
public MediaWriter(Stream stream, OutFormat oformat, MediaDictionary options = null) { baseStream = stream; avio_Alloc_Context_Read_Packet = ReadFunc; avio_Alloc_Context_Write_Packet = WriteFunc; avio_Alloc_Context_Seek = SeekFunc; pFormatContext = ffmpeg.avformat_alloc_context(); pFormatContext->oformat = oformat; base.Format = oformat; if ((pFormatContext->oformat->flags & ffmpeg.AVFMT_NOFILE) == 0) { pFormatContext->pb = ffmpeg.avio_alloc_context((byte *)ffmpeg.av_malloc(bufferLength), bufferLength, 1, null, avio_Alloc_Context_Read_Packet, avio_Alloc_Context_Write_Packet, avio_Alloc_Context_Seek); } }
public static MediaEncoder CreateAudioEncode(OutFormat Oformat, int channels, int sampleRate, long bitRate = 0, AVSampleFormat format = AVSampleFormat.AV_SAMPLE_FMT_NONE) { return(CreateAudioEncode(Oformat.AudioCodec, Oformat.Flags, (ulong)ffmpeg.av_get_default_channel_layout(channels), sampleRate, bitRate, format)); }
public static MediaEncoder CreateAudioEncode(OutFormat Oformat, ulong channelLayout, int sampleRate, long bitRate = 0, AVSampleFormat format = AVSampleFormat.AV_SAMPLE_FMT_NONE) { return(CreateAudioEncode(Oformat.AudioCodec, Oformat.Flags, channelLayout, sampleRate, bitRate, format)); }
public static MediaEncoder CreateVideoEncode(OutFormat oformat, int width, int height, int fps, long bitRate = 0, AVPixelFormat format = AVPixelFormat.AV_PIX_FMT_NONE) { return(CreateVideoEncode(oformat.VideoCodec, oformat.Flags, width, height, fps, bitRate, format)); }
/// <summary> /// write to stream,default buffersize 4096 /// </summary> /// <param name="stream"></param> /// <param name="oformat"></param> /// <param name="options"></param> public MediaWriter(Stream stream, OutFormat oformat, MediaDictionary options = null) : this(stream, 4096, oformat, options) { }