Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
sample_enc_avc.cpp
Upload User: wangqun
Upload Date: 2019-10-16
Package Size: 34701k
Code Size: 6k
Category:
Multimedia program
Development Platform:
Visual C++
- /********************************************************************
- Created: 2005/12/24
- File name: sample_enc_avc.cpp
- Purpose: command-line sample for H.264/AVC encoder
- Copyright (c) 2005-2009 MainConcept GmbH. All rights reserved.
- This software is the confidential and proprietary information of
- MainConcept GmbH and may be used only in accordance with the terms of
- your license from MainConcept GmbH.
- *********************************************************************/
- #include <stdio.h>
- #include "mctypes.h"
- #include "mcfourcc.h"
- #include "bufstrm.h"
- #include "sample_common_args.h"
- #include "sample_common_misc.h"
- #include "buf_file.h"
- #include "enc_avc.h"
- #include "enc_avc_def.h"
- #include "config_avc.h"
- // guess desired video_type
- int get_video_type(int width, int height, double frame_rate)
- {
- if (width <= 320)
- {
- return H264_CIF;
- }
- else if (width < 1280)
- {
- return H264_MAIN;
- }
- else if (width < 1440)
- {
- return H264_HDTV_720p;
- }
- return H264_BD_HDMV;
- }
- int main(int argc, char* argv[])
- {
- avc_param_set param_set;
- struct h264_v_settings * v_settings = ¶m_set.params;
- h264_v_encoder * v_encoder = NULL;
- unsigned char * input_video_buffer = NULL;
- bufstream_tt * videobs = NULL;
- char * in_file;
- char * out_file;
- char * cfg_file;
- int32_t width;
- int32_t height;
- int32_t fourcc;
- double frame_rate;
- int32_t bit_rate;
- arg_item_t params[] =
- {
- { IDS_VIDEO_FILE, 1, &in_file},
- { IDS_OUTPUT_FILE, 1, &out_file},
- { IDS_CONFIG_FILE, 0, &cfg_file},
- { IDI_V_WIDTH, 1, &width},
- { IDI_V_HEIGHT, 1, &height},
- { IDN_V_FOURCC, 1, &fourcc},
- { IDD_V_FRAMERATE, 0, &frame_rate},
- { IDI_BITRATE, 0, &bit_rate},
- };
- int init_options = 0;
- void * opt_list[10];
- if (parse_args(argc - 1, argv + 1, sizeof(params) / sizeof(params[0]), params) >= 0)
- {
- int line_size, img_start;
- int video_frame_size = get_video_frame_size(width, height, fourcc, &line_size, &img_start);
- int video_type = get_video_type(width, height, frame_rate);
- h264OutVideoDefaults(v_settings, video_type, 0);
- if (cfg_file)
- {
- APIEXTFUNC_LOADPARAMSET load_param_func = (APIEXTFUNC_LOADPARAMSET) AVCConfigGetAPIExt(MCAPI_LoadParamSet);
- if (load_param_func(¶m_set, cfg_file) != MCAPI_NOERROR)
- {
- printf("nInvalid config file. Terminating...n");
- return 0;
- }
- }
- v_settings->def_horizontal_size = width;
- v_settings->def_vertical_size = height;
- v_settings->frame_rate = frame_rate > 0.0 ? frame_rate : v_settings->frame_rate;
- v_settings->bit_rate = bit_rate >= 0 ? bit_rate * 1000 : v_settings->bit_rate;
- if (h264OutVideoChkSettings(get_rc, v_settings, NULL, NULL))
- {
- printf("nInvalid settings, h264OutVideoChkSettings failed. Terminating...n");
- return 0;
- }
- v_encoder = h264OutVideoNew(get_rc, v_settings, 0, 0xFFFFFFFF, 0, 0);
- if(!v_encoder)
- {
- printf("h264OutVideoNew failedn");
- return 0;
- }
- videobs = open_file_buf_write(out_file, 65536, NULL);
- // save original auxinfo handler
- org_auxinfo = videobs->auxinfo;
- // in order to get encoding statistics
- videobs->auxinfo = auxinfo;
- if(h264OutVideoInit(v_encoder, videobs, init_options, &opt_list[0]))
- {
- printf("h264OutVideoInit fails.n");
- return 0;
- }
- input_video_buffer = new unsigned char [video_frame_size];
- FILE * input_video_file = fopen(in_file, "rb");
- int aborted = 0;
- int frame_cnt = 0;
- void * ext_info_stack[16] = {0};
- while (1)
- {
- unsigned int option_flags = 0;
- unsigned int option_cnt = 0;
- void ** ext_info = &ext_info_stack[0];
- if (fread(input_video_buffer, sizeof(unsigned char), video_frame_size, input_video_file) != video_frame_size)
- {
- // end of the file
- break;
- }
- if (h264OutVideoPutFrame(v_encoder, input_video_buffer + img_start, line_size, width, height, fourcc, option_flags, ext_info))
- {
- break;
- }
- frame_cnt++;
- if(has_pressed_key(NULL)){
- aborted = 1;
- break;
- }
- }
- if (v_encoder)
- {
- h264OutVideoDone(v_encoder, aborted);
- h264OutVideoFree(v_encoder);
- }
- if (videobs)
- {
- videobs->done(videobs, aborted);
- videobs->free(videobs);
- }
- if (input_video_buffer)
- delete [] input_video_buffer;
- if (input_video_file)
- fclose(input_video_file);
- }
- else
- {
- printf("n==== MainConcept AVC encoder sample ====n"
- "Usage:nsample_enc_avc -yv12 -w 720 -h 576 -f 25 -b 2500 -p -perf 9 -v video.yuv -o video.h264n"
- "Supported input colour spaces are:nYV12 (-yv12)nIYUV (-iyuv)nUYVY (-uyvy)nYUYV (-yuyv)nYUY2 (-yuy2)n"
- "RGB24 (-rgb24 or -bgr3)nRGB32 (-rgb32 or -bgr4)nARGB32 (-argb32 or -bgra)nn"
- "Options:n-w picture widthn-h picture heightn-f frame raten-b target bit rate (kbps)n"
- );
- }
- return 0;
- }