MciSendString automatically plays AVI files at fullspeed - c++

I'm trying to play avi files with mciSendString.
Here's my testing code :
#include <iostream>
#include <windows.h>
#include <string>
#pragma comment (lib, "winmm.lib")
using namespace std;
int main(int argc, char* argv[])
{
mciSendString("open D:\\something.avi type avivideo alias myAlias", NULL, 0, NULL);
mciSendString("play myAlias fullscreen from 0", NULL, 0, NULL);
return 0;
}
The thing is it plays the file at fullspeed, as if I had done :
mciSendString("set myAlias speed 0", NULL, 0, NULL);
I tried to set the speed to 1000, to no avail.
Some weird things :
If I set the speed to 2000 for example, the file does play at double speed instead of fullspeed
For some files, it is displayed at normal speed and I can't seem to figure out why.
I tried to find out where it comes from with GSpot (https://en.wikipedia.org/wiki/GSpot) because I already had this software for previous reasons but I couldn't find any correlation.
Please understand that my knowledge in media files is close to nonexistent, so try keeping it as simple as possible.
Thank you.

Related

Is there a way to play a sound without delay?

My program is playing a sound PlaySound.
The program works fine and I can hear the sound, but when the song end, there is a delay for like 1 second, and then the song play again.
I asked Google, and he gave me this question - PlaySound() Delay
The guy who answerd , said that instead SND_SYNC we need to use SND_ASYNC, I listened to him and did it, but I can't hear anything.
Do you have any suggestions ?
Btw, this is the song I'm currently using for this project - Nyan Cat
I want that this song will be start again immediately, for the user to not hear that there is a Delay.
Final Code:
#include <iostream>
#include <Windows.h>
#include <string>
#pragma comment(lib, "winmm.lib")
int main()
{
std::string pathtosound = "C:\\Users\\roile\\Documents\\Dragonite\\nyan.wav";
while (true) {
PlaySound(pathtosound.c_str(), 0, SND_SYNC);
}
return 0;
}
The SND_LOOP flag is described as follows in Microsoft Docs:
The sound plays repeatedly until PlaySound is called again with the
pszSound parameter set to NULL. If this flag is set, you must also set
the SND_ASYNC flag.
Pay attention to the last sentence, hence the following code will probably work better:
#include <iostream>
#include <Windows.h>
#include <string>
#pragma comment(lib, "winmm.lib")
int main()
{
std::string pathtosound = "C:\\Users\\roile\\Documents\\Dragonite\\nyan.wav";
PlaySound(pathtosound.c_str(), 0, SND_ASYNC | SND_LOOP);
while (true) {
// Stop loop at some point
}
PlaySound(NULL, 0, 0); // Stop sample
return 0;
}

Visual Studio 2015 OpenCV Assertion failed (size.width>0 && size.height>0) in cv::imshow windows.cpp

I've been learning a bit of c++ lately and i keep getting the same error for some reason.
Apparently, imshow isn't able to find the file.
My codes are
#include "stdafx.h"
#include<opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include<iostream>
#include <conio.h>
using namespace std;
using namespace cv;
int main()
{
cv::Mat img;
img = imread("1.png");
if (img.empty())
{
cout << "can't find da file\n\n" ;
}
cv::namedWindow("test");
cv::imshow("test",img);
waitKey(0);
}
I've tried putting it in the project folder along with the ".exe",
I tried listing the whole directory of the image using "/" and "\"
I've also tried not using any extensions in the code but to no avail.
Error Signs
Thanks for helping you guys :)
I always advise the same thing for these cases. It just needs a little lateral thinking. Change your code to this
int main()
{
ofstream test("test.txt");
test << "I'm here!!\n";
}
Now run this program, it will create a file called test.txt. Find out where that file is on your system and that's where you should put your 1.png file. Then you can go back to your original program confident that the file is in the right place and any remaining issues are a different problem.

OpenCV: Reading the frames of a video sequence

