[FFmpeg-devel] porting from lavc52

"René J.V. Bertin" rjvbertin at gmail.com
Tue Mar 12 23:10:35 CET 2013


A while back I asked some questions on the libav list related to my efforts to extract the libav-based decoding functionality from the Perian project (for QuickTime) and turn it back into a standalone decoder also available for MS Windows.

Perian uses libavcodec-52, libavutil-50 and libavcore-0 for decoding, but with quite a few additions and (apparently) calls to internal functions, so I decided to stick with those versions for the time being. The codec now works (github.com/RJVB/FFusion) and it might be a nice pet project to try and update it to use the current ffmpeg libs.

For that I'd need to understand what and why those additions are for. They appear to extend the parsers and I have seen very similar code in the current ffmpeg (parser) code base which makes me wonder if whatever function they're supposed to add is now included in ffmpeg.

If someone on here (at home in the relevant parts of ffmpeg) feels like having a look and giving some hints, I'd really appreciate it.
Below are a few of my mystery functions (including the only one with extensive comments); they're in bitstream_info.c (https://github.com/RJVB/FFusion/blob/master/bitstream_info.c) .

Thanks! (or not :) )

René



static int parse_mpeg4_extra(FFusionParserContext *parser, const uint8_t *buf, int buf_size)
{
	ParseContext1 *pc1 = (ParseContext1 *)parser->pc->priv_data;
	MpegEncContext *s = pc1->enc;
	GetBitContext gb1, *gb = &gb1;

	pc1->pc.frame_start_found = 0;

	s->avctx = parser->avctx;
	s->current_picture_ptr = &s->current_picture;

	init_get_bits(gb, buf, 8 * buf_size);
	ff_mpeg4_decode_picture_header(s, gb);
	return 1;
}

/*
 * Long story short, FFMpeg's parsers suck for our use.  This function parses an mpeg4 bitstream,
 * and assumes that it is given at least a full frame of data.
 * @param parser A FFusionParserContext structure containg all our info
 * @param buf The buffer to parse
 * @param buf_size Size of the input buffer
 * @param out_buf_size The number of bytes present in the first frame of data
 * @param type The frame Type: FF_*_TYPE
 * @param pts The PTS of the frame
 * @return 1 if a frame is found, 0 otherwise
 */
static int parse_mpeg4_stream(FFusionParserContext *parser, const uint8_t *buf, int buf_size, int *out_buf_size, int *type, int *skippable, int *skipped)
{
	ParseContext1 *pc1 = (ParseContext1 *)parser->pc->priv_data;
	int endOfFrame;
	GetBitContext gb1, *gb = &gb1;
	MpegEncContext *s;

	pc1->pc.frame_start_found = 0;

	endOfFrame = ff_mpeg4_find_frame_end(&(pc1->pc), buf, buf_size);

	s = pc1->enc;

	s->avctx = parser->avctx;
	s->current_picture_ptr = &s->current_picture;

	init_get_bits(gb, buf, 8 * buf_size);
	{ int parse_res = ff_mpeg4_decode_picture_header(s, gb);
		if(parse_res == FRAME_SKIPPED) {
			*out_buf_size = buf_size;
			*type = FF_P_TYPE;
			*skippable = 1;
			*skipped = 1;
		}
		if(parse_res != 0)
			return 0;
	}

	*type = s->pict_type;
	*skippable = (*type == FF_B_TYPE);
	*skipped = 0;

	if(endOfFrame == END_NOT_FOUND)
		*out_buf_size = buf_size;
	else
		*out_buf_size = endOfFrame;
	return 1;
}


#if LIBAVCODEC_VERSION_MAJOR > 52
	extern DLLIMPORT AVCodecParser ff_mpeg4video_parser;
#	define mpeg4video_parser	ff_mpeg4video_parser
#else
	extern DLLIMPORT AVCodecParser mpeg4video_parser;
#endif

static FFusionParser ffusionMpeg4VideoParser = {
	NULL,
	0,
	NULL,
	parse_mpeg4_extra,
	parse_mpeg4_stream,
};



More information about the ffmpeg-devel mailing list