Frage

I am rendering a video file from input pictures that come from a 3D engine at runtime (I don't pass an actual picture file, just RGB memory). This works perfectly when outputting MP4 using CODEC_ID_H264 as video codec.

But when I want to create an MPG file using CODEC_ID_MPEG2VIDEO, the resulting file is simply broken. No player can play the video correctly and when I then want to concatenate that MPG with another MPG file, and transform the result MP4 in another step, the resulting .mp4 file has both videos, but many frames from the original MPG video (and only video! Sound works fine) are simply skipped.

At first I thought the MPG -> MP4 conversion was the problem, but then I noticed that the initial MPG, which comes from the video render engine, is already broken, which would speak for broken headers. Not sure if it is the system or sequence headers that are broken, though. Or if it could be something totally different.

If you want to have a look, here is the file: http://www.file-upload.net/download-7093306/broken.mpg.html

Again, the exact same muxing code works perfectly fine when directly creating an MP4 from the video render engine, so I'm pretty sure the input data, swscale(), etc. is correct. The only difference is that CODEC_ID_H264 is used and some additional variables (like qmin, qmax, etc.) are set, which are all specific to H264 so should not have an impact.

Also, neither avformat_write_header nor av_write_trailer report an error.

As an additional info, when viewing the codec data of the MPG in VLC player, it is not able to show the FPS, resolution and format (should show 640x360, 30 fps and 4:2:0 YUV).

I am using a rather new (2-3 months old, maybe) FFmpeg version, which I compiled from sources with MinGW.

Any ideas on how to resolve this would be welcome. Currently, I am out of those :)

War es hilfreich?

Lösung

Alright, the problem was not the avformat_write_header, but that I did not set the PTS value of each written video packet to AV_NOPTS_VALUE.

Once I do set it for each video packet, everything works fine.

I assumed that AV_NOPTS_VALUE was the default, as I never needed to set any special PTS value.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top