Anyone help me ,I am trying to run code to read frames from video in folder its success in building but when debugging there isn't any output
* I am using Visual studio 2012 ,opencv 2.4.11 version
the code is :
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
int main()
{
// Open the video file
cv::VideoCapture capture("C:/Users/asus/Desktop/A.mp4");
// check if video successfully opened
if (!capture.isOpened())
return 1;
// Get the frame rate
int rate= capture.get(CV_CAP_PROP_FPS);
bool stop(false);
cv::Mat frame; // current video frame
cv::namedWindow("Extracted Frame");
// Delay between each frame in ms
// corresponds to video frame rate
int delay= 1000/rate;
// for all frames in video
while (!stop) {
// read next frame if any
if (!capture.read(frame))
break;
cv::imshow("Extracted Frame",frame);
// introduce a delay
// or press key to stop
if (cv::waitKey(delay)>=0)
stop= true;
}
// Close the video file.
// Not required since called by destructor
capture.release();
}
Your main() function is never executed. The only thing, that gets executed is _tmain(), which does nothing and returns immediately.
I haven't done much Windows programming in a while, but if I remember correctly this is how it works:
When Unicode is enabled for your compiler
int _tmain(int argc, _TCHAR* argv[])
gets compiled as
int wmain(int argc, wchar * argv[])
which is then used as the program entry point.
Since you seem not to be using any Windows-APIs in your code I would ignore the Microsoft specific way of doing multibyte character strings, which is non-portable, and simply use plain ASCII strings as you did in the main() function, that you intended to use.
So to solve your problem simply throw out the _tmain() function. Maybe you also need to disable Unicode in your project settings if you get linker errors.

lodepng, stb_image. Nothing works in my system for image loading in C++

I'm trying to load pngs or bmps into my programs. But none of the libraries I found around the web works. I have no idea why but I always get "incorrect PNG signature, it's no PNG or corrupted" for EVERY png when using lodepng. "unknown pixel format" for EVERY bmp when using SDL_loadBMP. "unknown image type" for every png when using stb_image.
I can't load anything. Maybe there is something wrong with my system ? I'm using OSX Yosemite. Here is the code.
#include <iostream>
#include <string>
#define STB_IMAGE_IMPLEMENTATION
#include <lodepng.h>
#include <stb_image.h>
using namespace std;
int main (){
string name = "res/img_test.png";
const char * cstr = name.c_str();
//lodepng
unsigned char *buffer;
unsigned int w,h;
int result = lodepng_decode32_file(&buffer, &w, &h, cstr);
cout << lodepng_error_text(result) << endl;
//stb_image
int x, y, comp;
FILE *f = fopen(cstr, "rb");
unsigned char *res;
res = stbi_load_from_file(f,&x,&y,&comp,0);
fclose(f);
cout << stbi_failure_reason() << endl;
return 0;
}
I'm using latest cmake to build this with gcc. Any recommendatation is appreciated but consider this. I've tried many files (generated by me or grabbed from internet). Tested same files with other users of the these libraries. Their code worked and mine didn't.
Edit:
Here's the source with complete cmake project >> github.com/onatbas/png_load_test.git
I solved it! Thank you everyone for trying to help.
It wasn't a code issue, afterall. It is a configuration issue. My cmake script damages the pngs and bmps when trying to copy them into destination folder. The code is fine.

Can't launch website in C++

Trying to launch a website in Visual C++ 2010 Express, every researched solution has not worked. So I gather I need more in-depth assistance. Here's my code:
#include <stdafx.h>
#include <stdio.h>
#include <iostream>
#include <io.h>
#include <string>
#include <string.h>
#include <conio.h>
#include <windows.h>
using namespace System;
using namespace std;
int main()
{
char name[240];
cout<<"\nHello, Please enter your name: ";
cin.getline(name,240);
cout<<"\nHello "<<name <<", your ID has been confirmed!";
cout<<"\nContinuing to launch website 'xyz' now.";
// system("C:\\Program%Files\\Google\\Chrome\\Application\\chrome.exe");
ShellExecute, TEXT("open"), TEXT(c:\\program
files\\google\\chrome\\application\\chrome.exe), NULL, NULL, SW_SHOWNORMAL;
goto end;
end:
cout<<"\n\nProgram completed, Pess any key to exit. ";
_getch();
return 0;
}
Like this.
ShellExecute(NULL, TEXT("open"), TEXT("c:\\program files\\google\\chrome\\application\\chrome.exe"), NULL, NULL, SW_SHOWNORMAL);
You had missing parens, missing double quotes and quite possibly spurious characters between 'program' and 'files' in your path. You also had a missing parameter to ShellExecute.
Reading a book and learning a minimum of C++ syntax would be a good idea. These are very basic errors.
system("\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" http://heise.de");
works for me.
See How to call an external program with parameters?