Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ofxVideoRecorder native windows support #4

Open
yty opened this issue Jul 26, 2013 · 44 comments
Open

ofxVideoRecorder native windows support #4

yty opened this issue Jul 26, 2013 · 44 comments
Labels

Comments

@yty
Copy link

yty commented Jul 26, 2013

I do not have unistd.h. . .

@timscaffidi
Copy link
Owner

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.

@juansobral
Copy link

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
Copy link

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

@timscaffidi
Copy link
Owner

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 timscaffidi reopened this Nov 19, 2014
@timscaffidi timscaffidi changed the title ofxVideoRecorder can work in windows7 and vs2010 do? ofxVideoRecorder native windows support Nov 19, 2014
@DomAmato
Copy link

DomAmato commented Feb 1, 2015

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.

@liquidzym
Copy link

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?

@timscaffidi
Copy link
Owner

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.

@DomAmato
Copy link

DomAmato commented May 1, 2015

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

@liquidzym
Copy link

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
Copy link

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.........

@timscaffidi
Copy link
Owner

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

@liquidzym
Copy link

@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

@DomAmato
Copy link

DomAmato commented May 4, 2015

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
Copy link

DomAmato commented May 5, 2015

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.

@liquidzym
Copy link

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.

@DomAmato
Copy link

DomAmato commented May 5, 2015

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

@liquidzym
Copy link

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.

@DomAmato
Copy link

DomAmato commented May 5, 2015

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.

@liquidzym
Copy link

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

@DomAmato
Copy link

DomAmato commented May 5, 2015

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

@DomAmato
Copy link

DomAmato commented May 6, 2015

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

@liquidzym
Copy link

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

@DomAmato
Copy link

DomAmato commented May 6, 2015

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

@timscaffidi
Copy link
Owner

@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

@DomAmato
Copy link

DomAmato commented May 7, 2015

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
Copy link

DomAmato commented May 7, 2015

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.

@liquidzym
Copy link

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

@DomAmato
Copy link

DomAmato commented May 7, 2015

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.

@liquidzym
Copy link

@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!

@Geistyp
Copy link

Geistyp commented May 14, 2015

@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);
        }
    }
....
}

@DomAmato
Copy link

I actually never tested that so I will do that now

@DomAmato
Copy link

OK i fixed it. I also added a random number generation for the pipe naming so that you can have multiple instances.

@timscaffidi
Copy link
Owner

@DomAmato as far as multiple instances goes, this was already supported. look at the requestPipeNumber and retirePipeNumber functions

@DomAmato
Copy link

I know but i hadn't implemented it in my fork as i was just interested in getting it working. I did see the request and retire functions and ill give them a closer look

@razvanilin
Copy link

Any updates on this issue?

@DomAmato I tried the code in your fork and I can't get it to work. It crashes when I create a simple example using the example code in your fork. If integrate it in my project, I get a file not found on the pipe name.

Seems like there are not so many alternatives to recording a video on windows

@DomAmato
Copy link

Can you tell me what error you get and on what line it crashes. My fork should work. The file not found is probably referring to the location of the compiled ffmpeg application, where do you have that installed?

@haschdl
Copy link

haschdl commented Apr 13, 2016

Hello @DomAmato ! I was able to compile and run your version, however with small modifications, so that in every place you refer to a file path, I added double quotes. This should take care of issues with spaces in the file path.

Another change is that ffmpeg location expects not the "bin" folder, but the complete file path of the ffmpeg.exe file (my Path includes only c:\ffmpeg\bin").

@DomAmato
Copy link

Are you talking about changes made to the example or to the code in the addon source? you alter the path to wherever your ffmpeg version is installed which can include the data folder from OF so long as ffmpeg.exe exists in that location.

@natxopedreira
Copy link

Im using @DomAmato repo for record a ofApp on win 10 and is working great, thank you!!

But i want to know if is possible to get a callback or a flag somewhere to know when the creation of the video has ended ??... like the linux version one does.

@DomAmato
Copy link

There are so many forks now I don't even know the state anymore for windows. Maybe @razvanilin might have an idea? it looks like they extended the work I was doing but it should be possible to have an event once the video is done.

@natxopedreira
Copy link

Thanks, lets see if he knows about and also will be nice to know which fork is the good one for windows..

@razvanilin
Copy link

Unfortunately, I didn't extend the addon more than just adjusted it to work for both MacOS and Windows. Like @DomAmato said, it's definitely possible to create some sort of event that fires when the video creation ends. You can also have a look at ffprobe which reads the metadata of the video.

@natxopedreira
Copy link

Thanks, its a good idea!! i will try using ffprobe to check the video before send an event

@pandevim
Copy link

What is the status of this issue in 2020?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants