#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    AVI Stream to Blob


    Hi All

    I was wondering if it is possible to save a video stream directly into a BLOB field?

    I can capture the video stream and write portions of it to a Memory stream, this then needs to be written to the Blob, but i need to somehow write multiple buffers to the one Blob field because I will only be buffering a very small amount at a time.

    Is this even possible or should I just write the stream to file and then write the file to blob?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2006
    Posts
    205
    Rep Power
    15
    Originally Posted by Donovan4319
    Hi All

    I was wondering if it is possible to save a video stream directly into a BLOB field?

    I can capture the video stream and write portions of it to a Memory stream, this then needs to be written to the Blob, but i need to somehow write multiple buffers to the one Blob field because I will only be buffering a very small amount at a time.

    Is this even possible or should I just write the stream to file and then write the file to blob?

    No need to write to file, you can copy directly from stream to BLOB. The "how" depends on what language (and what components) are you using. I tried this in Delphi and PHP.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    55
    Rep Power
    7

    Thumbs up


    See as you can READ and Write data (in files) em MemoryStream or FileStream, and, try to use in your code.

    For red portion of data in BLOB (Binary type), you can "catch" by using the method SEEK and look the HELP by another funcions, procedure and methods by Stream access.

    Read one file PDF using gtPDFDocument component and using MemoryStream and post to dataset
    -------------------------------------------------
    procedure TForm1.SavetoBlobClick(Sender: TObject);
    var
    blob: TBlobStream;
    TempStrm: TMemoryStream;
    begin
    // Create a blob stream for writing
    blob := YourDataset.CreateBlobStream(YourDataset.FieldByName('YOUR_BLOB_FIELD_NAME'),bmWrite);
    try
    // Move to the beginning of the blob stream for read operations
    blob.Seek(0, soFromBeginning);
    // Create a memory stream
    TempStrm := TMemoryStream.Create;
    // Load a PDF document
    gtPDFDocument1.LoadFromFile('C:\Input.pdf');

    // Steps for modifying the PDF omitted.

    // Save the PDF document to the stream
    gtPDFDocument1.SaveToStream(TempStrm);

    // Move to the beginning of the memory stream for read operations
    TempStrm.Position := 0;
    // Copy the stream to the blob
    try
    blob.CopyFrom(TempStrm, TempStrm.Size)
    finally
    TempStrm.Free
    end;
    finally
    blob.Free
    end;
    end;


    Read one file to MemoryStream and post to dataset
    ---------------------------------
    if (OpenPictureDialog1.Execute) then
    begin
    MemoryStream := TMemoryStream.Create;
    MemoryStream.Position := 0;
    MemoryStream.LoadFromFile( OpenPictureDialog1.FileName);
    MemoryStream.Position := 0;

    ClientDataSet1YOURBLOBFIELD.LoadFromStream(MemoryS tream);

    ClientDataSet1.Post;
    ClientDataSet1.ApplyUpdates(0);

    MemoryStream.Free;

    ---------------------------------
    procedure TfrmMain.btLoadMemoClick(Sender: TObject);
    var
    FileStream: TFileStream;
    BlobStream: TStream;
    begin
    if (odBlob.Execute) then
    begin
    tVenues.Edit;
    try
    BlobStream := tVenues.CreateBlobStream(tVenues.FieldByName('Remarks'),bmWrite);
    FileStream := TFileStream.Create(odBlob.FileName,fmOpenRead or fmShareDenyNone);
    BlobStream.CopyFrom(FileStream,FileStream.Size);
    FileStream.Free;
    BlobStream.Free;
    tVenues.Post;
    except
    tVenues.Cancel;
    end;
    end;
    end;

    procedure TfrmMain.btSaveMemoClick(Sender: TObject);
    var
    FileStream: TFileStream;
    BlobStream: TStream;
    begin
    if (sdBlob.Execute) then
    begin
    FileStream := TFileStream.Create(sdBlob.FileName,fmCreate);
    BlobStream := tVenues.CreateBlobStream(tVenues.FieldByName('Remarks'),bmRead);
    FileStream.CopyFrom(BlobStream,BlobStream.Size);
    BlobStream.Free;
    FileStream.Free;
    end;
    end;

    procedure TfrmMain.btLoadImageClick(Sender: TObject);
    var
    FileStream: TFileStream;
    BlobStream: TStream;
    begin
    if (odBlob.Execute) then
    begin
    tVenues.Edit;
    try
    BlobStream := tVenues.CreateBlobStream(tVenues.FieldByName('Venue_Map'),bmWrite);
    FileStream := TFileStream.Create(odBlob.FileName,fmOpenRead or fmShareDenyNone);
    BlobStream.CopyFrom(FileStream,FileStream.Size);
    FileStream.Free;
    BlobStream.Free;
    tVenues.Post;
    except
    tVenues.Cancel;
    raise;
    end;
    end;
    end;

    procedure TfrmMain.btSaveImageClick(Sender: TObject);
    var
    FileStream: TFileStream;
    BlobStream: TStream;
    begin
    if (sdBlob.Execute) then
    begin
    FileStream := TFileStream.Create(sdBlob.FileName,fmCreate);
    BlobStream := tVenues.CreateBlobStream(tVenues.FieldByName('Venue_Map'),bmRead);
    FileStream.CopyFrom(BlobStream,BlobStream.Size);
    BlobStream.Free;
    FileStream.Free;
    end;
    end;

IMN logo majestic logo threadwatch logo seochat tools logo