EmguFFmpeg icon indicating copy to clipboard operation
EmguFFmpeg copied to clipboard

Error when I called AddAudioSrcFilter

Open sbabich opened this issue 4 years ago • 1 comments

Hi!

I try to create audio filter

filterGraph.AddAudioSrcFilter(new MediaFilter(MediaFilter.AudioSources.Abuffer), 0x00000004, sample_rate, (AVSampleFormat)aformat) .LinkTo(0, filterGraph.AddAudioSinkFilter(new MediaFilter(MediaFilter.AudioSinks.Abuffersink)));

but I got error, because filterContext.NbOutputs = 1

    public MediaFilterContext AddAudioSrcFilter(MediaFilter filter, ulong channelLayout, int samplerate, AVSampleFormat format, string contextName = null)
    {
        int nb_channels = ffmpeg.av_get_channel_layout_nb_channels(channelLayout);
        //var buffersrc = ffmpeg.avfilter_get_by_name("abuffer");
        MediaFilterContext filterContext = AddFilter(filter, _ =>
        {
            fixed (byte* p = new byte[64])
            {
                ffmpeg.av_get_channel_layout_string(p, 64, nb_channels, channelLayout);
                ffmpeg.av_opt_set(_, "channel_layout", ((IntPtr)p).PtrToStringUTF8(), ffmpeg.AV_OPT_SEARCH_CHILDREN);
                ffmpeg.av_opt_set(_, "sample_fmt", ffmpeg.av_get_sample_fmt_name(format), ffmpeg.AV_OPT_SEARCH_CHILDREN);
                ffmpeg.av_opt_set_q(_, "time_base", new AVRational() { num = 1, den = samplerate }, ffmpeg.AV_OPT_SEARCH_CHILDREN);
                ffmpeg.av_opt_set_int(_, "sample_rate", samplerate, ffmpeg.AV_OPT_SEARCH_CHILDREN);
            }
        }, contextName);
        if (filterContext.NbOutputs > 0)
            throw new FFmpegException(FFmpegException.NotSourcesFilter);
        if (ffmpeg.avfilter_pad_get_type(filterContext.AVFilterContext.input_pads, 0) != AVMediaType.AVMEDIA_TYPE_AUDIO)
            throw new FFmpegException(FFmpegException.FilterTypeError);
        return filterContext;
    }

Please, help me to solve this issue Thanks!

sbabich avatar Dec 31 '20 12:12 sbabich

Hi!

I try to create audio filter

filterGraph.AddAudioSrcFilter(new MediaFilter(MediaFilter.AudioSources.Abuffer), 0x00000004, sample_rate, (AVSampleFormat)aformat) .LinkTo(0, filterGraph.AddAudioSinkFilter(new MediaFilter(MediaFilter.AudioSinks.Abuffersink)));

but I got error, because filterContext.NbOutputs = 1

    public MediaFilterContext AddAudioSrcFilter(MediaFilter filter, ulong channelLayout, int samplerate, AVSampleFormat format, string contextName = null)
    {
        int nb_channels = ffmpeg.av_get_channel_layout_nb_channels(channelLayout);
        //var buffersrc = ffmpeg.avfilter_get_by_name("abuffer");
        MediaFilterContext filterContext = AddFilter(filter, _ =>
        {
            fixed (byte* p = new byte[64])
            {
                ffmpeg.av_get_channel_layout_string(p, 64, nb_channels, channelLayout);
                ffmpeg.av_opt_set(_, "channel_layout", ((IntPtr)p).PtrToStringUTF8(), ffmpeg.AV_OPT_SEARCH_CHILDREN);
                ffmpeg.av_opt_set(_, "sample_fmt", ffmpeg.av_get_sample_fmt_name(format), ffmpeg.AV_OPT_SEARCH_CHILDREN);
                ffmpeg.av_opt_set_q(_, "time_base", new AVRational() { num = 1, den = samplerate }, ffmpeg.AV_OPT_SEARCH_CHILDREN);
                ffmpeg.av_opt_set_int(_, "sample_rate", samplerate, ffmpeg.AV_OPT_SEARCH_CHILDREN);
            }
        }, contextName);
        if (filterContext.NbOutputs > 0)
            throw new FFmpegException(FFmpegException.NotSourcesFilter);
        if (ffmpeg.avfilter_pad_get_type(filterContext.AVFilterContext.input_pads, 0) != AVMediaType.AVMEDIA_TYPE_AUDIO)
            throw new FFmpegException(FFmpegException.FilterTypeError);
        return filterContext;
    }

Please, help me to solve this issue Thanks!

I have no idea. I seldom use the filter part. I'm thinking about keeping only the codec part and deleting other modules. Because of ffmpeg's license agreement, piped access to command-line programs(ffmpeg.exe) is probably the best.

IOL0ol1 avatar Dec 31 '20 12:12 IOL0ol1