Ofxvideorecorder output video not encoding

hi,

i am using ofxVideoRecorder to an encode audio and video from my project. i have augmented the expample project, which works fine. when i use the same code in my project, an empty video file that can not be read is created.

in setup:
vidRecorder.setFfmpegLocation(ofFilePath::getAbsolutePath("/opt/local/bin/ffmpeg"));

fileName = "filename";
fileExt = ".mov"; //i have tried .mp4 as well

ofAddListener(vidRecorder.outputFileCompleteEvent, this, &ofApp::recordingComplete);
bRecording = false;

in update:
if(bRecording){
compositeToVideo.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
vidRecorder.addFrame(compositeToVideo.getPixels());
}

in audio out:
if(bRecording) vidRecorder.addAudioSamples(output, bufferSize, nChannels);

in keyreleased:
if(key == ‘s’){
startAudio = true;
bRecording = true;

    if(bRecording && !vidRecorder.isInitialized()) {
        vidRecorder.setup(fileName + ofGetTimestampString() + fileExt, ofGetWidth(), ofGetHeight(), 30, sampleRate, channels);
        vidRecorder.start();
    }
}

if(key == 'c'){
    bRecording = false;
    vidRecorder.close();
}

i tried to record a video without audio thinking that the code in the audioout was the problem, but i had the same problem.

the exported video files have sizes (i.e. 1.2MB), but can’t be read in quicktime and show as having 0:00 duration in VLC.

last night my console showed that there weren’t enough frames, so i followed the discussion in thi thread:

https://github.com/timscaffidi/ofxVideoRecorder/issues/11#

now, my console reads like this:

[verbose] ofxVideoRecorder: recDelta = -0.0359176. Too many video frames, skipping.

[verbose] ofxVideoRecorder: recDelta = -0.0344671. Too many video frames, skipping.

[verbose] ofxVideoRecorder: recDelta = -0.0400907. Too many video frames, skipping.

[verbose] ofxVideoRecorder: recDelta = -0.0384127. Too many video frames, skipping.

[verbose] ofxVideoRecorder: recDelta = -0.0354195. Too many video frames, skipping.

[verbose] ofxVideoRecorder: recDelta = -0.0337415. Too many video frames, skipping.

[verbose] ofxVideoRecorder: recDelta = -0.0393651. Too many video frames, skipping.

[verbose] ofxVideoRecorder: recDelta = -0.0361459. Too many video frames, skipping.

.
.
.
.
.

[verbose] ofxVideoRecorder: recDelta = -0.0355564. Too many video frames, skipping.

[verbose] ofxVideoRecorder: recDelta = -0.0396828. Too many video frames, skipping.

[verbose] ofxVideoRecorder: recDelta = -0.0395013. Too many video frames, skipping.

[verbose] ofxVideoRecorder: recDelta = -0.0393197. Too many video frames, skipping.

[verbose] ofxVideoRecorder: recDelta = -0.0391382. Too many video frames, skipping.

[verbose] ofxVideoRecorder: recDelta = -0.0361459. Too many video frames, skipping.

not sure what the issue is since the same code i have posted is working in the example i changed. the differences are that the example is recording audio in, not audio out.

thanks in advance for your help.

robot

i think the problem is with my audioout code. do i need to replace the “output” paramter in .addaudiosamples(output, buffersize, channels) with the sample buffer? when i do that, it crashes.

here is my audio code: if(bRecording) vidRecorder.addAudioSamples(&trackBuffer[3][0], bufferSize, nChannels);

my console log is without dropped or skipped frames now, but the .mov files still do not encode, with or without the audio.

i am not sure what changed (since i haven’t changed the code), but it’s working now. i am not sure about the audio or video quality, since both seem to be quite diminished, but at least the video is being encoded. if any one has any suggestions about codecs, i’d be grateful.

cheers,

robot

I dont know what resolution and frame rate you are trying to record, but i had a lot of trouble getting full hD to encode on my machine. In my investigation the pre-compiled ffmpg that you download is very basic, there are other options and libraries you can include when compiling ffmpg from scratch that let you take advantage of cuda and opencl accelerated encoding and a few other tools to optimise recording. Compiling from scratch was a bit of a pain but doable and then you have more options.

hi fresla,

i haven’t tried to record in full hd yet. i wrote that the quality was poor, but it’s more so that the resulting audio and video are distorted, almost warped. i went back to the example and exported 1024 x 720, 1280 x 800 and 1920 x 1080 videos. for the first 2, the video quality is a bit poor, but the audio is fine. for the last, the video is the same, but the audio is distorted.

i am about to look through the available codecs to see if i can find something that works better than the default. can you discuss more about the other options and libraries? and did you use them with the ofxvideorecorder or another process?

thanks for your reply.

cheers,

robot

Quality can be changed with the settings in the addon.

Too many video frames, skipping.

This means you computer cannot keep up with the encoding. You can try to help this out with other additions to ffmpeg or your machine may be too slow for this.

Take a look at this streaming guide but the codec and encoding hints are a good reference (much of the other encoding info is for non real time and not useful). Here is a guide to hardware acceleration.

I did not ever see distortion or artefacts unless the settings I was using were so low…The basic example should give a kind of OK file but not the best quality, you can start from there and increase the bit rate.

Some (many) codecs are optimized for SMPTE formats for encoding and decoding, this means using SMPTE frame sizes like 720576, 1280720, 19201080, you will see better performance and quality at these resolutions than arbitrary sizes like1024720 & 1280*800.

I ended up just using these directly from ffmpg as I was using the decklink option with ffmpg. There should be very little difference in this as the addon does create a pipe to send the video and audio, but otherwise it is just sending commands to ffmpg.

thanks for the link.

i didn’t realize that it was your post from the other thread about ofxviderecorder that i planned to follow today. should i not bother with prores? did you not find it useful?

you mentioned decklink. do you have hardware for that option, or was it implemented only from the sdk and flags?

also, did you set the options using this code? //when i use this, i see no difference in the video quality — still poor, but thr is no audio.

vidRecorder.setVideoCodec("mpeg4");
vidRecorder.setVideoBitrate("800k");
vidRecorder.setAudioCodec("mp3");
vidRecorder.setAudioBitrate("192k");

or using flags in this code (without the streaming)?

vidRecorder.setupCustomOutput(fileName+ofGetTimestampString()+fileExt, ofGetWidth(), ofGetHeight(), 30, sampleRate, channels, “-vcodec mpeg4 -b 1600k -acodec mp2 -ab 128k -f mpegts udp://localhost:1234”);

The setup does the same thing, if you check the set functions you will see it is just adding them together.

In the end I could use proress for higher res and it was better quality, but I could not get always reliable full HD. Your small resolutions may well work fine depending on your computer, definitely worth a try.

sorry, i don’t understand your first sentence…

are you referring to the setup in the ofApp::setup() or the vidRecorder.setup when you say it “does the same thing?” and for the “same thing,” are you referring to the decklink hardware and sdk, or do you mean the prores does the same thing as the decklink?

Sorry, I was only refering to the style of notation for the setup, this function:

vidRecorder.setupCustomOutput();

Essentially does the same thing as these:

vidRecorder.setVideoCodec("mpeg4");
vidRecorder.setVideoBitrate("800k");
vidRecorder.setAudioCodec("mp3");
vidRecorder.setAudioBitrate("192k");

In that all the settings are added together to send in a single command to ffmpg.

i see.

i’ll play around with them and see what happens.

thanks for your time. i’ll post a solution if and when i find one or more questions…

cheers,

robot