Esempio n. 1
0
 /// <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);
 }
Esempio n. 2
0
 /// <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);
 }
Esempio n. 3
0
 /// <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);
 }
Esempio n. 4
0
        private void SwrCheckInit(MediaFrame srcFrame)
        {
            if (pSwrContext == null && !isDisposing)
            {
                AVFrame *src = srcFrame;
                AVFrame *dst = dstFrame;
                ulong    srcChannelLayout = src->channel_layout;
                if (srcChannelLayout == 0)
                {
                    srcChannelLayout = FFmpegHelper.GetChannelLayout(src->channels);
                }

                pSwrContext = ffmpeg.swr_alloc_set_opts(null,
                                                        (long)DstChannelLayout, DstFormat, DstSampleRate == 0 ? src->sample_rate : DstSampleRate,
                                                        (long)srcChannelLayout, (AVSampleFormat)src->format, src->sample_rate,
                                                        0, null);
                ffmpeg.swr_init(pSwrContext).ThrowIfError();
            }
        }
Esempio n. 5
0
 public static MediaEncoder CreateAudioEncode(AVCodecID audioCodec, int flags, int channels, int sampleRate = 0, long bitRate = 0, AVSampleFormat format = AVSampleFormat.AV_SAMPLE_FMT_NONE)
 {
     return(CreateAudioEncode(audioCodec, flags, FFmpegHelper.GetChannelLayout(channels), sampleRate, bitRate, format));
 }