[Libav-user] help needed on "Encoding .png images with h264 to a file on disk"

laddoe xyfix at hotmail.com
Mon Mar 1 14:11:02 EET 2021


Hi there,

I made some progress and now I can create a 10 MB file in .mp4 or mpeg , that opens in VLC without any warnings and I can see my target. But the file doesn't open in VirtualDub, should I worry ? also the first 12 frames are written to the encoding buffere but not written to the file and that is very disturbing because I need the very first frame.
________________________________
Van: Libav-user <libav-user-bounces at ffmpeg.org> namens laddoe <xyfix at hotmail.com>
Verzonden: vrijdag 26 februari 2021 16:15
Aan: libav-user at ffmpeg.org <libav-user at ffmpeg.org>
Onderwerp: Re: [Libav-user] help needed on "Encoding .png images with h264 to a file on disk"

Can somebody please have a look at my issue, it must be something small that I'm missing. I have posted my code previously, I'm missing a couple of frames in the movie output file and I can't open the movie with VLC , so I tried this:

m_codecCtx->gop_size = 0;

m_codecCtx->max_b_frames = 0;

and now it starts writing to the file from the 13th frame while it was from 26th with my previous code but the file still can't be opened in VLC. I expect in total 120 frames (5 sec at 24 fps ).

I have ran also "recover_mp4.exe on the output video file:

recover_mp4.exe c:\tmp\outputVideo.mp4 result.h264 --noaudio --lav

and got this :

recover_mp4 v1.92 (C) 2011-2017 Dmitry Vasilyev <slydiman at mail.ru>
http://slydiman.me

Writing H264 video file 'result.h264'...
Video format: Invalid AVC Configuration: Version 64
Invalid AVC Configuration: Size 0
Assuming max AVC/HEVC NAL unit size (IDR) 0x3FFFFF, (non IDR) 0xFFFFF
Used AVC templates: LAV/FFMPEG
Cannot open file 'audio.hdr'
Ignoring audio
Audio format: None
Searching 'mdat' atom in 'c:\tmp\outputVideo.mp4'...
mdat (32-bit) payload from 0x30 to 0x928FF9
%0.000
H264: 0x00000030 [0x     272] -> 0x       0 {06 05 FF FF} SEI
H264: 0x000002A2 [0x    4663] -> 0x     272 {65 88 84 17} IDR frame
H264: 0x00004905 [0x    AECE] -> 0x    48D5 {65 88 82 02} IDR frame
H264: 0x0000F7D3 [0x    AD96] -> 0x    F7A3 {65 88 84 0B} IDR frame
H264: 0x0001A569 [0x    AF83] -> 0x   1A539 {65 88 82 02} IDR frame
H264: 0x000254EC [0x    AF6E] -> 0x   254BC {65 88 84 0B} IDR frame
H264: 0x0003045A [0x    AE62] -> 0x   3042A {65 88 82 02} IDR frame
H264: 0x0003B2BC [0x    AF72] -> 0x   3B28C {65 88 84 0B} IDR frame
H264: 0x0004622E [0x    B119] -> 0x   461FE {65 88 82 02} IDR frame
H264: 0x00051347 [0x    AF49] -> 0x   51317 {65 88 84 0B} IDR frame
.....

In total there are 107 IDR frames detected in the movie so I'm missing 13 frames( probablye the 13 mentioned above)

If I open my output video file with virtualdub hexeditor I got this :

[cid:7056d579-cdb1-4275-bf15-96a14e20c86f]
________________________________
Van: Libav-user <libav-user-bounces at ffmpeg.org> namens laddoe <xyfix at hotmail.com>
Verzonden: donderdag 25 februari 2021 15:07
Aan: libav-user at ffmpeg.org <libav-user at ffmpeg.org>
Onderwerp: Re: [Libav-user] help needed on "Encoding .png images with h264 to a file on disk"

Hi Gonzalo, all,

thanks for pointing out what I did wrong. I now get files that are of reasonable sizes 20 MB, something that one would expect. I have added the .h and .cpp file that I have modified according to your feedback and I have also added the .h file for the image class. But the generated videofiles that I get can not be read by VLC or any other application.
When I run "ffmpeg.exe -v error -i c:\tmp\myVideo.mp4 -f null - >error.log 2>&1 " , I get the following error lines multiple times :

[h264 @ 05c0c780] No start code is found.
[h264 @ 05c0c780] Error splitting the input into NAL units.
Error while decoding stream #0:0: Invalid data found when processing input

I have also attached a debug output file that is created by my C++/Qt application in which you'll see which images are send to the encoder. What I don't understand is that the first 26 frames are send to the encoder but not written to the file, I know that the H264 needs some frames before it starts encoding but I would like those frames to be written to the videofile as well.

Your help is greatly appreciated.
________________________________
Van: Libav-user <libav-user-bounces at ffmpeg.org> namens Gonzalo GarramuƱo <ggarra13 at gmail.com>
Verzonden: maandag 22 februari 2021 17:55
Aan: libav-user at ffmpeg.org <libav-user at ffmpeg.org>
Onderwerp: Re: [Libav-user] help needed on "Encoding .png images with h264 to a file on disk"



El 22/2/21 a las 05:25, laddoe escribiĆ³:
can anybody please help me with my post of 2 days ago, I'm really stuck but not able to understand what is wrong. I have also tried several different code examples but it all ends up the same as mentioned in the post. Am I not understanding this ? Are my expectations of the results incorrect? I'm new to this so please bear with me.



One thing that is wrong in your code is that you never call av_write_trailer(), which should be called before avio_close().

Also, there's no need for m_file in your code.  avformat handles the file for you.

Other things are hard to say, as you don't provide the code to the Image or cv::Mat classes.  You should provide a self-compilable example for us to help you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20210301/ed61b555/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 92937 bytes
Desc: image.png
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20210301/ed61b555/attachment.png>


More information about the Libav-user mailing list