[FFmpeg-devel] [PATCH] dnxhd parser and raw de/muxer
Michael Niedermayer
michaelni
Mon Sep 15 14:23:41 CEST 2008
On Mon, Sep 08, 2008 at 02:54:14PM -0700, Baptiste Coudurier wrote:
> Hi,
>
> $subject, to use dnxhd raw essences.
[...]
> Index: libavformat/raw.c
> ===================================================================
> --- libavformat/raw.c (revision 15275)
> +++ libavformat/raw.c (working copy)
> @@ -487,6 +487,15 @@
> }
> #endif
>
> +static int dnxhd_probe(AVProbeData *p)
> +{
> + static const uint8_t header[] = {0x00,0x00,0x02,0x80,0x01};
> + if (!memcmp(p->buf, header, 5))
> + return AVPROBE_SCORE_MAX;
> + else
> + return 0;
> +}
Can more than that be used for a more reliable probe?
I mean yes its 5 bytes but they are all 0 except 3 bits, thus this might
be more common in real files than expected in random data.
[...]
> +typedef struct {
> + ParseContext pc;
> + uint64_t state;
> +} DNXHDParseContext;
> +
> +#define DNXHD_HEADER_PREFIX 0x0000028001
> +
> +static int dnxhd_find_frame_end(DNXHDParseContext *ctx, const uint8_t *buf,
> + int buf_size)
> +{
> + uint64_t state = ctx->state;
> + int pic_found = ctx->pc.frame_start_found;
> + int i = 0;
> +
> + if(!pic_found){
> + for(i = 0; i < buf_size; i++) {
> + state = (state<<8) | buf[i];
> + if((state & 0xffffffffffLL) == DNXHD_HEADER_PREFIX){
> + i++;
> + pic_found = 1;
> + break;
> + }
> + }
> + }
> +
> + if(pic_found){
> + /* EOF considered as end of frame */
> + if (!buf_size)
> + return 0;
> + for(; i < buf_size; i++){
> + state = (state<<8) | buf[i];
> + if((state & 0xffffffffffLL) == DNXHD_HEADER_PREFIX){
> + ctx->pc.frame_start_found=0;
> + ctx->state=-1;
> + return i-4;
> + }
> + }
> + }
> + ctx->pc.frame_start_found = pic_found;
> + ctx->state = state;
> + return END_NOT_FOUND;
> +}
> +
> +static int dnxhd_parse(AVCodecParserContext *s,
> + AVCodecContext *avctx,
> + const uint8_t **poutbuf, int *poutbuf_size,
> + const uint8_t *buf, int buf_size)
> +{
> + DNXHDParseContext *ctx = s->priv_data;
> + int next;
> +
> + if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
> + next= buf_size;
> + }else{
> + next= dnxhd_find_frame_end(ctx, buf, buf_size);
> + if(ff_combine_frame(&ctx->pc, next, &buf, &buf_size) < 0){
> + *poutbuf = NULL;
> + *poutbuf_size = 0;
> + return buf_size;
> + }
> + }
> + *poutbuf = buf;
> + *poutbuf_size = buf_size;
> + return next;
> +}
Iam not sure if this is correct, ff_combine_frame() upates state, but
thats just its 32bit state, it has no knowledge of the 64bit state.
This should lead to problems when DNXHD_HEADER_PREFIX is split accross
2 input frames.
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080915/8afbf7ab/attachment.pgp>
More information about the ffmpeg-devel
mailing list