Creating an AVI in memory with C++

Creating an AVI in memory with C++
        
The following example demonstrates how an avi file is completely created in memory.

/*
   MakeAviInMemory.cpp

An example on how to use Avi.cpp

Copyright (c) 2004, 2005 René Nyffenegger

This source code is provided ‘as-is‘, without any express or implied
   warranty. In no event will the author be held liable for any damages
   arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
   including commercial applications, and to alter it and redistribute it
   freely, subject to the following restrictions:

1. The origin of this source code must not be misrepresented; you must not
      claim that you wrote the original source code. If you use this source code
      in a product, an acknowledgment in the product documentation would be
      appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
      misrepresented as being the original source code.

3. This notice may not be removed or altered from any source distribution.

René Nyffenegger [email protected]
*/

#include <windows.h>
#include "avi.h"

#include <iostream>
#include <sstream>

#include "MemoryDC.h"
#include "DibSection.h"
#include "Color.h"
#include "Font.h"

int main() {
  const float frames_per_second = 24.0;

Avi a("InMemory.avi",static_cast<int>(1000.0/frames_per_second),0);

MemoryDC memory_dc;

for (int i=0; i<5*frames_per_second; i++) {  
    DibSection dib_section(200, 200);
    memory_dc.Select(dib_section);
     // Set up compression just before the first frame
     if (i==0) {
       //AVICOMPRESSOPTIONS opts;
       //ZeroMemory(&opts,sizeof(opts));
       //opts.fccHandler=mmioFOURCC(‘d‘,‘i‘,‘v‘,‘x‘);
       //SetAviVideoCompression(hbm,0/*&opts*/,true,0);
       HRESULT r = a.compression(dib_section, 0 /*&opts*/, true, 0);
       char buf [200];
       if (r != S_OK) {
         FormatAviMessage(r, buf, 200);
         std::cout << "compression: " << buf << std::endl;
         return -1;
       }
    }

memory_dc.DrawOpaque(false);
    memory_dc.TextColor(Color(0,0,255));
    memory_dc.Select(Font("Arial", 100));
 
    STD_SSTR s;
    s<<i;
    memory_dc.Text(50,50,s.str().c_str());

HRESULT r =a.add_frame(dib_section);

char buf [200];
    if (r != S_OK) {
      FormatAviMessage(r, buf, 200);
      std::cout << buf << std::endl;
    }
  }
}

时间: 2024-10-14 13:27:15

Creating an AVI in memory with C++的相关文章

FPGA内部RAM的初始化

Altera的RAM初始化文件格式是mif和hex. QuartusII自带的RAM初始化工具很方便产生初始化文件. Xilinx的RAM初始化文件格式是coe, 在vivado中软件会将coe文件变成mif 文件.Xilinx和Altera的mif文件格式并不相同.Xilinx的mif文件才是最终有效的初始化文件.可以用Memory Editor编辑工具产生coe文件,具体位置在Tools > Memory Editor.也可以在 $XILINX/coregen/data目录下发现参考文件.

WCF Windows Service Using TopShelf and ServiceModelEx z

http://lourenco.co.za/blog/2013/08/wcf-windows-service-using-topshelf-and-servicemodelex/ There are two excellent .NET libraries that help us to build enterprise solutions using the Windows Communication Foundation (WCF) – TopShelf and ServiceModelEx

[原]Threads vs Processes in Linux 分析

Linux中thread (light-weighted process) 跟process在實作上幾乎一樣. 最大的差異來自於,thread 會分享 virtual memory address space. a. 從kernel角度看兩者沒差別,在user看來process是least shared而thread是most sharing. b. 從實作角度來比較: 創建user process的方法是有三個API: fork, vfork, clone創建user thread的方法主要是

MySQL SHOW PROCESSLIST 状态详解

官方手册:https://dev.mysql.com/doc/refman/5.7/en/general-thread-states.html 8.14.2 General Thread States The following list describes thread State values that are associated withgeneral query processing and not more specialized activities such asreplicat

STM32物联网之TFTP文件传输

感言:专注物联网应用开发,分享物联网技术经验. 软件平台:IAR6.5 TCP/IP协议栈:LWIP1.4.1 硬件平台:STM32F103C8T6有线通信板(点击这里可以购买) 1.TCP/IP协议栈LWIP 1.1.LWIP认识 LWIP是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈,是Light Weight (轻型)IP协议,有无操作系统的支持都可以运行.LWIP提供三种API,分别是RAW API.LWIP API .BSD API.其

Creating an generated Earth AVI with C++

Creating an generated Earth AVI with C++        EarthGenerator.cpp /*    EarthGenerator.cpp An example on how to use AviMemDC.cpp Copyright (c) 1998-2003 Torben AE. Mogensen   Copyright (c) 2004,2005 René Nyffenegger All algorithms and source code pe

Creating a ZIP Archive in Memory Using System.IO.Compression

Thanks to http://stackoverflow.com/a/12350106/222748 I got: using (var memoryStream = new MemoryStream()) { using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) { var demoFile = archive.CreateEntry("foo.txt"); using (v

outdated: 35.Playing AVI Files In OpenGL

AVI视频文件读取,首先得建个AVI(AVISTREAMINFO)文件流指针,具体的结构, typedef struct { DWORD fccType; // Stream type DWORD fccHandler; // Compressor handler DWORD dwFlags; // Applicable flags for the stream DWORD dwCaps; // Capability flags; currently unused WORD wPriority;

【C#】AviFile使用(播放AVI文件,兼容性比较差)

最近在做一个视频识别项目,需要用到视频处理,在codeproject上找到了一个关于对Avi的操作库,感觉不错,在这里把一些要点记录下来 http://www.codeproject.com/Articles/7388/A-Simple-C-Wrapper-for-the-AviFile-Library Avi视频文件的编码有很多,这个库只支持部分Avi文件,有些Avi文件不支持,具体哪些不支持还没搞清楚 AviFile库提供了 1.从视频流中图片的处理 2.视频中音频的处理 3.压缩和解压视频