0

I am new too mpeg2dec and I Have been trying to extract sequence header from a video file with mpeg2.h(from libmpeg2) but not getting anywhere.
I tried by getting STATE_SEQUENCE and tried to point to that location in the file but could not copy that to another file.

#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);
}

In the statement of case STATE_SEQUENCE: instead of returning position, I wanted to write the whole sequence header to the another file. Is that correct or not ?

n0p
  • 3,399
  • 2
  • 29
  • 50
poker
  • 23
  • 5

0 Answers0