summarylogtreecommitdiffstats
path: root/ffmpeg.patch
blob: 82a6ef80c0cddefa898dcf6b0dc03876164a608d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
diff --git a/gazebo/common/Video.cc b/gazebo/common/Video.cc
--- a/gazebo/common/Video.cc
+++ b/gazebo/common/Video.cc
@@ -15,14 +15,18 @@
  *
 */
 
-#include <gazebo/common/Console.hh>
-#include <gazebo/common/Video.hh>
-#include <gazebo/gazebo_config.h>
-#include <gazebo/common/ffmpeg_inc.h>
+#include "gazebo/gazebo_config.h"
+#include "gazebo/common/Console.hh"
+#include "gazebo/common/Video.hh"
+#include "gazebo/common/ffmpeg_inc.h"
 
 using namespace gazebo;
 using namespace common;
 
+/// \brief Destination audio video frame
+/// TODO Do not merge forward. Declared here for gazebo7 ABI compatibility
+AVFrame *avFrameDst;
+
 /////////////////////////////////////////////////
 // #ifdef HAVE_FFMPEG
 // static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize,
@@ -44,25 +48,17 @@
 {
   this->formatCtx = NULL;
   this->codecCtx = NULL;
-  this->avFrame = NULL;
   this->swsCtx = NULL;
   this->avFrame = NULL;
-  this->pic = NULL;
   this->videoStream = -1;
 
-#ifdef HAVE_FFMPEG
-  this->pic = new AVPicture;
-#endif
+  avFrameDst = NULL;
 }
 
 /////////////////////////////////////////////////
 Video::~Video()
 {
   this->Cleanup();
-
-#ifdef HAVE_FFMPEG
-  delete this->pic;
-#endif
 }
 
 /////////////////////////////////////////////////
@@ -78,7 +74,7 @@
   // Close the codec
   avcodec_close(this->codecCtx);
 
-  avpicture_free(this->pic);
+  av_free(avFrameDst);
 #endif
 }
 
@@ -147,16 +143,13 @@
     return false;
   }
 
-  avpicture_alloc(this->pic, PIX_FMT_RGB24, this->codecCtx->width,
-                  this->codecCtx->height);
-
   this->swsCtx = sws_getContext(
       this->codecCtx->width,
       this->codecCtx->height,
       this->codecCtx->pix_fmt,
       this->codecCtx->width,
       this->codecCtx->height,
-      PIX_FMT_RGB24,
+      AV_PIX_FMT_RGB24,
       SWS_BICUBIC, NULL, NULL, NULL);
 
   if (this->swsCtx == NULL)
@@ -165,20 +158,13 @@
     return false;
   }
 
-  // DEBUG: Will save all the frames
-  /*Image img;
-  char buf[1024];
-  int frame = 0;
-
-  // the decoding loop, running until EOF
-  while (this->GetNextFrame(img))
-  {
-    printf("WH[%d %d]\n",this->codecCtx->width, this->codecCtx->height);
-    snprintf(buf, sizeof(buf), "/tmp/test_%3d.png", frame++);
-    img.SavePNG(buf);
-  }
-  printf("Done\n");
-  */
+  avFrameDst = common::AVFrameAlloc();
+  avFrameDst->format = this->codecCtx->pix_fmt;
+  avFrameDst->width = this->codecCtx->width;
+  avFrameDst->height = this->codecCtx->height;
+  av_image_alloc(avFrameDst->data, avFrameDst->linesize,
+      this->codecCtx->width, this->codecCtx->height, this->codecCtx->pix_fmt,
+      1);
 
   return true;
 }
@@ -226,9 +212,10 @@
       if (frameAvailable)
       {
         sws_scale(swsCtx, this->avFrame->data, this->avFrame->linesize, 0,
-            this->codecCtx->height, this->pic->data, this->pic->linesize);
+            this->codecCtx->height, avFrameDst->data,
+            avFrameDst->linesize);
 
-        memcpy(*_buffer, this->pic->data[0],
+        memcpy(*_buffer, avFrameDst->data[0],
             this->codecCtx->height * (this->codecCtx->width*3));
 
         // Debug:
diff --git a/gazebo/common/Video.hh b/gazebo/common/Video.hh
--- a/gazebo/common/Video.hh
+++ b/gazebo/common/Video.hh
@@ -14,8 +14,8 @@
  * limitations under the License.
  *
 */
-#ifndef _VIDEO_HH_
-#define _VIDEO_HH_
+#ifndef _GAZEBO_COMMON_VIDEO_HH_
+#define _GAZEBO_COMMON_VIDEO_HH_
 
 #include <string>
 #include "gazebo/util/system.hh"
@@ -74,7 +74,7 @@
       /// \brief audio video frame
       private: AVFrame *avFrame;
 
-      /// \brief audi video picture
+      /// \brief audio video picture
       private: AVPicture *pic;
 
       /// \brief software scaling context
diff --git a/gazebo/common/ffmpeg_inc.h b/gazebo/common/ffmpeg_inc.h
--- a/gazebo/common/ffmpeg_inc.h
+++ b/gazebo/common/ffmpeg_inc.h
@@ -31,6 +31,7 @@
 extern "C" {
 #include <libavcodec/avcodec.h>
 #include <libavformat/avformat.h>
+#include <libavutil/imgutils.h>
 #include <libavutil/opt.h>
 #include <libswscale/swscale.h>
 }