<div>Hello, Andrey ,</div><div> </div><div>Thanks for your reply</div><blockquote><div> </div><div>See avformat_new_stream(). Call it for each elementary stream you have,</div><div> </div><div>on the output file context.</div><div> </div></blockquote><div>I’ve already tried to do that with video thread only. But I receive an error while calling av_write_frame…</div><div> </div><div>av_write_frame (Unhandled exception at 0x76ff15de in ***.exe: 0xC0000094: Integer division by zero.).</div><div> </div><div>I’d better show you here the code fragment (without error processing)</div><div> </div><div>const char *sFileOutput = "d://video_stream.avi";</div><div> </div><div>ofmt = av_guess_format(NULL, sFileOutput, NULL);</div><div> </div><div>ofcx = avformat_alloc_context();</div><div> </div><div>ofcx->oformat = ofmt;</div><div> </div><div>memcpy(ofcx->filename, sFileOutput, sizeof(ofcx->filename));</div><div> </div><div>if( avio_open2( &ofcx->pb, sFileOutput, AVIO_FLAG_WRITE, NULL, NULL ) < 0){…}</div><div> </div><div>ocodec = avcodec_find_decoder(CODEC_ID_H264);</div><div> </div><div>ost = avformat_new_stream(ofcx, ocodec);</div><div> </div><div>occx = ost->codec;</div><div> </div><div>occx->codec_id = CODEC_ID_H264;</div><div> </div><div>occx->codec_type = AVMEDIA_TYPE_VIDEO;</div><div> </div><div>avcodec_get_context_defaults3(occx, ocodec);</div><div> </div><div>if (avcodec_open2(ost->codec, ocodec, NULL) < 0) {…}</div><div> </div><div>if(avio_open2( &ofcx->pb, sFileOutput, AVIO_FLAG_WRITE, NULL, NULL )) {…}</div><div> </div><div>avformat_write_header( ofcx, NULL );</div><div> </div><div>av_dump_format(ofcx     , 0, ofcx->filename,      1 );</div><div> </div><div>ix = 0;</div><div> </div><div>…</div><div> </div><div>av_init_packet( &pkt );</div><div> </div><div>// m_sFrameBuf – <strong>This is a frame formed from the data received from the Ethernet</strong></div><div><br />av_packet_from_data(&pkt, (uint8_t*) &m_sFrameBuf, m_nFpameSize);</div><div> </div><div>pkt.stream_index = 0;//ost->id;</div><div> </div><div>pkt.pts = ix++;</div><div> </div><div>pkt.dts = pkt.pts;</div><div> </div><div>av_write_frame( ofcx, &pkt ); <strong>// in this point error -  Unhandled exception at 0x76ff15de in ***.exe: 0xC0000094: Integer division by zero</strong></div><div> </div><div>av_free_packet( &pkt );</div><div> </div><div>…</div><div> </div><div><strong>When I read data from file I copy context and it’s ok</strong></div><div> </div><div>…</div><div> </div><div>avcodec_copy_context( ost->codec, iccx );</div><div> </div><div>ost->sample_aspect_ratio.num = iccx->sample_aspect_ratio.num;</div><div> </div><div>ost->sample_aspect_ratio.den = iccx->sample_aspect_ratio.den;</div><div> </div><div>ost->r_frame_rate = ist->r_frame_rate;</div><div> </div><div>ost->time_base = av_inv_q( ost->r_frame_rate );</div><div> </div><div>ost->codec->time_base = ost->time_base;</div><div> </div><div>Where is a mistake?</div><div> </div><div>--</div><div> Ekaterina</div><div> </div><div> </div><div> </div><div> </div><div> </div><div> </div><div> </div><div> </div><div> </div>