[Libav-user] AVPacket av_malloc av_packet_unref question

2016-08-19 Thread Charles

I have a piece of code that appears to work, that is to say it does stream 
packets..
It goes like this:
av_packet = (AVPacket *) av_malloc( sizeof( AVPacket ) );
while ( 1 ) /// reading in from file out to mpegts
{
   av_read_frame( av_in_fmt_ctx, m_avpacket );
[...]
   ret = av_interleaved_write_frame( av_out_fmt_ctx, av_packet );
   av_packet_unref( av_packet );
}

In the include headers I find this type of verbage ::
 * The side data is always allocated with av_malloc(), copied by
 * av_packet_ref() and freed by av_packet_unref().

From reading the av_read_frame I know the packed is a reference to another 
packet (at least the buf).

Question :
What is av_malloc doing if the packet is getting unref and passed back into 
av_read_frame without another malloc?

Follow Up :
Is this thread safe?

Thanks
cco
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] imgutils.h decode dst buffer going from avpicture_fill to av_image_fill_arrays

2016-08-19 Thread Charles

On 08/19/2016 04:54 AM, ssshukla26 wrote:

For example let suppose "decoder->dst_data[0]" has YUV buffer and its
alignment is 1.

---

//Allocate AVFrame data and linesize

av_image_alloc(avframe->data, avframe->linesize,
decoder->video_resolution.frame_width,
decoder->video_resolution.frame_height,
AV_PIX_FMT_YUV420P, 1);


Below are the 3 methods to fill data array of avframe.

---

//1) if your Y, U, V buffers are contiguous and have the correct size, This
is deprecated
avpicture_fill((AVPicture*) avframe, decoder->dst_data[0], avframe->format,
avframe->width, avframe->height);

---

//2) if your Y, U, V buffers are non-contiguous, This is deprecated
// Initialize avframe->linesize
avpicture_fill((AVPicture*) avframe, NULL, avframe->format, avframe->width,
avframe->height);

//Set avframe->data pointers manually
avframe->data[0] = decoder->dst_data[0];//Y-Buffer
avframe->data[1] = decoder->dst_data[1];//U-Buffer
avframe->data[2] = decoder->dst_data[2];//V-Buffer

---

//3) Fill data array of avframe, as decoder->dst_data[0] alignment is 1 use
the same alignment.
av_image_fill_arrays(avframe->data, avframe->linesize, decoder->dst_data[0],
avframe->format, avframe->width, avframe->height, *1*);



Good explanation.

I figured out #3 yesterday and avoided the deprecated call

  m_out_bufers[ m_buf_idx ] = (uint8_t*) av_malloc( 
av_image_get_buffer_size( AV_PIX_FMT_RGB24,
m_avcodec_ctx->width,
m_avcodec_ctx->height, 
1 ) );
  if ( !m_out_bufers[ m_buf_idx ] )[...]
  av_image_fill_arrays( m_avframeRGB[ m_buf_idx ]->data,
m_avframeRGB[ m_buf_idx ]->linesize,
m_out_bufers[ m_buf_idx ],
AV_PIX_FMT_RGB24,
m_avcodec_ctx->width,
m_avcodec_ctx->height, 1
  );

Can I replace the av_malloc for out_buffers with an input pointer?
size_t required_size = av_image_get_buffer_size( AV_PIX_FMT_RGB24, 
m_avcodec_ctx->width, m_avcodec_ctx->height, 1 );
if ( required_size <= in_buff.size ) m_out_bufers[ m_buf_idx ] = in_buff.data;

Thanks
cco

___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] Suggest how to propery fill incomming AVFrame pointer in a decoder !

2016-08-19 Thread ssshukla26
What is the difference between *av_frame_get_buffer* and *av_image_alloc*
function ?

Cause using anyone of 'em, I am getting the same output !



--
View this message in context: 
http://libav-users.943685.n4.nabble.com/Libav-user-Suggest-how-to-propery-fill-incomming-AVFrame-pointer-in-a-decoder-tp4662417p4662426.html
Sent from the libav-users mailing list archive at Nabble.com.
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] imgutils.h decode dst buffer going from avpicture_fill to av_image_fill_arrays

2016-08-19 Thread ssshukla26
For example let suppose "decoder->dst_data[0]" has YUV buffer and its
alignment is 1.

---

//Allocate AVFrame data and linesize

av_image_alloc(avframe->data, avframe->linesize, 
decoder->video_resolution.frame_width,
decoder->video_resolution.frame_height,
AV_PIX_FMT_YUV420P, 1);


Below are the 3 methods to fill data array of avframe.

---

//1) if your Y, U, V buffers are contiguous and have the correct size, This
is deprecated
avpicture_fill((AVPicture*) avframe, decoder->dst_data[0], avframe->format,
avframe->width, avframe->height);

---

//2) if your Y, U, V buffers are non-contiguous, This is deprecated
// Initialize avframe->linesize
avpicture_fill((AVPicture*) avframe, NULL, avframe->format, avframe->width,
avframe->height);

//Set avframe->data pointers manually
avframe->data[0] = decoder->dst_data[0];//Y-Buffer
avframe->data[1] = decoder->dst_data[1];//U-Buffer
avframe->data[2] = decoder->dst_data[2];//V-Buffer

---

//3) Fill data array of avframe, as decoder->dst_data[0] alignment is 1 use
the same alignment.
av_image_fill_arrays(avframe->data, avframe->linesize, decoder->dst_data[0],
avframe->format, avframe->width, avframe->height, *1*);



--
View this message in context: 
http://libav-users.943685.n4.nabble.com/Libav-user-imgutils-h-decode-dst-buffer-going-from-avpicture-fill-to-av-image-fill-arrays-tp4662419p4662425.html
Sent from the libav-users mailing list archive at Nabble.com.
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user