<div dir="ltr"><div>Hi,</div><div>Currently, I am working on a little Libav example to split a small MP4 video into a PNG sequence.<br></div><div>So far, this is what I have right now:<br></div><div><a href="https://github.com/xtingray/MP4toPNG/blob/main/cutter.c">https://github.com/xtingray/MP4toPNG/blob/main/cutter.c</a></div><div><br></div><div>If you clone the repository on a Unix environment, it's effortless to test the example by running the build.sh script.</div><div>Most of the implementation is working: I load the MP4 input file, split the video into AVFrame variables, and then I use the libpng library to create the PNG files.</div><div>My only problem is that the images generated are misconfigured and gray-colored, just like this one: <br></div><div><a href="https://github.com/xtingray/MP4toPNG/blob/main/output/frame-1.png">https://github.com/xtingray/MP4toPNG/blob/main/output/frame-1.png</a></div><div><br></div><div>I am guessing the error is related to the way I take the AVFrame data and store it for the PNG file, but I am not sure at all:<br></div><div><br></div><div><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container gmail-js-code-nav-container gmail-js-tagsearch-file"><tbody><tr><td id="gmail-LC317" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line">  png_bytep *row_pointers = (png_bytep *) <span class="gmail-pl-c1">malloc</span>(<span class="gmail-pl-k">sizeof</span>(png_bytep) * frame-><span class="gmail-pl-smi">height</span>);</td>
        </tr>
        <tr>
          </tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container gmail-js-code-nav-container gmail-js-tagsearch-file"><tbody><tr><td id="gmail-LC318" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line">    <span class="gmail-pl-k">for</span> (<span class="gmail-pl-k">int</span> y = <span class="gmail-pl-c1">0</span>; y < frame-><span class="gmail-pl-smi">height</span>; y++) {</td>
        </tr>
        <tr>
          </tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container gmail-js-code-nav-container gmail-js-tagsearch-file"><tbody><tr><td id="gmail-LC319" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line">        row_pointers[y] = (png_bytep) (frame-><span class="gmail-pl-smi">data</span>[<span class="gmail-pl-c1">0</span>] + y * frame-><span class="gmail-pl-smi">linesize</span>[<span class="gmail-pl-c1">0</span>]);</td>
        </tr>
        <tr>
          </tr></tbody></table>    }</div><div><span class="gmail_signature_prefix"><br></span></div>I appreciate any hint to fix the error. Thank you!<br><div><span class="gmail_signature_prefix"><br></span></div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>--<br>  Gustav Gonzalez<br>  <a href="mailto:xtingray@gmail.com" target="_blank">xtingray@gmail.com</a><br><br></div></div></div></div>