diff -ur dvbcut/SConstruct dvbcut-wg/SConstruct
--- dvbcut/SConstruct	Sat Jul 28 12:58:00 2007
+++ dvbcut-wg/SConstruct	Sat Jul 28 15:43:29 2007
@@ -117,6 +117,9 @@
   env.Append(CPPPATH=os.path.join(str(ffmpegpath),'include'))
   env.Append(LIBPATH=os.path.join(str(ffmpegpath),'lib'))
 env.Append(LIBS=['avformat','avcodec','avutil'])
+if (localffmpeg==False):
+  env.Append(CPPDEFINES=["__STDC_CONSTANT_MACROS", "__STDC_LIMIT_MACROS"])
+
   
 ###### WORK
 
diff -ur dvbcut/src/avframe.h dvbcut-wg/src/avframe.h
--- dvbcut/src/avframe.h	Sat Jul 28 12:57:53 2007
+++ dvbcut-wg/src/avframe.h	Sat Jul 28 15:43:29 2007
@@ -21,7 +21,9 @@
 #ifndef _DVBCUT_AVFRAME_H
 #define _DVBCUT_AVFRAME_H
 
+extern "C" {
 #include <ffmpeg/avcodec.h>
+}
 
 class QImage;
 
diff -ur dvbcut/src/lavfmuxer.cpp dvbcut-wg/src/lavfmuxer.cpp
--- dvbcut/src/lavfmuxer.cpp	Sat Jul 28 12:57:53 2007
+++ dvbcut-wg/src/lavfmuxer.cpp	Sat Jul 28 16:30:40 2007
@@ -18,8 +18,10 @@
 
 /* $Id: lavfmuxer.cpp 58 2007-07-23 07:03:07Z too-tired $ */
 
+extern "C" {
 #include <ffmpeg/avformat.h>
 #include <ffmpeg/avcodec.h>
+}
 #include <string.h>
 #include <utility>
 #include <list>
@@ -29,10 +31,6 @@
 
 #include <stdio.h>
 
-#if LIBAVCODEC_VERSION_INT < (51 << 16)
-#define liba52_decoder ac3_decoder
-#endif
-
 lavfmuxer::lavfmuxer(const char *format, uint32_t audiostreammask, mpgfile &mpg, const char *filename)
     : muxer(), avfc(0), fileopened(false)
   {
@@ -87,8 +85,7 @@
 
 	if (sd->getitemlistsize() > 1) {
 	  if (!avcodec_open(s->codec,
-			    (mpg.getstreamtype(astr)==streamtype::ac3audio) ?
-			    &liba52_decoder : &mp2_decoder)) {
+			    avcodec_find_decoder(s->codec->codec_id))) {
 	    int16_t samples[6*1536]; // must be enough for 6 AC-3 channels --mr
 	    int frame_size=sizeof(samples);
 	    //fprintf(stderr, "** decode audio size=%d\n", sd->inbytes());
diff -ur dvbcut/src/lavfmuxer.h dvbcut-wg/src/lavfmuxer.h
--- dvbcut/src/lavfmuxer.h	Sat Jul 28 12:57:53 2007
+++ dvbcut-wg/src/lavfmuxer.h	Sat Jul 28 16:00:22 2007
@@ -21,7 +21,10 @@
 #ifndef _DVBCUT_LAVFMUXER_H
 #define _DVBCUT_LAVFMUXER_H
 
+extern "C" {
 #include <ffmpeg/avformat.h>
+}
+
 #include "mpgfile.h"
 #include "muxer.h"
 
diff -ur dvbcut/src/main.cpp dvbcut-wg/src/main.cpp
--- dvbcut/src/main.cpp	Sat Jul 28 12:57:53 2007
+++ dvbcut-wg/src/main.cpp	Sat Jul 28 15:43:29 2007
@@ -30,7 +30,9 @@
 #endif // HAVE_LIB_AO
 
 #include <qapplication.h>
+extern "C" {
 #include <ffmpeg/avformat.h>
+}
 #include <qimage.h>
 #include <qsettings.h>
 #include "dvbcut.h"
diff -ur dvbcut/src/mpgfile.cpp dvbcut-wg/src/mpgfile.cpp
--- dvbcut/src/mpgfile.cpp	Sat Jul 28 12:57:53 2007
+++ dvbcut-wg/src/mpgfile.cpp	Sat Jul 28 16:21:46 2007
@@ -238,6 +238,24 @@
   }
 }
 
