从mpeg视频文件中提取序列头

时间:2014-06-11 13:33:06

标签: c mpeg-2

我也是新人mpeg2dec而我一直在尝试使用mpeg2.h(来自libmpeg2)从视频文件中提取序列标题,但却无法获取任何内容。
我尝试获取STATE_SEQUENCE并尝试指向文件中的该位置,但无法将其复制到另一个文件。

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
//mpeg2dec library
#include "mpeg2dec/mpeg2.h"
//jni header
#include "VideoProc.h"

int mpeg2Fun(uint8_t * pointer);
//jni function to get byte array from and return integer
JNIEXPORT jint JNICALL Java_VideoProc_mpeg2FunC(JNIEnv * env, jobject jobj, jbyteArray bytes)
{
    jbyte u_byte[4096] ;
    (*env)->GetByteArrayRegion(env,bytes, 0, 4096, u_byte);

    jint reply=mpeg2Fun(u_byte);

    return reply;
}

int mpeg2Fun(uint8_t * pointer)
{
    mpeg2dec_t * decoder;
    const mpeg2_info_t * info;
    const mpeg2_sequence_t * sequence;
    mpeg2_state_t state;
    size_t size;
    int framenum = 0;

    decoder = mpeg2_init ();
    if (decoder == NULL) {
    fprintf (stderr, "Could not allocate a decoder object.\n");
    exit (1);
    }
    info = mpeg2_info (decoder);

    int t;
    size = (size_t)-1;
    do {
    state = mpeg2_parse (decoder);
    sequence = info->sequence;
    switch (state) {
    case STATE_BUFFER:
        mpeg2_buffer (decoder, pointer, pointer + 4096);
        break;
    case STATE_SEQUENCE:
        t=mpeg2_getpos(decoder);
        return 4096-t;
        break;
    default:
        break;
    }
    } while (size);

    mpeg2_close (decoder);
}

在案例STATE_SEQUENCE的陈述中:我想将整个序列标题写入另一个文件而不是返回位置。这是否正确?

0 个答案:

没有答案