Hello libav users.

I'm a writing to hopefully expedite my task of eliminating a memory leak and 
assert0 crash when remuxing AVPackets.

I used the remuxing example at 
https://ffmpeg.org/doxygen/2.8/remuxing_8c-example.html as a reference for 
writing my code.

The remux example was a great help to me, but it only opens an input file, 
reads the AVPackets out, and writes these AVPackets to an output file and then 
exists.
My code opens an RTSP input URL, continuously reads H.264 AVPackets from the 
RTSP input, and writes these unmodified H.264 AVPackets out to an MP4 file with 
a fixed duration of 30 seconds.  This means after writing out 30 seconds worth 
of AVPackets, I close only the AVFormatContext for the MP4 output file and I 
leave the RTSP input open so I don't miss reading any frames from the camera.  
I then open a new AVFormatContext for the next 30 second MP4 clip and continue 
writing out the H.264 AVPackets from the RTSP input.

Unfortunately, every time I open/close an MP4 output file, a memory leak occurs 
amounting to 250KB.  I don't know if this memory leak occurs in the remuxing 
example because the remuxing example code closes both the input and output and 
exits thereby eliminating any memory leaks when the OS terminates the process.

To get my code to run without crashing, I had to comment out a section of code 
that calls int attribute_align_arg avcodec_encode_video2(...) where it passes 
in NULL AVFrame's and then calls libffmpeg::av_interleaved_write_frame() to 
apparently flush any/all delayed AVPackets.  The AVPacket (for flushing) is 
initialized with .size = 0 and .data = NULL, before calling 
avcodec_encode_video2().

The crash (when running the flush code) occurs in avcodec_encode_video2() 
within libavcodec/utils.c  when the following assert0 is called:
av_assert0(avctx->codec->encode2);

Apparently the input AvCodecContext does not contain an encoding AvCodec.

The avctx and codec are created the same way as the remuxing example as follows:
data->VideoStream = libffmpeg::avformat_new_stream(data->FormatContext, 
pRtspInputAvCodecContext->codec);
              ret = avcodec_copy_context(data->VideoStream->codec, 
pRtspInputAvCodecContext);
              if (ret < 0)
              {
                     fprintf(stderr, "Failed to copy context from input to 
output stream codec context\n");
              }
              else
              {
                     data->VideoStream->codec->codec_tag = 0;
                     if (data->FormatContext->oformat->flags & 
AVFMT_GLOBALHEADER)
                     {
                           data->VideoStream->codec->flags |= 
CODEC_FLAG_GLOBAL_HEADER;
                     }
              }

Does anyone know if flushing is required to eliminate the memory leak and if 
so, then how do I get flushing to work without running into the assert0 as 
described above?

Thank you,
Jeff Mueller
Senior Systems Engineer
[Beveled Wi-Tronix logo no shadow]
631 E Boughton Rd, Suite 240 | Bolingbrook, IL 60440-3455 | 
[email protected]<mailto:[email protected]> | Directions & 
Map<http://goo.gl/maps/WgZCJ>
[https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcS9ii3VxAces63_UOaGvunLMLuIVzGCeDLCZaJyWXYeUPh18S7ESw]
 (630) 679-9927 Ext. xxx | 
[http://cpanelcloudvps.com/wp-content/uploads/2013/12/cell-phone-logo-pnghs-enterprises-9fttttbq.png]
  (847) xxx-xxxx | Toll Free: (888) WI-TRONIX (948-7664) | 
[http://png-1.findicons.com/files/icons/1580/devine_icons_part_2/128/printer_and_fax.png]
  (630) 679-9954

 [cid:[email protected]] 
<https://www.facebook.com/pages/Wi-Tronix/167958306554722>  
[cid:[email protected]] <https://twitter.com/WiTronix>   
[cid:[email protected]] 
<http://www.linkedin.com/company/wi-tronix-llc?trk=cp_followed_name_wi-tronix-llc>
CONFIDENTIALITY NOTICE
This email and any attached files are confidential, protected by copyright and 
may be legally privileged.  If you are not the intended addressee or have 
received the e-mail in error, any use of this e-mail or any copying, 
distribution or other dissemination of it is strictly prohibited. If you have 
received this transmission in error, please notify the sender immediately and 
then delete the e-mail. E-mail cannot be guaranteed to be secure, error free or 
free from viruses. Wi-Tronix, LLC and its affiliates  do not accept any 
liability whatsoever for any loss or damage which may be caused as a result of 
the transmission of this message by e-mail. If verification is required, please 
request a hard copy version.

_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to