示例#1
0
        public FilterContext AddSource(AudioFormatInfo format)
        {
            AVFilterContext *filterContext;

            var sampleFormatName = ffmpeg.av_get_sample_fmt_name(format.SampleFormat.ToAVFormat());

            var channelLayoutHex = ((ulong)format.ChannelLayout);
            var hexChannelLayout = ((long)format.ChannelLayout).ToString("x");

            var args = string.Join(':',
                                   $"time_base=1/{format.SampleRate}",
                                   $"sample_rate={format.SampleRate}",
                                   $"sample_fmt={sampleFormatName}",
                                   $"channel_layout=0x{hexChannelLayout}"
                                   );

            ffmpeg.avfilter_graph_create_filter(
                filt_ctx: &filterContext,
                filt: Filter.FromName("abuffer").Pointer,
                name: "in",
                args: args,
                opaque: null,
                graph_ctx: pointer
                ).EnsureSuccess();

            // Console.WriteLine("added source:" + Marshal.PtrToStringAnsi((IntPtr)filterContext->name));

            return(new FilterContext(filterContext));
        }
示例#2
0
        public AudioFrame(AudioFormatInfo format, int sampleCount)
        {
            this.format = format ?? throw new ArgumentNullException(nameof(format));

            Memory = Buffer.Allocate(AudioFormatHelper.GetBufferSize(format, sampleCount));

            channelPlanePointers = ffmpeg.av_calloc((ulong)IntPtr.Size, 8);

            ffmpeg.av_samples_fill_arrays(
                audio_data: (byte **)channelPlanePointers,
                linesize: null,
                buf: (byte *)Memory.Pointer,
                nb_channels: format.ChannelCount,
                sample_fmt: format.SampleFormat.ToAVFormat(),
                nb_samples: sampleCount,
                align: 0
                );

            // Set the frame properties
            SampleFormat  = format.SampleFormat;
            SampleRate    = format.SampleRate;
            SampleCount   = sampleCount;
            ChannelCount  = format.ChannelCount;
            ChannelLayout = format.ChannelLayout;

            pointer->extended_data = (byte **)channelPlanePointers;
        }
示例#3
0
        public unsafe static int GetBufferSize(this AudioFormatInfo format, int sampleCount)
        {
            if (sampleCount <= 0)
            {
                throw new ArgumentException("Must be > 0");
            }

            return(ffmpeg.av_samples_get_buffer_size(
                       linesize: null,
                       nb_channels: format.ChannelCount,
                       nb_samples: sampleCount,
                       sample_fmt: format.SampleFormat.ToAVFormat(),
                       align: 0
                       ));
        }