如何在OpenFrameworks OF 0.8.4 OSX中将输出帧记录到视频文件中

时间:2015-04-16 11:12:01

标签: c++ macos video ffmpeg openframeworks

您好我试图用它来记录我的openframeworks应用程序的输出。

我试图在这里使用此扩展程序。因为似乎没有内置的方法。

https://github.com/timscaffidi/ofxVideoRecorder

我有它生成一个视频文件,但它看起来像滚动人行道广告之一,帧向上滚动而不是像普通视频一样继续。知道为什么吗?

我在设置方法结束时有这个。

if(!vidRecorder.isInitialized())
{
vidRecorder.setup(fileName+ofGetTimestampString()+fileExt, ofGetWidth(), ofGetHeight(), 30); // no audio

}

现在我把窗口模式设置为全屏幕,并且在输出上给了我扫描线,所以我没有全屏,我得到了我已经提到过的帧,然后我把它设置为640,480而且我得到了更多扫描线。

我在更新循环中使用此代码

ofImage img;
img.grabScreen(0, 0, ofGetWidth(), ofGetHeight());


vidRecorder.addFrame(img.getPixelsRef());

这是ffmpeg输出。

[warning] ofThread: - name: Thread 4 - Calling startThread with verbose is deprecated.
[warning] ofThread: - name: Thread 2 - Calling startThread with verbose is deprecated.
ffmpeg version 2.6.1 Copyright (c) 2000-2015 the FFmpeg developers
  built with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
  configuration: --prefix=/Volumes/Ramdisk/sw --enable-gpl --enable-pthreads --enable-version3 --enable-libspeex --enable-libvpx --disable-decoder=libvpx --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-avfilter --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-filters --enable-libgsm --enable-libvidstab --enable-libx265 --disable-doc --arch=x86_64 --enable-runtime-cpudetect
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, rawvideo, from '/Users/benjgorman/Code/OF_ROOT/addons/ofxTimeline/duplicate_lips/bin/data/ofxvrpipe0':
  Duration: N/A, start: 0.000000, bitrate: 566231 kb/s
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1024x768, 566231 kb/s, 30 tbr, 30 tbn, 30 tbc
Please use -b:a or -b:v, -b is ambiguous
Output #0, mov, to '/Users/benjgorman/Code/OF_ROOT/addons/ofxTimeline/duplicate_lips/bin/data/testMovie2015-04-16-11-21-31-504.mov':
  Metadata:
    encoder         : Lavf56.25.101
    Stream #0:0: Video: mpeg4 (mp4v / 0x7634706D), yuv420p, 1024x768, q=2-31, 800 kb/s, 30 fps, 15360 tbn, 30 tbc
    Metadata:
      encoder         : Lavc56.26.100 mpeg4
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
frame=    9 fps=0.0 q=14.2 size=     861kB time=00:00:00.30 bitrate=23510.3kbits/s    
frame=   19 fps= 18 q=24.8 size=    1330kB time=00:00:00.63 bitrate=17202.4kbits/s    
frame=   31 fps= 20 q=24.8 size=    1864kB time=00:00:01.03 

//

为清晰起见,此处省略了更多帧

//

frame=   87 fps= 16 q=24.8 size=    4349kB time=00:00:02.90 bitrate=12286.0kbits/s    
frame=   95 fps= 16 q=24.8 size=    4704kB time=00:00:03.16 bitrate=12169.1kbits/s    
frame=  103 fps= 16 q=24.8 size=    5061kB time=00:00:03.43 bitrate=12075.1kbits/s    
frame=  111 fps= 16 q=24.8 size=    5415kB time=00:00:03.70 bitrate=11990.0kbits/s    
frame=  118 fps= 15 q=24.8 size=    5726kB time=00:00:03.93 bitrate=11925.3kbits/s    
frame=  130 fps= 16 q=24.8 size=    6261kB time=00:00:04.33 bitrate=11835.3kbits/s    
[rawvideo @ 0x10201e000] Invalid buffer size, packet size 1179648 < expected frame_size 2359296
Error while decoding stream #0:0: Invalid argument
frame=  138 fps= 14 q=24.8 size=    6618kB time=00:00:04.60 bitrate=11785.4kbits/s    
frame=  138 fps= 14 q=24.8 Lsize=    6620kB time=00:00:04.60 bitrate=11788.8kbits/s    
video:6618kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.028923%

这是一个ffmpeg错误吗?或者是否有更好的解决方案。

1 个答案:

答案 0 :(得分:0)

你能提供完整的代码吗?你在使用vidGrabber.update();在更新?

为什么不使用:

<强> ofApp.h

ofVideoGrabber      vidGrabber;
ofxVideoRecorder    vidRecorder;
bool bRecording;
void startRecord();
void stopRecord();

<强> ofApp.c

void ofApp::setup(){
    vidInput = ofPtr<ofQTKitGrabber>( new ofQTKitGrabber() );
    vidGrabber.setGrabber(vidInput);
    vidGrabber.initGrabber(1280, 720);
    vidRecorder.setFfmpegLocation(ofFilePath::getAbsolutePath("ASSETS/ffmpeg"));
}

void ofApp::update(){
    vidGrabber.update();
    if(vidGrabber.isFrameNew()){
        vidRecorder.addFrame(vidGrabber.getPixelsRef());
    }
}

void ofApp::startRecord() {

    bRecording = true;

    if(bRecording && !vidRecorder.isInitialized()) {

        vidRecorder.setup("your-file-name.mp4", vidGrabber.getWidth(), vidGrabber.getHeight(), 30, 44100, 2);

    }

}
//--------------------------------------------------------------
void ofApp::stopRecord() {

    bRecording = false;

    vidRecorder.close();

}