Sophie

Sophie

distrib > Fedora > 13 > x86_64 > by-pkgid > dcf6716a37784c80cd24e9731ac25766 > files > 16

libdvdnav-devel-4.1.4-0.1.svn1184.fc12.x86_64.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>libdvdnav: A first libdvdnav program</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">


<h1><a class="anchor" id="firstprog">A first libdvdnav program </a></h1><h2><a class="anchor" id="compiling">
Compiling a libdvdnav program</a></h2>
<p>Below is a simple <code>libdvdnav</code> program. Type/copy it and save it into the file 'dvdtest.c'.</p>
<div class="fragment"><pre class="fragment">
#include &lt;stdio.h&gt;
#include &lt;dvdnav/dvdnav.h&gt;
#include &lt;dvdnav/dvdnav_events.h&gt;
#include &lt;sys/types.h&gt;

int main(int argc, char **argv) {
  dvdnav_t *dvdnav;
  int finished, len, event;
  uint8_t buf[2050];

  /* Open the DVD */
  dvdnav_open(&amp;dvdnav, "/dev/dvd");

  fprintf(stderr, "Reading...\n");
  finished = 0;
  while(!finished) {
    int result = dvdnav_get_next_block(dvdnav, buf,
                                       &amp;event, &amp;len);

    if(result == DVDNAV_STATUS_ERR) {
      fprintf(stderr, "Error getting next block (%s)\n",
              dvdnav_err_to_string(dvdnav));
      exit(1);
    }

    switch(event) {
     case DVDNAV_BLOCK_OK:
        /* Write output to stdout */
        fwrite(buf, len, 1, stdout);
      break;
     case DVDNAV_STILL_FRAME:
       {
        fprintf(stderr, "Skipping still frame\n");
        dvdnav_still_skip(dvdnav);
       }
      break;
     case DVDNAV_STOP:
       {
        finished = 1;
       }
     default:
      fprintf(stderr, "Unhandled event (%i)\n", event);
      finished = 1;
      break;
    }
  }

  dvdnav_close(dvdnav);

  return 0;
}
</pre></div><p>If you have correctly installled <code>libdvdnav</code>, you should have the command 'dvdnav-config' in your path. If so you can compile this program with </p>
<div class="fragment"><pre class="fragment">
  gcc -o dvdtest dvdtest.c `dvdnav-config --cflags --libs`
</pre></div><p>If all goes well, this should generate the 'dvdtest' program in your current working directory. You can now start saving a MPEG 2 stream directly off your DVD with </p>
<div class="fragment"><pre class="fragment">
  ./dvdtest 2&gt;error.log &gt;out.mpeg
</pre></div><p>If the command fails, check the error.log file for details.</p>
<h2><a class="anchor" id="walkthrorugh">
Line-by-line walk through</a></h2>
<div class="fragment"><pre class="fragment">
 include &lt;stdio.h&gt;
 include &lt;dvdnav/dvdnav.h&gt;
 include &lt;dvdnav/dvdnav_events.h&gt;
 include &lt;sys/types.h&gt;
</pre></div><p>These lines include the necessary headers. Almost all <code>libdvdnav</code> programs will only need to include the dvdnav.h and dvdnav_events.h header files from the dvdnav directory.</p>
<div class="fragment"><pre class="fragment">
 dvdnav_open(&amp;dvdnav, "/dev/dvd");
</pre></div><p>The <code>libdvdnav</code> uses <code>libdvdread</code> for its DVD I/O. <code>libdvdread</code> accesses the DVD-device directly so dvdnav_open() needs to be passed the location of the DVD device. <code>libdvdread</code> can also open DVD images/mounted DVDs. Read the <code>libdvdread</code> documentation for more information.</p>
<div class="fragment"><pre class="fragment">
 int result = dvdnav_get_next_block(dvdnav, buf,
                                    &amp;event, &amp;len);
</pre></div><p>Return to <a class="el" href="tutorial.html">A libdvdnav Tutorial</a>. </p>
</div>
<hr size="1"/><address style="text-align: right;"><small>Generated on 26 Sep 2009 for libdvdnav by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>