Solved

Decrypt and play video from TMemoryStream

Posted on 2011-03-25
6
1,696 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
  • 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 500 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now