/// <summary> /// create audio converter by dst output parames /// </summary> /// <param name="dstFormat"></param> /// <param name="dstChannels"></param> /// <param name="dstNbSamples"></param> /// <param name="dstSampleRate"></param> public SampleConverter(AVSampleFormat dstFormat, int dstChannels, int dstNbSamples, int dstSampleRate) { DstFormat = dstFormat; DstChannels = dstChannels; DstChannelLayout = FFmpegHelper.GetChannelLayout(dstChannels); DstNbSamples = dstNbSamples; DstSampleRate = dstSampleRate; dstFrame = new AudioFrame(DstChannels, DstNbSamples, DstFormat, DstSampleRate); AudioFifo = new AudioFifo(DstFormat, DstChannels); }
/// <summary> /// create audio converter by dst output parames /// </summary> /// <param name="dstFormat"></param> /// <param name="dstChannelLayout">see <see cref="AVChannelLayout"/></param> /// <param name="dstNbSamples"></param> /// <param name="dstSampleRate"></param> public SampleConverter(AVSampleFormat dstFormat, ulong dstChannelLayout, int dstNbSamples, int dstSampleRate) { DstFormat = dstFormat; DstChannelLayout = dstChannelLayout; DstChannels = ffmpeg.av_get_channel_layout_nb_channels(dstChannelLayout); DstNbSamples = dstNbSamples; DstSampleRate = dstSampleRate; dstFrame = new AudioFrame(DstChannels, DstNbSamples, DstFormat, DstSampleRate); AudioFifo = new AudioFifo(DstFormat, ffmpeg.av_get_channel_layout_nb_channels(DstChannelLayout), 1); }
/// <summary> /// create audio converter by dst frame /// </summary> /// <param name="dstFrame"></param> public SampleConverter(AudioFrame dstFrame) { ffmpeg.av_frame_make_writable(dstFrame).ThrowIfError(); DstFormat = (AVSampleFormat)dstFrame.AVFrame.format; DstChannels = dstFrame.AVFrame.channels; DstChannelLayout = dstFrame.AVFrame.channel_layout; if (DstChannelLayout == 0) { DstChannelLayout = FFmpegHelper.GetChannelLayout(DstChannels); } DstNbSamples = dstFrame.AVFrame.nb_samples; DstSampleRate = dstFrame.AVFrame.sample_rate; base.dstFrame = dstFrame; AudioFifo = new AudioFifo(DstFormat, DstChannels); }
/// <summary> /// create audio converter by dst codec /// </summary> /// <param name="dstCodec"></param> public SampleConverter(MediaCodec dstCodec) { if (dstCodec.Type != AVMediaType.AVMEDIA_TYPE_AUDIO) { throw new FFmpegException(FFmpegException.CodecTypeError); } DstFormat = dstCodec.AVCodecContext.sample_fmt; DstChannels = dstCodec.AVCodecContext.channels; DstChannelLayout = dstCodec.AVCodecContext.channel_layout; if (DstChannelLayout == 0) { DstChannelLayout = FFmpegHelper.GetChannelLayout(DstChannels); } DstNbSamples = dstCodec.AVCodecContext.frame_size; DstSampleRate = dstCodec.AVCodecContext.sample_rate; dstFrame = new AudioFrame(DstChannels, DstNbSamples, DstFormat, DstSampleRate); AudioFifo = new AudioFifo(DstFormat, DstChannels); }