[Ffmpeg-devel] Reading video from a buffer

Tomas Christiansson tomas.christiansson
Mon Jan 9 17:17:21 CET 2006


Hi,

We have done this for a MPEG2-PS without changing anything in the
libavformat code, but I guess that won't really matter.

The following code is extracts which we use to parse the MPEG"-stream
into MPEG2 packets which we then decode using avdecode.

// ---------------------------------------------
// First we declare a buffer read funtion (which reads directly from an
mpeg2 compression card).
// This can be replaced by reading from a buffer, make sure not to
return 0 from this function,
// since that will stop the parsing.
int read_function(void * opaque, uint8_t *buf, int buf_size){

	some_struct * data_struct = (some_struct * ) opaque;

	unsigned int data_to_copy = buf_size;
	int t = ReadFromCard(data_struct->board_handle, buf,
&data_to_copy);
	return data_to_copy;
}

// ---------------------------------------------
// init av format stuff

input_format = av_find_input_format("mpeg");
input_format->flags |= AVFMT_NOFILE;
av_packet.data = NULL;

io = new ByteIOContext();

unsigned char * buffer = new unsigned char[ buffer_size ];
int ret = init_put_byte(io, buffer, buffer_size, 0, private_data,
read_function, NULL, NULL);

io->is_streamed = 1;

// open the format context
av_open_input_stream(&format_context, io, "", input_format, NULL);

----------------------------------------------
// then we loop, i.e. read one packet
	
av_packet.pts = AV_NOPTS_VALUE;
while(av_packet.pts == AV_NOPTS_VALUE){
	int res = av_read_frame(format_context, &av_packet);

	if((res == 0)&& (av_packet.pts != AV_NOPTS_VALUE)){
		break;
	}

	// Free packet
	if (av_packet.data != NULL){
		av_free_packet(&av_packet);
		av_packet.data = NULL;
	}
}

----------------------------------------------

regards
Tomas Christiansson

> -----Original Message-----
> From: ffmpeg-devel-bounces at mplayerhq.hu 
> [mailto:ffmpeg-devel-bounces at mplayerhq.hu] On Behalf Of 
> Enrique Estalayo
> Sent: den 9 januari 2006 16:44
> To: FFMpeg development discussions and patches
> Subject: [Ffmpeg-devel] Reading video from a buffer
> 
> 
> 
> Hi,
> 
> I have an MPEG2-TS video in a buffer, but I cannot read it 
> using libavformat. Nevertheless, I've got no problems when I 
> read/decode the same video from a file, so I guess there must 
> be a way to get things working with a buffer instead.
> 
> Anyone could help?
> 
> Enrique.
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> http://mplayerhq.hu/mailman/listinfo/ffmpeg-devel
> 





More information about the ffmpeg-devel mailing list