[GRASS-SVN] r53882 - grass/branches/develbranch_6/lib/ogsf

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Nov 18 02:27:40 PST 2012


Author: martinl
Date: 2012-11-18 02:27:40 -0800 (Sun, 18 Nov 2012)
New Revision: 53882

Modified:
   grass/branches/develbranch_6/lib/ogsf/gsd_img_mpeg.c
Log:
ogsf: support also older FFMPEG API (see r53854)
      (merge r53880 from trunk)


Modified: grass/branches/develbranch_6/lib/ogsf/gsd_img_mpeg.c
===================================================================
--- grass/branches/develbranch_6/lib/ogsf/gsd_img_mpeg.c	2012-11-18 10:25:46 UTC (rev 53881)
+++ grass/branches/develbranch_6/lib/ogsf/gsd_img_mpeg.c	2012-11-18 10:27:40 UTC (rev 53882)
@@ -5,15 +5,14 @@
 
    GRASS OpenGL gsurf OGSF Library 
 
-   (C) 1999-2008 by the GRASS Development Team
+   (C) 1999-2008, 2012 by the GRASS Development Team
 
-   This program is free software under the 
-   GNU General Public License (>=v2). 
-   Read the file COPYING that comes with GRASS
-   for details.
+   This program is free software under the GNU General Public License
+   (>=v2).  Read the file COPYING that comes with GRASS for details.
 
    \author Bill Brown USACERL, GMSL/University of Illinois
-   \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
+   \author Doxygenized (May 2008) and update for FFMPEG >= 0.7
+   (November 2012) by Martin Landa <landa.martin gmail.com>
  */
 
 #include <stdlib.h>
@@ -59,7 +58,11 @@
     AVCodecContext *c;
     AVStream *st;
 
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52, 100, 0)
+    st = av_new_stream(oc, 0);
+#else
     st = avformat_new_stream(oc, NULL);
+#endif
     if (!st) {
 	G_warning(_("Unable to allocate stream"));
 	return NULL;
@@ -98,12 +101,13 @@
 	c->flags |= CODEC_FLAG_GLOBAL_HEADER;
 
     c->flags |= CODEC_FLAG_QSCALE;
-    /* Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
-       
-       \todo use AVVideoFrame
-       c->global_quality = st->quality = FF_QP2LAMBDA * 10;
-    */
+    
+    /* Quality, as it has been removed from AVCodecContext and put in AVVideoFrame. */
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52, 100, 0)
+    c->global_quality = st->quality = FF_QP2LAMBDA * 10;
+#else
     c->global_quality = FF_QP2LAMBDA * 10;
+#endif
 
     return st;
 }
@@ -164,7 +168,11 @@
     }
 
     /* open the codec */
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52, 100, 0)
+    if (avcodec_open(c, codec) < 0) { 
+#else
     if (avcodec_open2(c, codec, NULL) < 0) {
+#endif
 	G_warning(_("Unable to open codec"));
 	return;
     }
@@ -339,12 +347,20 @@
     }
 
     /* set the output parameters (must be done even if no parameters). */
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52, 100, 0)
+    if (av_set_parameters(oc, NULL) < 0) { 
+#else
     if (avformat_write_header(oc, NULL) < 0) {
+#endif
 	G_warning(_("Invalid output format parameters"));
-	return (-1);
+	return -1;
     }
 
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52, 100, 0)
+    dump_format(oc, 0, filename, 1); 
+#else
     av_dump_format(oc, 0, filename, 1);
+#endif
 
     /* now that all the parameters are set, we can open the audio and
        video codecs and allocate the necessary encode buffers */
@@ -353,21 +369,28 @@
 
     /* open the output file, if needed */
     if (!(fmt->flags & AVFMT_NOFILE)) {
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52, 100, 0)
+        if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) { 
+#else
 	if (avio_open(&oc->pb, filename, AVIO_FLAG_WRITE) < 0) {
+#endif
 	    G_warning(_("Unable to open <%s>"), filename);
 	    return (-1);
 	}
     }
 
     /* write the stream header, if any */
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52, 100, 0)
+    av_write_header(oc);
+#else
     avformat_write_header(oc, NULL);
+#endif
 
-
 #else
-    G_warning(_("NVIZ has not been built with MPEG output support"));
-    return (-1);
+    G_warning(_("OGSF library has not been built with MPEG output support"));
+    return -1;
 #endif
-    return (0);
+    return 0;
 }
 
 /*!
@@ -442,7 +465,13 @@
 
     if (!(fmt->flags & AVFMT_NOFILE)) {
 	/* close the output file */
-	avio_close(oc->pb);
+#if (LIBAVFORMAT_VERSION_INT>>16) < 52
+      url_fclose(&oc->pb);
+#elif LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52, 100, 0)
+      url_fclose(oc->pb);
+#else
+      avio_close(oc->pb);
+#endif 
     }
 
     /* free the stream */
@@ -452,5 +481,5 @@
     G_debug(3, "Closed MPEG stream");
 #endif
 
-    return (0);
+    return 0;
 }



More information about the grass-commit mailing list