Akagi201 / ffmpeg-muxer

Mux a video bitstream and a audio bitstream together into one file based on FFmpeg
GNU General Public License v2.0
19 stars 11 forks source link

bitstream filter possible leak #1

Open greg-sokol opened 7 years ago

greg-sokol commented 7 years ago

Hi Akagi201,

I tend to be a lazy coder, so I occasionally look at other people's code to see how stuff should be done. I looked at how you used a bitstream filter h264_mp4toannexb in your code. I must say I had written a couple of bitstream converters between ISO and annexb but this time I wanted to use the stock ffmpeg filter. And my valgrind was not very pleased with how I used h264_mp4toannexb, which was exactly as you did. I mean, there was a huge leak, all of the incoming packet data leaked while being converted to annexb. ffmpeg is way too poorly documented so I often look into its code to see how it really works, because documentation is so scarce. So I came up with this:

instead of simply calling av_bitstream_filter_filter(h264bsfc, in_stream->codec, NULL, &pkt.data, &pkt.size, pkt.data, pkt.size, 0);

which will allocate a new buffer and place it in pkt.data, while leaking the original buffer stored in pkt.data, I wrote this:

uint8_t* outBuf = NULL; int outBufSize = 0; av_bitstream_filter_filter(h264bsfc, in_stream->codec, NULL, &outBuf, &outBufSize, pkt.data, pkt.size, 0); av_free_packet(&pkt); av_packet_from_data(&pkt, outBuf, outbufSize);

No more complaints from valgrind now. The leak is gone.

Cheers Greg

abc1225 commented 7 years ago

hi! friends thks for your remind!

Lao-Bee commented 6 years ago

this code is copied !!! the source code address is https://blog.csdn.net/leixiaohua1020/article/details/39802913