<div dir="ltr"><div>Thanks Gonzalo,</div><div><br></div><div>According to your suggestion i have written the below code can you check ones, because audio is written but in output file no audio is present.</div><div><br style="font-size:12.8px"><span style="font-size:12.8px">ref struct WriterData</span><br style="font-size:12.8px"><span style="font-size:12.8px">{</span><br style="font-size:12.8px"><span style="font-size:12.8px"> public:</span><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::AVFormatContext* FormatContext;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::AVStream* AudioStream;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::AVFrame* AudioFrame;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::AVCodec *Audio_Codec;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> int AudioBitRate;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> int SampleRate;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> int Channels;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> int AudioReceived;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> int AudioWritten;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::int64_t next_pts;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> int samples_count;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::AVFrame *tmp_frame;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> float t, tincr, tincr2;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> struct Ffmpeg::SwsContext *sws_ctx;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> struct Ffmpeg::SwrContext *swr_ctx;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> double PreviousAudioDts;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> AudioWriterData()</span><br style="font-size:12.8px"><span style="font-size:12.8px"> {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> FormatContext = NULL;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> AudioStream = NULL;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> Audio_Codec = NULL;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> AudioFrame = NULL;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> AudioReceived = 0;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> AudioWritten = 0;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> }</span><br style="font-size:12.8px"><span style="font-size:12.8px">};</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">void Encoder::Open(String^ fileName, AudioCodec audioCodec, int</span><br style="font-size:12.8px"><span style="font-size:12.8px">audioBitrate, int sampleRate, int channels)</span><br style="font-size:12.8px"><span style="font-size:12.8px">{</span><br style="font-size:12.8px"><span style="font-size:12.8px"> CheckIfDisposed();</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> Close();</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> data = gcnew WriterData();</span><br style="font-size:12.8px"><span style="font-size:12.8px"> bool success = false;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (((int)audioCodec < -1) || ((int)audioCodec >= AUDIO_CODECS_COUNT))</span><br style="font-size:12.8px"><span style="font-size:12.8px"> throw gcnew ArgumentException("Invalid audio codec is specified.");</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> m_acodec = audioCodec;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> m_audioBitrate = audioBitrate;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> m_sampleRate = sampleRate;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> m_channels = channels;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> data->AudioBitRate = audioBitrate;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> data->SampleRate = sampleRate;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> data->Channels = channels;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> char* nativeFileName =</span><br style="font-size:12.8px"><span style="font-size:12.8px">(char*)System::Runtime::</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">InteropServices::Marshal::</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">StringToHGlobalAnsi(fileName).</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">ToPointer();</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> try</span><br style="font-size:12.8px"><span style="font-size:12.8px"> {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::AVOutputFormat* outputFormat = Ffmpeg::av_guess_format(NULL,</span><br style="font-size:12.8px"><span style="font-size:12.8px">nativeFileName, NULL);</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (!outputFormat)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> outputFormat = Ffmpeg::av_guess_format("mp3", NULL, NULL);</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (!outputFormat)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> throw gcnew Exception("Cannot find suitable output format.");</span><br style="font-size:12.8px"><span style="font-size:12.8px"> }</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> data->FormatContext = Ffmpeg::avformat_alloc_</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">context();</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (!data->FormatContext)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> throw gcnew Exception("Cannot allocate format context.");</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> data->FormatContext->oformat = outputFormat;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> strcpy_s(data->FormatContext-></span><wbr style="font-size:12.8px"><span style="font-size:12.8px">filename, nativeFileName);</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::AVCodecID codecId = (audioCodec == AudioCodec::Default) ?</span><br style="font-size:12.8px"><span style="font-size:12.8px">outputFormat->audio_codec : (Ffmpeg::AVCodecID)</span><br style="font-size:12.8px"><span style="font-size:12.8px">audio_codecs[(int)audioCodec];</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> data->FormatContext->oformat-></span><wbr style="font-size:12.8px"><span style="font-size:12.8px">audio_codec = codecId;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> add_audio_stream(data, codecId);</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> open_audio(data);</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::av_dump_format(data-></span><wbr style="font-size:12.8px"><span style="font-size:12.8px">FormatContext, 0, nativeFileName, 1);</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (!(outputFormat->flags & AVFMT_NOFILE))</span><br style="font-size:12.8px"><span style="font-size:12.8px"> {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> if (Ffmpeg::avio_open(&data-></span><wbr style="font-size:12.8px"><span style="font-size:12.8px">FormatContext->pb, nativeFileName,</span><br style="font-size:12.8px"><span style="font-size:12.8px">AVIO_FLAG_WRITE) < 0)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> throw gcnew System::IO::IOException("</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">Cannot open the video file.");</span><br style="font-size:12.8px"><span style="font-size:12.8px"> }</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::avformat_write_header(</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">data->FormatContext, NULL);</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> success = true;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> }</span><br style="font-size:12.8px"><span style="font-size:12.8px"> finally</span><br style="font-size:12.8px"><span style="font-size:12.8px"> {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> nativeFileName = NULL;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> delete[] nativeFileName;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (!success)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> Close();</span><br style="font-size:12.8px"><span style="font-size:12.8px"> }</span><br style="font-size:12.8px"><span style="font-size:12.8px">}</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">void add_audio_stream(WriterData^ data, enum Ffmpeg::AVCodecID codecId)</span><br style="font-size:12.8px"><span style="font-size:12.8px">{</span><br style="font-size:12.8px"><span style="font-size:12.8px"> data->AudioStream = Ffmpeg::avformat_new_stream(</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">data->FormatContext,</span><br style="font-size:12.8px"><span style="font-size:12.8px">data->FormatContext->audio_</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">codec);</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (!data->AudioStream)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> throw gcnew Exception("Could not alloc audio stream");</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::AVCodecContext *codecContext = data->AudioStream->codec;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->codec_id = codecId;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->codec_type = Ffmpeg::AVMEDIA_TYPE_AUDIO;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->sample_fmt = Ffmpeg::AV_SAMPLE_FMT_S16;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->channels = data->Channels;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->delay = 0;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->bit_rate = data->AudioBitRate;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (codecContext->bit_rate == 0)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->bit_rate = data->SampleRate * data->Channels * 16;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->bit_rate = codecContext->bit_rate;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->bit_rate_</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">tolerance = codecContext->bit_rate;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->rc_min_rate = 0;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->rc_max_rate = 0;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->frame_size = 0;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->channel_layout = (codecContext->channels == 2 ?</span><br style="font-size:12.8px"><span style="font-size:12.8px">AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO);</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->sample_rate = data->SampleRate;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->time_base.den = data->SampleRate;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->time_base.num = 1;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> //data->AudioStream->time_</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">base.den = codecContext->time_base.den;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> //data->AudioStream->time_</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">base.num = codecContext->time_base.num;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (data->FormatContext->oformat-</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">>flags & AVFMT_GLOBALHEADER)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->flags |= CODEC_FLAG_GLOBAL_HEADER;</span><br style="font-size:12.8px"><span style="font-size:12.8px">}</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">void open_audio(WriterData^ data)</span><br style="font-size:12.8px"><span style="font-size:12.8px">{</span><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::AVCodecContext* codecContext = data->AudioStream->codec;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::AVCodec* codec = avcodec_find_encoder(</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">codecContext->codec_id);</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (!codec)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> throw gcnew Exception("Cannot find audio codec.");</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->codec_id = codec->id;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->codec_type = Ffmpeg::AVMEDIA_TYPE_AUDIO;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->sample_fmt = codec->sample_fmts[0];</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->sample_rate = data->SampleRate;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->channel_layout = AV_CH_LAYOUT_STEREO;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->channels =</span><br style="font-size:12.8px"><span style="font-size:12.8px">Ffmpeg::av_get_channel_layout_</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">nb_channels(codecContext-></span><wbr style="font-size:12.8px"><span style="font-size:12.8px">channel_layout);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> codecContext->bit_rate = data->AudioBitRate;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> int ret = Ffmpeg::avcodec_open2(</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">codecContext, codec, NULL);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> if (ret < 0)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> throw gcnew Exception("Cannot open audio codec.");</span><br style="font-size:12.8px"><span style="font-size:12.8px">}</span><br style="font-size:12.8px"><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">void Encoder::WriteAudioChunk(</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">IntPtr chunk, int lenght, TimeSpan timestamp)</span><br style="font-size:12.8px"><span style="font-size:12.8px">{</span><br style="font-size:12.8px"><span style="font-size:12.8px"> CheckIfDisposed();</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (data == nullptr)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> throw gcnew System::IO::IOException("A video file was not opened yet.");</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> int bufferSize = lenght;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> data->AudioFrame = Ffmpeg::av_frame_alloc();</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::av_frame_unref(data-></span><wbr style="font-size:12.8px"><span style="font-size:12.8px">AudioFrame);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> data->AudioFrame->pts = AV_NOPTS_VALUE;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> data->AudioFrame->format = data->AudioStream->codec-></span><wbr style="font-size:12.8px"><span style="font-size:12.8px">sample_fmt;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> int bytePerSample =</span><br style="font-size:12.8px"><span style="font-size:12.8px">Ffmpeg::av_get_bytes_per_</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">sample(data->AudioStream-></span><wbr style="font-size:12.8px"><span style="font-size:12.8px">codec->sample_fmt);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> int dataSize = data->Channels * bytePerSample;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> data->AudioStream->codec-></span><wbr style="font-size:12.8px"><span style="font-size:12.8px">frame_size = data->Channels *</span><br style="font-size:12.8px"><span style="font-size:12.8px">data->SampleRate * bytePerSample;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> data->AudioFrame->nb_samples = data->AudioStream->codec-></span><wbr style="font-size:12.8px"><span style="font-size:12.8px">frame_size;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::uint8_t *buf =</span><br style="font-size:12.8px"><span style="font-size:12.8px">reinterpret_cast<Ffmpeg::</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">uint8_t*>(static_cast<void*>(</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">chunk));</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> int ret = Ffmpeg::avcodec_fill_audio_</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">frame(data->AudioFrame,</span><br style="font-size:12.8px"><span style="font-size:12.8px">data->Channels, data->AudioStream->codec-></span><wbr style="font-size:12.8px"><span style="font-size:12.8px">sample_fmt, buf, bufferSize,</span><br style="font-size:12.8px"><span style="font-size:12.8px">1);</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (!ret)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> throw gcnew System::IO::IOException("A video file was not opened yet.");</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> data->AudioReceived++;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> write_audio_chunk(data, buf, ret,timestamp.</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">TotalMilliseconds);</span><br style="font-size:12.8px"><span style="font-size:12.8px">}</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">void write_audio_chunk(WriterData^ data, Ffmpeg::uint8_t *ut, int</span><br style="font-size:12.8px"><span style="font-size:12.8px">size,double timeStamp)</span><br style="font-size:12.8px"><span style="font-size:12.8px">{</span><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::AVCodecContext* codecContext = data->AudioStream->codec;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> int out_size, ret = 0;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::AVPacket packet;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> int64_t dts = timeStamp;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> dts = dts * data->FrameRate;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (data->PreviousAudioDts < 0)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> data->PreviousAudioDts = dts;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> int got_packet;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> Ffmpeg::av_init_packet(&</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">packet);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> packet.data = ut;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> packet.size = size;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> out_size = Ffmpeg::avcodec_send_frame(</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">codecContext, data->AudioFrame);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> got_packet = Ffmpeg::avcodec_receive_</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">packet(codecContext, &packet);</span><br style="font-size:12.8px"><br style="font-size:12.8px"><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (got_packet)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> if (codecContext->coded_frame-></span><wbr style="font-size:12.8px"><span style="font-size:12.8px">pts != AV_NOPTS_VALUE)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> packet.pts = Ffmpeg::av_rescale_q(packet.</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">pts,</span><br style="font-size:12.8px"><span style="font-size:12.8px">codecContext->time_base, data->AudioStream->time_base);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> packet.dts = Ffmpeg::av_rescale_q(packet.</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">dts,</span><br style="font-size:12.8px"><span style="font-size:12.8px">codecContext->time_base, data->AudioStream->time_base);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> packet.duration = Ffmpeg::av_rescale_q(packet.</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">duration,</span><br style="font-size:12.8px"><span style="font-size:12.8px">codecContext->time_base, data->AudioStream->time_base);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> }</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> packet.stream_index = data->AudioStream->index;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> ret = Ffmpeg::av_interleaved_write_</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">frame(data->FormatContext, &packet);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> //ret = Ffmpeg::av_write_frame(data-></span><wbr style="font-size:12.8px"><span style="font-size:12.8px">FormatContext, &packet);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> data->AudioWritten++;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> }</span><br style="font-size:12.8px"><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> av_packet_unref(&packet);</span><br style="font-size:12.8px"><span style="font-size:12.8px"> got_packet = 0;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> if (ret != 0)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> throw gcnew Exception("Error while writing audio frame.");</span><br style="font-size:12.8px"><span style="font-size:12.8px">}</span><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 15 February 2017 at 03:07, Gonzalo Garramuño <span dir="ltr"><<a href="mailto:ggarra13@gmail.com" target="_blank">ggarra13@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
El 14/02/17 a las 08:00, Prakash Rokade escribió:<div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have created CLI/CPP wrapper over Ffmpe,<br>
And i want to write audio to file that is in IntPtr format.<br>
I don't know how to do, can any one suggest something..<br>
Thank You.<br>
</blockquote></div></div>
You need to select a codec to save your audio in and initialize it appropiately. Then use the swresample part of ffmpeg to turn your int samples into what the codec expects (for example, planar float or fltp ).<br>
The docs/examples/muxing.c should prove useful.<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Gonzalo Garramuño<br>
<br>
______________________________<wbr>_________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/list<wbr>info/libav-user</a><br>
</font></span></blockquote></div><br></div>