+void mpgfile::initcodeccontexts(int vid)
+{
+  if (vid>=0) {
+    videostreams=1;
+    stream *S=&s[VIDEOSTREAM];
+    S->id=vid;
+    S->allocavcc();
+    S->avcc->codec_type=CODEC_TYPE_VIDEO;
+    S->avcc->codec_id=CODEC_ID_MPEG2VIDEO;
+    S->dec=avcodec_find_decoder(CODEC_ID_MPEG2VIDEO);
+    S->enc=avcodec_find_encoder(CODEC_ID_MPEG2VIDEO);
+    S->type=streamtype::mpeg2video;
+    }
+
+  for (int i=0;i<audiostreams;++i)
+    initaudiocodeccontext(i);
+}
+
 #ifdef HAVE_LIB_AO
 void mpgfile::playaudio(int aud, int picture, int ms)
 {
diff -ur dvbcut/src/mpgfile.h dvbcut-wg/src/mpgfile.h
--- dvbcut/src/mpgfile.h	Sat Jul 28 12:57:53 2007
+++ dvbcut-wg/src/mpgfile.h	Sat Jul 28 16:18:29 2007
@@ -21,7 +21,6 @@
 #ifndef _DVBCUT_MPGFILE_H
 #define _DVBCUT_MPGFILE_H
 
-#include <ffmpeg/avcodec.h>
 #include <string>
 #include <vector>
 #include <list>
@@ -143,6 +142,7 @@
 
   void decodegop(int start, int stop, std::list<avframe*> &framelist);
   void initaudiocodeccontext(int aud);
+  void initcodeccontexts(int vid);
   void playaudio(int aud, int picture, int ms);
   void savempg(muxer &mux, int start, int stop, int progresspics=0,
                int progresstotal=0, logoutput *log=0);
diff -ur dvbcut/src/psfile.cpp dvbcut-wg/src/psfile.cpp
--- dvbcut/src/psfile.cpp	Sat Jul 28 12:57:53 2007
+++ dvbcut-wg/src/psfile.cpp	Sat Jul 28 16:24:30 2007
@@ -21,7 +21,6 @@
 #include "psfile.h"
 #include "streamhandle.h"
 #include "stream.h"
-#include <ffmpeg/avcodec.h>
 
 psfile::psfile(inbuffer &b, int initial_offset)
     : mpgfile(b, initial_offset)
@@ -66,8 +65,10 @@
         len=((data[4]<<8)|data[5])+6;
 
     if (sid>=0xe0 && sid<=0xef) {
-      if (vid<0)
+      if (vid<0) {
         vid=sid;
+	streamnumber[vid]=VIDEOSTREAM;
+      }
       inbytes-=len;
       data+=len;
       continue;
@@ -108,22 +109,7 @@
         break;
       }
 
-  if (vid>=0) {
-    videostreams=1;
-    streamnumber[vid]=VIDEOSTREAM;
-    stream *S=&s[VIDEOSTREAM];
-    S->id=vid;
-    S->allocavcc();
-    S->avcc->codec_type=CODEC_TYPE_VIDEO;
-    S->avcc->codec_id=CODEC_ID_MPEG2VIDEO;
-    S->dec=&mpeg2video_decoder;
-    S->enc=&mpeg2video_encoder;
-    S->type=streamtype::mpeg2video;
-    }
-
-
-  for (int i=0;i<audiostreams;++i)
-    initaudiocodeccontext(i);
+  initcodeccontexts(vid);
   }
 
 
diff -ur dvbcut/src/stream.h dvbcut-wg/src/stream.h
--- dvbcut/src/stream.h	Sat Jul 28 12:57:53 2007
+++ dvbcut-wg/src/stream.h	Sat Jul 28 15:43:29 2007
@@ -23,6 +23,10 @@
 
 #include <string>
 
+extern "C" {
+#include <ffmpeg/avcodec.h>
+}
+
 class stream
   {
 protected:
diff -ur dvbcut/src/tsfile.cpp dvbcut-wg/src/tsfile.cpp
--- dvbcut/src/tsfile.cpp	Sat Jul 28 12:57:53 2007
+++ dvbcut-wg/src/tsfile.cpp	Sat Jul 28 16:23:03 2007
@@ -24,8 +24,6 @@
 #include <list>
 #include <utility>
 
-#include <ffmpeg/avcodec.h>
-
 tsfile::tsfile(inbuffer &b, int initial_offset)
     : mpgfile(b, initial_offset)
   {
@@ -71,8 +69,10 @@
         audios.push_back(std::pair<int,int>(sid,pid));
         apid[pid]=true;
         }
-      } else if (vid<0 && ((sid&0xf0)==0xe0)) // mpeg video stream
-      vid=pid;
+      } else if (vid<0 && ((sid&0xf0)==0xe0)) { // mpeg video stream
+	vid=pid;
+	streamnumber[vid]=VIDEOSTREAM;
+      }
     }
   audios.sort();
   for (std::list<std::pair<int,int> >::iterator it=audios.begin();it!=audios.end();++it) {
@@ -92,21 +92,7 @@
       break;
     }
 
-  if (vid>=0) {
-    videostreams=1;
-    streamnumber[vid]=VIDEOSTREAM;
-    stream *S=&s[VIDEOSTREAM];
-    S->id=vid;
-    S->allocavcc();
-    S->avcc->codec_type=CODEC_TYPE_VIDEO;
-    S->avcc->codec_id=CODEC_ID_MPEG2VIDEO;
-    S->dec=&mpeg2video_decoder;
-    S->enc=&mpeg2video_encoder;
-    S->type=streamtype::mpeg2video;
-    }
-
-  for (int i=0;i<audiostreams;++i)
-    initaudiocodeccontext(i);
+  initcodeccontexts(vid);
   }
 
 tsfile::~tsfile()
@@ -209,12 +195,12 @@
     //     else
       {
       if (sid>=0xe0 && sid<0xf0 && sd->header.size()>=payloadbegin+4)
-        if ( *(uint32_t*)(sd->header.c_str()+payloadbegin)==mbo32(0x00000001) )
+        if ( *(uint32_t*)(&sd->header[payloadbegin])==mbo32(0x00000001) )
           ++payloadbegin;
       }
 
     sd->appenditem(filepos_t(sd->nextfilepos,0), std::string(sd->header,6,payloadbegin-6),
-                   sd->header.c_str()+payloadbegin, sd->header.size()-payloadbegin);
+                   &sd->header[payloadbegin], sd->header.size()-payloadbegin);
     returnvalue += sd->header.size()-payloadbegin;
     sd->header.clear();
     return returnvalue;

