Hi,<div><br></div><div>I'm developing a plugin for writing raw images to uncompressed AVI. The problem is that if file is larger than 1GB, windows media player cannot open it, but media player classic can. Additionaly writing is stopped once file size reaches 2GB and seeking does not work anymore. AVI muxer in FFMPEG is supposed to support OpenDML AVI 2.0, right?</div>
<div><br></div><div>Any ideas?</div><div><br></div><div>Source code</div><div>----------------------------</div><div><div><font face="courier new, monospace">#define RET(x) { res = x; goto failed;}</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">HRESULT __stdcall CFFMPEGVideoStoreEngine::CreateFile(BSTR fileName, int pixelFormat, int width, int height, double frameRate)</font></div><div><font face="courier new, monospace">{</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>DBGPRINT(_T("CFFMPEGVideoStoreEngine::CreateFile called"));</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>DBGPRINT(_T(" param fileName: %s"), fileName);</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>HRESULT res;</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font face="courier new, monospace"> </font></span></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>_bstr_t fName;</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>fName.Assign(fileName);</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>if (!g_registered)</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>{</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>av_register_all();</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>g_registered = true;</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>}</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_lastErrNum = avformat_alloc_output_context2(&m_pFmtCtx, NULL, NULL, fName);</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>if (m_lastErrNum < 0)</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>RET(FFMPEG_E_NOOUTPUTFORMAT);</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>AVOutputFormat* pOutFmt = m_pFmtCtx->oformat;</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>AVCodec* codec = avcodec_find_encoder(AV_CODEC_ID_RAWVIDEO);</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font face="courier new, monospace"> </font></span></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_pStream = avformat_new_stream(m_pFmtCtx, codec);</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>if (!m_pStream)</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>RET(FFMPEG_E_CREATESTREAMFAILED);</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font face="courier new, monospace"> </font></span></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_pCodCtx = m_pStream->codec;</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> avcodec_get_context_defaults3(m_pCodCtx, codec);</font></div><div><font face="courier new, monospace"><br></font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_pCodCtx->width = width;</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_pCodCtx->height = height;</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_pCodCtx->time_base = av_inv_q(av_d2q(frameRate, 1000));</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_pCodCtx->pix_fmt = (AVPixelFormat) pixelFormat;</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>if (pOutFmt->flags & AVFMT_GLOBALHEADER)</font></div><div><font face="courier new, monospace"> m_pCodCtx->flags |= CODEC_FLAG_GLOBAL_HEADER;</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_lastErrNum = avcodec_open2(m_pCodCtx, codec, NULL);</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>if (m_lastErrNum < 0)</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>RET(FFMPEG_E_OPENCODECFAILED);</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_pFrame = avcodec_alloc_frame();</font></div><div><font face="courier new, monospace"> if (!m_pFrame)</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>RET(FFMPEG_E_ALLOCFRAMEFAILED);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>int picSize = avpicture_get_size(m_pCodCtx->pix_fmt, m_pCodCtx->width, m_pCodCtx->height);</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_pFrame->format = m_pCodCtx->pix_fmt;</font></div><div>
<font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_pFrame->width = m_pCodCtx->width;</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_pFrame->height = m_pCodCtx->height;</font></div>
<div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>if (!(pOutFmt->flags & AVFMT_NOFILE)) </font></div><div>
<font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>{</font></div><div><font face="courier new, monospace"> m_lastErrNum = avio_open(&m_pFmtCtx->pb, fName, AVIO_FLAG_WRITE);</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>if (m_lastErrNum < 0)</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>RET(FFMPEG_E_CREATEFILEFAILED);</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>}</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_lastErrNum = avformat_write_header(m_pFmtCtx, NULL);</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>if (m_lastErrNum < 0)</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>{</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>avio_close(m_pFmtCtx->pb);</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>RET(FFMPEG_E_WRITEFILEFAILED);</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>}</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>DBGPRINT(_T("CFFMPEGVideoLoadEngine::CreateFile succeeded"));</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>return S_OK;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">failed:</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>DBGPRINT(_T("CFFMPEGVideoLoadEngine::OpenFile failed (exit code %x)"), res);</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>FreeResources();</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>return res;</font></div>
<div><font face="courier new, monospace">}</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">HRESULT __stdcall CFFMPEGVideoStoreEngine::WriteFrame(void* pData, int len)</font></div>
<div><font face="courier new, monospace">{</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>DBGPRINT(_T("CFFMPEGVideoStoreEngine::WriteFrame called"));</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>HRESULT res;</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"> AVPacket pkt;</font></div><div><font face="courier new, monospace"> int got_output;</font></div><div><font face="courier new, monospace"><br></font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>avpicture_fill((AVPicture*) m_pFrame, (uint8_t*) pData, m_pCodCtx->pix_fmt, m_pCodCtx->width, m_pCodCtx->height);</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>av_init_packet(&pkt);</font></div><div><font face="courier new, monospace"> pkt.data = NULL; // packet data will be allocated by the encoder</font></div>
<div><font face="courier new, monospace"> pkt.size = 0;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_lastErrNum = avcodec_encode_video2(m_pCodCtx, &pkt, m_pFrame, &got_output);</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>if (m_lastErrNum < 0)</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>RET(FFMPEG_E_ENCODEFAILED);</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> if (got_output) </font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>{</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>pkt.pts = pkt.dts = m_cnt++;</font></div><div><span class="Apple-tab-span" style="font-family:'courier new',monospace;white-space:pre"> </span><span style="font-family:'courier new',monospace">if (m_pCodCtx->coded_frame->key_frame)</span></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>pkt.flags |= AV_PKT_FLAG_KEY;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>pkt.stream_index = m_pStream->index;</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>m_lastErrNum = av_write_frame(m_pFmtCtx, &pkt);</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>if (m_lastErrNum < 0)</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>RET(FFMPEG_E_WRITEFILEFAILED);</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>av_free_packet(&pkt);</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>}</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>DBGPRINT(_T("CFFMPEGVideoLoadEngine::WriteFrame succeeded"));</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>return S_OK;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">failed:</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>DBGPRINT(_T("CFFMPEGVideoLoadEngine::WriteFrame failed (exit code %x)"), res);</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>return res;</font></div><div><font face="courier new, monospace">}</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">HRESULT __stdcall CFFMPEGVideoStoreEngine::CloseFile()</font></div><div><font face="courier new, monospace">{</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>DBGPRINT(_T("CFFMPEGVideoStoreEngine::CloseFile called"));</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>// Close file</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>av_write_trailer(m_pFmtCtx);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>if (!(m_pFmtCtx->oformat->flags & AVFMT_NOFILE)) </font></div>
<div><font face="courier new, monospace"> avio_close(m_pFmtCtx->pb);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>FreeResources();</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>DBGPRINT(_T("CFFMPEGVideoLoadEngine::CloseFile succeeded"));</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>return S_OK;</font></div><div><font face="courier new, monospace">}</font></div><div><br></div><div><br></div><br>
</div>