summaryrefslogtreecommitdiff
path: root/rotord/ofxMovieExporter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/ofxMovieExporter.cpp')
-rwxr-xr-x[-rw-r--r--]rotord/ofxMovieExporter.cpp35
1 files changed, 22 insertions, 13 deletions
diff --git a/rotord/ofxMovieExporter.cpp b/rotord/ofxMovieExporter.cpp
index eae289c..e8a53e6 100644..100755
--- a/rotord/ofxMovieExporter.cpp
+++ b/rotord/ofxMovieExporter.cpp
@@ -88,7 +88,7 @@
inW=outW;
inH=outH;
-
+
convertCtx = sws_getContext(inW, inH, PIX_FMT_RGB24, outW, outH, PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);
allocateMemory();
@@ -134,7 +134,7 @@ inH=outH;
lastFrameTime = 0;
frameNum = 0;
recording = true;
-
+
return true;
}
@@ -158,7 +158,7 @@ inH=outH;
inW = w;
inH = h;
usePixelSource = true;
-
+
// resetup encoder etc
setup(outW, outH, bitRate, frameRate, codecId, container);
}
@@ -168,7 +168,7 @@ inH=outH;
{
return numCaptures;
}
-
+
void ofxMovieExporter::resetNumCaptures()
{
numCaptures = 0;
@@ -194,10 +194,10 @@ inH=outH;
void ofxMovieExporter::encodeFrame()
{
-
+
avpicture_fill((AVPicture*)inFrame, inPixels, PIX_FMT_RGB24, inW, inH);
avpicture_fill((AVPicture*)outFrame, outPixels, PIX_FMT_YUV420P, outW, outH);
-
+
//perform the conversion for RGB to YUV and size
sws_scale(convertCtx, inFrame->data, inFrame->linesize, 0, inH, outFrame->data, outFrame->linesize);
@@ -208,7 +208,7 @@ inH=outH;
av_init_packet(&pkt);
//pkt.pts = av_rescale_q(codecCtx->coded_frame->pts, codecCtx->time_base, videoStream->time_base);
//if(codecCtx->coded_frame->key_frame) pkt.flags |= AV_PKT_FLAG_KEY;
- pkt.pts = frameNum;//ofGetFrameNum();//codecCtx->coded_frame->pts;
+ //pkt.pts = frameNum;//ofGetFrameNum();//codecCtx->coded_frame->pts;
pkt.flags |= AV_PKT_FLAG_KEY;
pkt.dts = pkt.pts;
pkt.stream_index = videoStream->index;
@@ -219,15 +219,20 @@ inH=outH;
frameNum++;
}
- void ofxMovieExporter::encodeFrame(char *pixels)
+ bool ofxMovieExporter::encodeFrame(unsigned char *pixels)
{
-
+
+ if (pixels==nullptr) return false;
+
+ //is it possible to skip the first avpicture_fill?
+
avpicture_fill((AVPicture*)inFrame, pixels, PIX_FMT_RGB24, inW, inH);
avpicture_fill((AVPicture*)outFrame, outPixels, PIX_FMT_YUV420P, outW, outH);
-
+
//perform the conversion for RGB to YUV and size
sws_scale(convertCtx, inFrame->data, inFrame->linesize, 0, inH, outFrame->data, outFrame->linesize);
+
int outSize = avcodec_encode_video(codecCtx, encodedBuf, ENCODED_FRAME_BUFFER_SIZE, outFrame);
if (outSize > 0)
{
@@ -235,7 +240,9 @@ inH=outH;
av_init_packet(&pkt);
//pkt.pts = av_rescale_q(codecCtx->coded_frame->pts, codecCtx->time_base, videoStream->time_base);
//if(codecCtx->coded_frame->key_frame) pkt.flags |= AV_PKT_FLAG_KEY;
- pkt.pts = frameNum;//ofGetFrameNum();//codecCtx->coded_frame->pts;
+ int num=videoStream->time_base.num;
+ int den=videoStream->time_base.den;
+ pkt.pts = (int64_t)frameNum*(frameInterval*(((float)videoStream->time_base.den)/videoStream->time_base.num));//ofGetFrameNum();//codecCtx->coded_frame->pts;
pkt.flags |= AV_PKT_FLAG_KEY;
pkt.dts = pkt.pts;
pkt.stream_index = videoStream->index;
@@ -244,6 +251,8 @@ inH=outH;
av_write_frame(formatCtx, &pkt);
}
frameNum++;
+
+ return true;
}
void ofxMovieExporter::allocateMemory()
@@ -268,7 +277,7 @@ inH=outH;
delete[] inPixels;
inPixels = NULL;
-
+
av_free(inFrame);
av_free(outFrame);
av_free(encodedBuf);
@@ -350,7 +359,7 @@ inH=outH;
options=NULL;
// open codec
//if (
- avcodec_open2(codecCtx, codec,&options);
+ avcodec_open2(codecCtx, codec,&options);
// < 0) ofLog(OF_LOG_ERROR, "ofxMovieExproter: Could not open codec");
}