I've written a very simple front end for ffmpeg (converting stuff: video -> mp3) in GTK3.0/C for linux. For spawning ffmpeg I use g_spawn_async_with_pipes(). I thought this was the right way to execute stuff like that without having the GUI freeze up - but it does though. So - how can I prevent it from freezing - so I can f.e. display a spinner?
You might need to add something like"
while (gtk_events_pending ()) {
gtk_main_iteration_do (FALSE);
}
That is, to let GTK process the pending events (like drawing the UI).
I suppose you are processing the output of ffmpeg with g_io_add_watch
or similar.
Related
I'm trying to make a C application that closes another console application by sending Control + C to it but my code doesn't always seem to work. The program I am trying to shutdown with Control + C is a game server process.. The only way to shut it down is by pressing Control + C. I want to avoid using TerminateProcess because the program does some form of cleanup code when Control + C is pressed and I'm afraid TerminateProcess will corrupt its database files. According to all the research I've done, GenerateConsoleCtrlEvent is the right function to simulate Control + C but it is not working.
Here is my code:
FreeConsole();
if(AttachConsole(dwProcessID))
{
SetConsoleCtrlHandler(NULL, TRUE);
if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0))
return;
FreeConsole();
if (WaitForSingleObject(hProcess, 30000) == WAIT_TIMEOUT)
{
Log("The process did not terminate on its own.");
}
}
// output: The process did not terminate on its own.
The above code is only partially working.. I know this because it causes the console app to spit out information about drivers shutting down but it wont proceed with the full cleanup & shutdown code. Why isn't my code working? Also, FreeConsole is causing my own console to disappear although it still runs in the background. Is there a function I can call to get it back?
I want to do Text-to-speech with many voices in many languages.
I tried SpeechSynthesizer (Ref: System.Speech) but it only allows 2 English voices. After installing 6 English voices from Microsoft site, I still cannot get any other voices.
I changed to SpVoice (Ref: Microsoft Speech Object Library). SpVoice can recognize 6 voices I just installed. The problem is when I call spVoice.Pause(), it always delay 0.5 second before it stops speaking completely. I also tried to set AlertBoundary for SpVoice but it didn't help.
SpeechSynthesizer can pause right away with SpeakAsyncCancelAll but only works with default voices.
Basically,the Pause method pauses the voice at the nearest alert boundary and closes the output device, allowing it to be used by other voices.
spVoice.Speak() method can be called synchronously or asynchronously. When called synchronously, the method does not return until the text has been spoken; when called asynchronously, it returns immediately, and the voice speaks as a background process.
I hope you are calling spVoice.Speak() synchronously. Thats why you are getting this issue. So use asynchronous method instead of synchronous,your problem should be solved. Then spVoice.Pause() will pause immediately.
SpVoice spVoice = new SpVoice ();
spVoice.Speak ("Testing spVoice",SpeechVoiceSpeakFlags.SVSFlagsAsync);
//......
spVoice.Pause();
using this code example (dranger - ffmpeg):
https://github.com/arashafiei/dranger-ffmpeg-tuto/blob/master/tutorial03.c
and dranger tutorial for ffmpeg:
http://dranger.com/ffmpeg/tutorial02.html
The video runs as fast as possible but it makes sense because there is no timer and we just extract the frames as soon as we have them ready. But for some reason, the sound also runs as fast as possible even though he says that it shouldn't.
I'm using mac os x (Maybe that has something to do with it).
Any suggestions?
Try adding:
aCodecCtx = pFormatCtx->streams[audioStream]->codec;
> aCodecCtx->request_sample_fmt = AV_SAMPLE_FMT_S16;
I am coding an app in C for windows using openCV. I want to capture video from the webcam and show it in a window.
The app is almost finished but it doesn't work properly. I think it's because of the cvQueryFrame() that alwasy returns NULL and I don't know why. I tried capturing some frames before going into the while but didn't fix the problem.
The compiler doesn't show me any error. It's not a compiling problem but an execution one. I debugged it step by step and in the line
if(!originalImg) break;
it allways jumps out of the while. That's why the app doesn't remain in execution. It opens and closes very fast.
Here's the code:
void main()
{
cvNamedWindow("Original Image", CV_WINDOW_AUTOSIZE);
while (1)
{
originalImg = cvQueryFrame(capture);
if(!originalImg) break;
cvShowImage("Original Image", originalImg);
c = cvWaitKey(10);
if( c == 27 ) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("Original Image");
}
Let's see if someone have some idea and can help me with this, thanks!
Assuming the compilation was ok (included all relevant libraries), it may be that the camera has not been installed properly. Can you check if you are able to use the webcam otherwise (using some other software)
If the compilation is actually the issue, please refer to the following related question:
https://stackoverflow.com/a/5313594/1218748
Quick summary:
Recompile opencv_highgui changing the "Preprocesser Definitions" in the C/C++ panel of the properties page to include: HAVE_VIDEOINPUT HAVE_DSHOW
There are other good answers that raise some relvant good points, but my gut feeling is that the above solution would work :-)
It seems you have not opened capture.
Add in the beginning of main:
CvCapture* capture = 0;
capture = cvCaptureFromCAM(0);
I am trying a program in c that controls keyboard handler to blink NUMLOCK & CAPSLOCK LED's as a reaction of ctrl+alt+del push... please help me..
I kinda agree with KP. This is funny...
But if yer serious...
First:
There's a setleds program that might help you get started. It's been around for ages... Try man setleds.
Also, xset can be used (under X-windows) to change leds... (You may have to see which leds are enabled for changing in the X-config file.)
Second:
Detecting ctrl+alt+del is more of an issue as it's flagged specially by init. Look in /etc/inittab or /etc/init/control-alt-delete.conf or someplace like that, and you'll see lines like:
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -h now
Or:
# control-alt-delete - emergency keypress handling
#
# This task is run whenever the Control-Alt-Delete key combination is
# pressed. Usually used to shut down the machine.
start on control-alt-delete
exec /sbin/shutdown -r now "Control-Alt-Delete pressed"
So you'd have to disable that... Or simply have it run your keyboard-blink program rather than /sbin/shutdown.
Also, watch out for "Control-Alt-Backspace" -- Many X11 config setups enable this combination to shutdown the X server. (Option "DontZap".)
Third:
Now you need to find a way to pickup the control-alt-delete keypress. It's not impossible, but it may not be as simple as getc(). (The again, I could be wrong...)
Of course, if you don't want your program to have the keyboard focus. If you want this to happen while other programs are running in the foreground with keyboard focus... Well then yer looking at tweaking the kernel or some kernel driver. (Or having inittab run yer program instead of /sbin/shutdown.)
Any way you slice it, this is not a good Hello World type exercise.
Option:
Find the right place to trap Alt+Ctrl+Del and register a handler.
Use the KDGETLED/KDSETLED ioctl on /dev/console to changes the keyboard LEDs.
Good Luck!