SFML community forums

Help => Network => Topic started by: jbos190 on January 23, 2014, 06:58:40 am

Title: How to download a video from a website?
Post by: jbos190 on January 23, 2014, 06:58:40 am
When I use the http functionalities of sfml, I can download videos, but I can't play them properly.  For example, if I send a request to http://assets.ign.com/videos/zencoder/640/d092914f4631a98554ac9849165b5ee9-500000-1390433049-w.mp4 , and save the response body as a file with the .mp4 extention, the file does not play when I open it with VLC player.  When I enter the uri into IE browser, it downloads and then plays properly.  It also works when I download it using URLDownloadToFile() in Visual Studio.  Also, the file downloaded with sfml is about .3MB larger, although I couldn't see any noticeable differences when I opened the files as .txt.  I also encountered this same problem when using libcurl.  Does anyone know is causing this problem?
Title: Re: How to download a video from a website?
Post by: Laurent on January 23, 2014, 08:03:02 am
How do you save the file after downloading it?
Title: Re: How to download a video from a website?
Post by: jbos190 on January 23, 2014, 05:51:51 pm
Using std::ofstream, I give the file a name with the required ext:
sf::Http http;
http.setHost("http://assets.ign.com/");
sf::Http::Request request;     
request.setUri("/videos/zencoder/640/d092914f4631a98554ac9849165b5ee9-500000-1390433049-w.mp4");
sf::Http::Response response = http.sendRequest(request);       
std::string data = response.getBody();
std::ofstream fout("example.mp4");
fout << data;
fout.close();
 
I have tried this with .flv and .mp4 videos from various websites and get the same result - a file with extra bytes that doesn't play.
Title: Re: How to download a video from a website?
Post by: Laurent on January 23, 2014, 06:52:00 pm
Typical error: you forget to open the stream as binary (std::ios::bin in the constructor).
Title: Re: How to download a video from a website?
Post by: jbos190 on January 23, 2014, 08:25:54 pm
Thank you.