?
Solved

Decrypt and play video from TMemoryStream

Posted on 2011-03-25
6
Medium Priority
?
1,815 Views
Last Modified: 2012-05-11
Hello,

I have encrypted video located in http server, and i want to do with it the following.
- Download and decrypt it in MemoryStream.
- Play this video from MemoryStream.

So i won't to put the video in the hard driver, i want to download, decrypt and play it in memory.
0
Comment
Question by:Mahdi78
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 35221501
You can't download to MemoryStream. You have to assign physical destination in the local hard drive.
All the online Multimedia players download videos before playback (through buffering). Even Youtube downloads and use temp files to stream the videos.

The default path is the Temp Folder, default is:
C:\Documents and Settings\UserName\Local Settings\Temp

So you should download your video to the Temp Folder and then decrypt it and finally play it.

All the Audio/Video players require path/file location to start. Haven't seen Multimedia player that supports such streaming from Memory.
0
 
LVL 9

Author Comment

by:Mahdi78
ID: 35222729
>> You can't download to MemoryStream.

It is possible with idhttp to download to MemoryStream, like the following example

var MStrm: TMemoryStream;
begin
MStrm := TMemoryStream.Create;
  try
  IdHttp1.Get('http://localhost/video.wmv', MStrm);
  MStrm.SaveToFile('myvideo.wmv');
  Showmessage('Download finished');
  finally
  MStrm.Free;
  end;
end;

It is possible to Decrypt MemoryStream too

>> All the Audio/Video players require path/file location to start. Haven't seen Multimedia player that supports such streaming from Memory.

what about mms protocol? like this link
mms://83.221.120.201/streaming/mednetu/5455/Lez001.wmv

My idea about how to do like the following example

var MStrm1, MStrm2: TMemoryStream;
begin
MStrm1 := TMemoryStream.Create;
MStrm2 := TMemoryStream.Create;
  try
  IdHttp1.Get('http://localhost/video.wmv', MStrm1);
  MStrm2 := Decrypt(MStrm1);
  MyPlayer.Loadstream(MStrm2);
  MyPlayer.Play;
  finally
  MStrm1.Free;
  MStrm2.Free;
  end;
end;

0
 
LVL 24

Accepted Solution

by:
jimyX earned 2000 total points
ID: 35223544
I don't know much about TIdhttp, but I will investigate on how it handles that exactly (i.e. does it use local temp file or it's a direct stream loading).
Ya agree, decrypting streams is not an issue, once you have your stream fully loaded and ready, you can change it easily.

MMS is a network streaming protocol which uses data packets to be sent via network, then played on the fly. It differs than downloading multimedia content to a stream.

Ciuly has developed a component which will enable you to play multimedia contents from stream:
http://www.ciuly.com/delphi/multimedia/

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_22901002.html

Let's find out how it goes:
procedure TForm1.Button1Click(Sender: TObject);
var
  MStrm: TMemoryStream;
begin
  MStrm := TMemoryStream.Create;
  try
    IdHttp1.Get('http://MultimediaLink/test.avi', MStrm);
    Caption := 'Download finished';
    MCIStreamPlayer1.Stream := MStrm;
    MCIStreamPlayer1.open;
  finally
    MStrm.Free;
  end;
end;

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Author Comment

by:Mahdi78
ID: 35260895
Good links jimyX, this what i'm looking for
But unfortunately the both components don't work with Delphi 2009 and don't support wmv video,

Your code doesn't work it raise an error when MCIStreamPlayer1 get the stream, but i got the way how to load stream into MCIStreamPlayer1

You really answered to my question,  if you have or any expert has an additional comment please shoot it
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35261177
>   "components don't work with Delphi 2009"
When compiling it under Delphi 2009 and you get the errors, just change all the PAnsiChar to PChar.

>   "it raise an error when MCIStreamPlayer1 get the stream"
Let me guess, you downloaded to a temp file, converted it, then loaded it to the MCIStreamPlayer1, no?
0
 
LVL 9

Author Comment

by:Mahdi78
ID: 35261512
>> When compiling it under Delphi 2009 and you get the errors, just change all the PAnsiChar to PChar.

Oops, thank you it resolved, i was so lazy, when got errors with TMCIStreamPlayer i changed all functions PAnsiChar to PChar but i forgot to change the variable from AnsiChar to Char, when i converted my components to Delphi 2009 i changed variables Char to AnsiChar and function PChar to PAnsiChar except TMCIStreamPlayer, it work by opposite way lol, i don't know why.

DSPack still unconverted to Delphi 2009.

>> Let me guess, you downloaded to a temp file, converted it, then loaded it to the MCIStreamPlayer1, no?

I downloaded an avi from local http server like this example

procedure TForm1.Button1Click(Sender: TObject);
var
  MStrm: TMemoryStream;
begin
  MStrm := TMemoryStream.Create;
  try
    IdHttp1.Get('http://localhost/video/test.avi', MStrm);
    Caption := 'Download finished';
    MCIStreamPlayer1.Stream := MStrm;
    MCIStreamPlayer1.open;
  finally
    MStrm.Free;
  end;
end;

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question