Solved

Decrypt and play video from TMemoryStream

Posted on 2011-03-25
6
1,747 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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