title: Extracting sequence header from mpeg video file
body: <p>I am new too <code>mpeg2dec</code> and I Have been trying to extract sequence header from a video file with  <code>mpeg2.h</code>(from <code>libmpeg2</code>) but not getting anywhere.<br>
  I tried by getting <code>STATE_SEQUENCE</code> and tried to point to that location in the file but could not copy that to another file.</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;inttypes.h&gt;
  //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)-&gt;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-&gt;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);
  }
  </code></pre>
  
  <p>In the statement of case <code>STATE_SEQUENCE</code>: instead of returning position, I wanted to write the whole sequence header to the another file. Is that correct or not ?</p>