aboutsummaryrefslogtreecommitdiff
blob: eb7b71c5ec9e42b7633ef181bf20b8589f21e9b2 (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
diff -burN VTK5.10.1.old/IO/vtkFFMPEGWriter.cxx VTK5.10.1/IO/vtkFFMPEGWriter.cxx
--- VTK5.10.1.old/IO/vtkFFMPEGWriter.cxx	2013-05-25 01:26:52.768954436 +0200
+++ VTK5.10.1/IO/vtkFFMPEGWriter.cxx	2013-05-25 11:13:53.112672449 +0200
@@ -60,9 +60,6 @@
 
   AVStream *avStream;
 
-  unsigned char *codecBuf;
-  int codecBufSize;
-
   AVFrame *rgbInput;
   AVFrame *yuvOutput;
 
@@ -83,7 +80,6 @@
 
   this->avStream = NULL;
 
-  this->codecBuf = NULL;
   this->rgbInput = NULL;
   this->yuvOutput = NULL;
 
@@ -140,7 +136,7 @@
   strcpy(this->avFormatContext->filename, this->Writer->GetFileName());
 
   //create a stream for that file
-  this->avStream = av_new_stream(this->avFormatContext, 0);
+  this->avStream = avformat_new_stream(this->avFormatContext, NULL);
   if (!this->avStream) 
     {
     vtkGenericWarningMacro (<< "Could not create video stream.");
@@ -199,7 +195,7 @@
     vtkGenericWarningMacro (<< "Codec not found." );
     return 0;
     }
-  if (avcodec_open(c, codec) < 0) 
+  if (avcodec_open2(c, codec, NULL) < 0)
     {
     vtkGenericWarningMacro (<< "Could not open codec.");
     return 0;
@@ -207,15 +203,6 @@
 
   //create buffers for the codec to work with.
 
-  //working compression space
-  this->codecBufSize = 2*c->width*c->height*4; //hopefully this is enough
-  this->codecBuf = new unsigned char[this->codecBufSize];
-  if (!this->codecBuf)
-    {
-    vtkGenericWarningMacro (<< "Could not make codec working space." );
-    return 0;
-    }
-
   //for the output of the writer's input...
   this->rgbInput = avcodec_alloc_frame();
   if (!this->rgbInput)
@@ -316,38 +303,24 @@
     return 0;
     }
 #endif
-
+  AVPacket pkt = { 0 };
+  int got_frame;
 
   //run the encoder
-  int toAdd = avcodec_encode_video(cc, 
-                                   this->codecBuf, 
-                                   this->codecBufSize, 
-                                   this->yuvOutput);
+  int ret = avcodec_encode_video2(cc,
+                                  &pkt,
+                                  this->yuvOutput,
+                                  &got_frame);
 
   //dump the compressed result to file
-  if (toAdd) 
+  if (got_frame)
     {
-    //create an avpacket to output the compressed result
-    AVPacket pkt;
-    av_init_packet(&pkt);
-
-   //to do playback at actual recorded rate, this will need more work    
-    pkt.pts = cc->coded_frame->pts;
-    //pkt.dts = ?; not dure what decompression time stamp should be
-    pkt.data = this->codecBuf;
-    pkt.size = toAdd;
     pkt.stream_index = this->avStream->index;
-    if (cc->coded_frame->key_frame) //treat keyframes well
-      {
-      pkt.flags |= AV_PKT_FLAG_KEY;
-      }
-    pkt.duration = 0; //presentation duration in time_base units or 0 if NA
-    pkt.pos = -1; //byte position in stream or -1 if NA
     
-    toAdd = av_write_frame(this->avFormatContext, &pkt);
+    ret = av_write_frame(this->avFormatContext, &pkt);
     } 
   
-  if (toAdd) //should not have anything left over
+  if (ret < 0) //should not have anything left over
     {
     vtkGenericWarningMacro (<< "Problem encoding frame." );
     return 0;
@@ -373,12 +346,6 @@
     this->rgbInput = NULL;
     }
   
-  if (this->codecBuf)
-    {
-    av_free(this->codecBuf);
-    this->codecBuf = NULL;
-    }
-
   if (this->avFormatContext)
     {          
     if (this->openedFile)
Binary files VTK5.10.1.old/IO/.vtkFFMPEGWriter.cxx.swp and VTK5.10.1/IO/.vtkFFMPEGWriter.cxx.swp differ