ofxVideoRecorder icon indicating copy to clipboard operation
ofxVideoRecorder copied to clipboard

ofxVideoRecorder native windows support

Open yty opened this issue 12 years ago • 44 comments

I do not have unistd.h. . .

yty avatar Jul 26 '13 09:07 yty

I've never tried on windows, I'm not sure what the equivalent for unistd.h is, or if it is even possible. It might be simpleer to just use a unix compatibility layer like mingw. If you can figure it out on windows with vs2010 that would be great, and I would gladly pull in your changes.

timscaffidi avatar Aug 14 '13 05:08 timscaffidi

The equivalent for unistd.h in windows is io.h, but it does not have the ioctl function or the FIOBIO. Do we need it? Could anybody adapted it to windows?

Thanks!

juansobral avatar Sep 26 '14 16:09 juansobral

Im seeing that you have TODO: add windows compatable pipe creation (does ffmpeg work with windows pipes?). Could you fix this?

juansobral avatar Sep 26 '14 18:09 juansobral

As I've said, if anyone wants to figure this out, I will gladly pull in changes. Windows support would likely benefit a lot of people, but it is unfortunately very low priority for me personally, and I don't have the time to devote to it right now.

timscaffidi avatar Sep 26 '14 20:09 timscaffidi

This seems to be an approach to deal with the streaming options, (https://trac.ffmpeg.org/ticket/986) I am taking a stab at it to see if I can get it working on windows 8.1 vs 2012. I changed a few things and am able to get it to compile at least but it crashed when starting a recording.

DomAmato avatar Feb 01 '15 02:02 DomAmato

hey,@DomAmato, thanks for the windows update althought it's not fully working yet my case didn't get crashed instead there were some error output avdelta = -0.0333333. too many video frames skipping [fatal] ofThreadErrorLogger ::exception:timeout any ideas?

liquidzym avatar May 01 '15 13:05 liquidzym

Just a wild guess but it sounds like it could be that the audio thread is stalled on an IO wait (which eventually times out), this would also cause the video thread to skip frames. as there is no audio coming in.

timscaffidi avatar May 01 '15 21:05 timscaffidi

I will take a look. How quickly did it throw that error? I was doing short recordings of like < 20 seconds and it worked but I think the audio didn't work properly. I'll do some testing this weekend to see if I can replicate the issue

DomAmato avatar May 01 '15 21:05 DomAmato

from the start actually after pressed the r key, yeah,the audio pipe seems not working at all .\pipe\audiopipe:Invalid argument

thxs for look into it

liquidzym avatar May 02 '15 07:05 liquidzym

ok,i just noticed i have to change setDevice to 3 enable input recording. this time got audio queue size but still got avdelta = -0.0029932 .\pipe\audiopipe:Invalid argument,avdelta = -0.0031746 not enough video frames for desired frame rate.copied this frame 2 times and so on.........

liquidzym avatar May 04 '15 10:05 liquidzym

@liquidzym do you have a branch you with your in-progress code anywhere? I could take a look.

timscaffidi avatar May 04 '15 14:05 timscaffidi

@timscaffidi,sorry,i haven't put any code on github yet,could you please take a look DomAmato's brunch basically i'm just using his contribution,but i can upload it later on tomorrow in case you can help on this cheers

liquidzym avatar May 04 '15 15:05 liquidzym

I think the named pipes arent working properly, I will have to update things. Sorry for the inconvenience but yeah I am getting a similar issue with invalid argument. using pipe: works but its considerably slower than using named pipes

DomAmato avatar May 04 '15 21:05 DomAmato

I pushed a new commit. It fixes things sort of. It can record video or audio but not both. Trying to record both hangs up the pipes (audio will connect video hangs indefinitely). Also spaces in the path name causes a problem but thats actually an easy fix. I just wanted to push an update so that you would have at least something to work with.

DomAmato avatar May 05 '15 04:05 DomAmato

hey,thxs for the update,the video part its working now, do you think any chance can make audio working? btw, i have to change it back to cmd << ffmpegLocation << " -y "; otherwise causing ffmpegffmppeg trouble in cmd not too sure why.

liquidzym avatar May 05 '15 07:05 liquidzym

I changed it so that when you change the ffmpeg location it would run the console command for you but I switched it back now. Audio does work too just not with video. You can do one or the other but not both. I am not sure why but it it will only connect to one pipe, if you try to do both it hangs after connecting to one of the pipes. Not sure why this is

DomAmato avatar May 05 '15 07:05 DomAmato

ok,i see,i added ffmepg to my sys path var maybe that's why. anyway,that's not issue. really need video&audio working together,yes,i saw the audio connect to one pipe succed does ffmpeg record the audio via directshow? much appreciated for the help on this.

liquidzym avatar May 05 '15 08:05 liquidzym

Ffmpeg doesn't handle the devices in this instance. That is handled by openframeworks and audio is dependent on the system. Mostly likely yes the rtaudio or whatever soundstream library you use will connect to direct show since rtaudio only recently supported wasapi. A solution here might be writing a custom script until the pipe situation gets sorted out. U can use ffmpeg to directly connect to a device so u might want to setup a video recording and then add a custom script to connect to the audio device. Not an ideal work around but it should work.

DomAmato avatar May 05 '15 08:05 DomAmato

right,i'll try that thxs,also after googling i found this "ConnectNamedPipe() accepts an inbound connection on a listening named pipe, so that would only work if ffmpeg were calling CreateFile() to connect to the named pipe" http://stackoverflow.com/questions/28476219/how-to-use-win32-pipe-on-single-application guess i have to understand basic pipe stuff,shame on me.

thank you again for the help

liquidzym avatar May 05 '15 13:05 liquidzym

Thats not right. ffmpeg does not have to call createfile() to connect to the pipe.

DomAmato avatar May 05 '15 21:05 DomAmato

http://trac.ffmpeg.org/ticket/1663 Seems to be a known issue

DomAmato avatar May 06 '15 03:05 DomAmato

too bad,what you saying is that i can call the setupCustomOutput method with custom script to connect to the audio?

liquidzym avatar May 06 '15 04:05 liquidzym

if you know what devices you will be using you can connect directly to them using ffmpeg http://www.ffmpeg.org/ffmpeg-devices.html#Input-Devices

the current custom script method needs work and ill expand it to allow for more robust custom scripts

DomAmato avatar May 06 '15 05:05 DomAmato

@DomAmato In the issue you linked to they are using mkfifo, which is a unix command, and it is how ofxVideoRecorder already works on linux and Mac OS. My guess is that, as a few people have commented over there, there is a synchronization issue. In fact I was getting the same issue when originally developing the audio+video feature for this addon. Perhaps windows pipes have a smaller buffer size by default than a fifo pipe in unix. have you tried increasing the buffer size when calling CreateNamedPipe? I see in your branch that you are only using 512 bytes buffer size for each pipe. I would say you should increase those significantly. According to this stack exchange post on unix systems the pipe buffer sizes are anywhere from 16384 to 65536 bytes. I hope this helps

timscaffidi avatar May 06 '15 14:05 timscaffidi

The problem is that it hangs when the second ConnectNamedPipe is called, changing the buffer size changed nothing. I also cant get it working on OSX. FFMpeg starts after the other threads so it never records anything. My guess is that ffmpeg only waits for the first pipe to connect so when it tries to connect the second pipe there is nothing listening and so it hangs. I think a solution might be to run two separate ffmpeg instances and then join the audio and video tracks into one at the end in a final script

DomAmato avatar May 07 '15 01:05 DomAmato

The above method worked. it required separate ffmpeg instances each listening to only 1 pipe. It now creates 2 temporary files and merges them afterwards. it doesnt automatically delete the files though. @liquidzym it should work now. I occasionally get avdelta warnings but i didn't notice anything out of sync. I can't say for longer recordings though.

DomAmato avatar May 07 '15 05:05 DomAmato

wow,thank you so much for this! @DomAmato,i just tried it out,i got three files one is .m4v audio,but the audio file seems not recoding at all,another two video files,one i think should be the video&audio,since the audio file play nothing so still got sound missing,can i ask which version of the ffmpeg you're using?

did you got fully working v merged ideo with sound? also i set my devie as 2 which is mircophone input am i missing something.

sorry,i just noticed that sound stream is missing during the record did you get those error? ffmpeg

liquidzym avatar May 07 '15 07:05 liquidzym

I don't believe u can encode to mp3 which looks like what you are trying to do. By default it records to .m4a so that it is an easy conversion to mp4. delete the line in the code that says .setaudiocodec(".mp3"). I would guess that is what is causing the problem. I tested it and both audio and video recorded and was in sync.

DomAmato avatar May 07 '15 08:05 DomAmato

@DomAmato,haha, its totally working now,got video&sound sync. for 30s, i'll test it for longer time. but for now i only need 30s. thank you so much for the help!

liquidzym avatar May 07 '15 08:05 liquidzym

@DomAmato Why add 1000ms to condition.wait function in your branch ? This will cause pause to timeout.

void ofxAudioDataWriterThread::threadedFunction(){
...
                if (b_written > 0){
                    b_remaining -= b_written;
                    b_offset += b_written;
                }
                else {
                    if (bClose){
                        break; // quit writing so we can close the file
                    }
                }
            }
            bIsWriting = false;
            delete[] frame->data;
            delete frame;
        }
        else{
            condition.wait(conditionMutex, 1000);
        }
    }
....
}

Geistyp avatar May 14 '15 10:05 Geistyp