<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi everyone,<div><br></div><div>I am using the FFmpeg project's C libraries to decode, modify and then re-encode the frames with new content.</div><div>I need to encode using a codec included in the LGPL version of FFmpeg, as such, I picked "mpeg4". I also need to encode using the MP4 container.<br></div><div>The parts that do the decoding and frame conversions are working as intended, however, I am having an issue with the encoding.  <br></div><div><br></div><div>The issue I am having is that using this combination of video codec and container, there are some issues with the output:</div><div>1- The MP4 file is unreadable from Adobe Premiere, Windows Media Player, Films and TV on Windows 10, and Gnome Totem player to give a few. Only VLC media player is able to play it. There are complaints from ffprobe about damaged MP4 headers.</div><div>2- ffmpeg and ffprobe CLIs themselves will not decode the file's frames, only headers. See attached gist for complete output of ffprobe, but basically the biggest issue is that width/coded_width=0, heigh/coded_height=0 and as such decoding fails. Also, a cryptic warning about "time_increment_bits", and various warnings from the mpeg4 decoder.</div><div><br></div><div>Interestingly, issue 2 only happens when I am using mpeg4 codec, with MP4 container. It does not happen if I use libx264 in a GPL build like Zeranoe build, or use MKV container. Coded_width and such are set in the headers in that case.</div><div>Additionally, when using libx264, I can fix issue 1 by remuxing the .mp4 file with the ffmpeg CLI (ffmpeg -i in.mp4 -c copy out.mp4) and the file can then be read by Premiere, Films and TV etc.. But not when using mpeg4 codec.</div><div><br></div><div>When developing the application, I tried following the examples, seeing how existing projects are using the libraries, and also following the ffmpeg CLI application in the debugger to figure out if it was setting some flag I didn't know I needed to set. I couldn't find the culprit.</div><div>My project is in C++ and as such I made wrapper classes which use the C API, but I made a cut down example in C which shows the issue (attached below).</div><div><br></div><div>I have tested the example has the same issues in the following combinations of platforms/versions:</div><div>- WIndows 10 (MinGW GCC build, shared libs) / Ubuntu 18.04 (GCC build, static libs)</div><div>- FFmpeg versions: Git head, 4.1.0, 4.0.1, 3.4.2</div><div>- Prebuilt Zeranoe build (<a href="https://ffmpeg.zeranoe.com/builds/" target="_blank" class="">https://ffmpeg.zeranoe.com/builds/</a>) in case my build was the culprit.</div><div><br></div><div>There is obviously something I am doing wrong when using the API. Can someone point me in the right direction to fix my issues?</div><div>Here are all the details I can think of that might be useful:</div><div><br></div><div>The source code for my cut down application (encodes 10 seconds of a green AVFrame):</div><div><a href="https://gist.github.com/jamesc2048/7503ec5dc3b46f3e687894b55192b6ff" target="_blank" class="">https://gist.github.com/jamesc2048/7503ec5dc3b46f3e687894b55192b6ff</a><br></div><div><br></div><div>Outputs from ffprobe on MP4 file:</div><div><a href="https://gist.github.com/jamesc2048/bf213c773d5dbcb4f19f22d1cea78ec0" target="_blank" class="">https://gist.github.com/jamesc2048/bf213c773d5dbcb4f19f22d1cea78ec0</a><br></div><div><br></div><div>Output of the application (the video file itself):</div><div><a href="https://drive.google.com/file/d/1hzui9D8ZX1XxqTgP_vGaGjPWBWXefhBr/view?usp=sharing" target="_blank" class="">https://drive.google.com/file/d/1hzui9D8ZX1XxqTgP_vGaGjPWBWXefhBr/view?usp=sharing</a></div><div><br></div><div>FFmpeg compilation flags and details:</div><div><a href="https://gist.github.com/jamesc2048/4463b498277c575198c982c6fd758616" target="_blank" class="">https://gist.github.com/jamesc2048/4463b498277c575198c982c6fd758616</a><br></div><div><br></div><div>Thanks in advance for the help,</div><div><br></div><div>- James </div></div></div></div></div></div></div></div></div>