Click here to Skip to main content
15,892,480 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Reading Image (JPG) file as Binary to CString Pin
jeron16-Sep-13 6:09
jeron16-Sep-13 6:09 
QuestionRe: Reading Image (JPG) file as Binary to CString Pin
David Crow6-Sep-13 6:12
David Crow6-Sep-13 6:12 
AnswerRe: Reading Image (JPG) file as Binary to CString Pin
Richard MacCutchan6-Sep-13 6:35
mveRichard MacCutchan6-Sep-13 6:35 
GeneralRe: Reading Image (JPG) file as Binary to CString Pin
Don Guy6-Sep-13 6:44
Don Guy6-Sep-13 6:44 
GeneralRe: Reading Image (JPG) file as Binary to CString Pin
Jochen Arndt6-Sep-13 7:05
professionalJochen Arndt6-Sep-13 7:05 
QuestionRe: Reading Image (JPG) file as Binary to CString Pin
David Crow6-Sep-13 17:23
David Crow6-Sep-13 17:23 
GeneralRe: Reading Image (JPG) file as Binary to CString Pin
Richard MacCutchan6-Sep-13 22:44
mveRichard MacCutchan6-Sep-13 22:44 
Questionffmpeg images to video using C++ Pin
CodingHell6-Sep-13 1:13
CodingHell6-Sep-13 1:13 
I'm working on ffmpeg to create a video using ffmpeg library.
I'm capturing desktop and using raw data to create a video, video is being created but there is nothing in video.
My code is:

for screen capture:
C++
HANDLE BmpFile=INVALID_HANDLE_VALUE;

	 screenWidth = GetSystemMetrics(SM_CXSCREEN);
   screenHeight = GetSystemMetrics(SM_CYSCREEN);
HWND hDesktopWnd = GetDesktopWindow();
    HDC hDesktopDC = GetDC(hDesktopWnd);
    HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
    hBmp = CreateCompatibleBitmap(GetDC(0), screenWidth, screenHeight);
    SelectObject(hCaptureDC, hBmp);
    BitBlt(hCaptureDC, 0, 0, screenWidth, screenHeight, hDesktopDC, 0, 0, SRCCOPY|CAPTUREBLT);
    BITMAPINFO bmi = {0}; 
    bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); 
    bmi.bmiHeader.biWidth = screenWidth; 
    bmi.bmiHeader.biHeight = screenHeight; 
    bmi.bmiHeader.biPlanes = 1; 
    bmi.bmiHeader.biBitCount = 32; 
    bmi.bmiHeader.biCompression = BI_RGB;
 pPixels = new RGBQUAD[screenWidth*screenHeight];
    GetDIBits(hCaptureDC,hBmp,0,screenHeight,pPixels,&bmi,DIB_RGB_COLORS);



for video creation and frame write up:

C++
AVCodec* codec;
AVCodecContext* c = NULL;
uint8_t* outbuf;
int i, out_size, outbuf_size;

avcodec_register_all();                               

printf("Video encoding\n");
codec = avcodec_find_encoder(CODEC_ID_H264);            // finding the H264 encoder
c = avcodec_alloc_context();
c->bit_rate = 20000000;
c->width = 1024;                                      
c->height = 768;
c->time_base.num = 1;                                   
c->time_base.den = 10;                                
c->gop_size = 12;                                       
c->max_b_frames = 2;                                    
c->keyint_min = 1;                                      
c->i_quant_factor = (float)0.71;                        
c->b_frame_strategy = 20;                               
c->qcompress = (float)0.6;                              
c->qmin = 20;                                           
c->qmax = 51;                                          
c->max_qdiff = 4;                                      
c->refs = 4;                                            
c->trellis = 1;                                  
c->pix_fmt = PIX_FMT_YUV420P; 
c->codec_id =CODEC_ID_H264;
c->codec_type = CODEC_TYPE_VIDEO;
if (avcodec_open(c, codec) < 0) {
    fprintf(stderr, "Could not open codec\n");          
    exit(1);
}
else printf("H264 codec opened\n");
outbuf_size = 100000 + c->width*c->height*(32>>3);      
outbuf = static_cast<uint8_t *>(malloc(outbuf_size));
printf("Setting buffer size to: %d\n",outbuf_size);
FILE* f = fopen("example.h264","wb");                   
if(!f) printf("x  -  Cannot open video file for writing\n");
else printf("Opened video file for writing\n");
for(i=0;i<STREAM_FRAME_RATE*STREAM_DURATION;i++) {
    fflush(stdout); screencap();                                             int nbytes = avpicture_get_size(PIX_FMT_YUV420P, c->width, c->height);                                      // allocating outbuffer
    uint8_t* outbuffer = (uint8_t*)av_malloc(nbytes*sizeof(uint8_t));

    AVFrame* inpic = avcodec_alloc_frame();                                                                    
    AVFrame* outpic = avcodec_alloc_frame();

    outpic->pts = (int64_t)((float)i * (1000.0/((float)(c->time_base.den))) * 90);                             
    avpicture_fill((AVPicture*)inpic, (uint8_t*)pPixels, PIX_FMT_RGB32, c->width, c->height);                  
    avpicture_fill((AVPicture*)outpic, outbuffer, PIX_FMT_YUV420P, c->width, c->height);                        
	//av_image_alloc(outpic->data, outpic->linesize, c->width, c->height, PIX_FMT_RGB32, 1); 
	//avpicture_alloc(outpic->pts, c->pix_fmt, c->width, c->height);
    inpic->data[0] += inpic->linesize[0]*(screenHeight-1);                             
    inpic->linesize[0] = -inpic->linesize[0];    
    struct SwsContext* fooContext = sws_getContext(screenWidth, screenHeight, PIX_FMT_RGB32, c->width, c->height, PIX_FMT_YUV420P, SWS_FAST_BILINEAR, NULL, NULL, NULL);
    sws_scale(fooContext, inpic->data, inpic->linesize, 0, c->height, outpic->data, outpic->linesize);   

	out_size = avcodec_encode_video(c, outbuf, outbuf_size, outpic);                                            // encoding video
    printf("Encoding frame %3d (size=%5d)\n", i, out_size);
    fwrite(outbuf, 1, out_size, f);
	
    delete [] pPixels;                                                                       // freeing memory
    av_free(outbuffer);     
    av_free(inpic);
    av_free(outpic);
}
outbuf[0] = 0x00;
outbuf[1] = 0x00;                                                                                             
outbuf[2] = 0x01;
outbuf[3] = 0xb7;
fwrite(outbuf, 1, 4, f);
fclose(f);

avcodec_close(c);                                                                                               // freeing memory
free(outbuf);
av_free(c);


How can I do it?
Please share your opinions and experiences over it.
Question1-Can I reverse drawtext function? 2-How to know the length of data in your app Pin
JoneLe865-Sep-13 21:46
JoneLe865-Sep-13 21:46 
AnswerRe: 1-Can I reverse drawtext function? 2-How to know the length of data in your app Pin
Richard MacCutchan5-Sep-13 22:09
mveRichard MacCutchan5-Sep-13 22:09 
GeneralRe: 1-Can I reverse drawtext function? 2-How to know the length of data in your app Pin
JoneLe865-Sep-13 22:14
JoneLe865-Sep-13 22:14 
GeneralRe: 1-Can I reverse drawtext function? 2-How to know the length of data in your app Pin
Richard MacCutchan5-Sep-13 22:29
mveRichard MacCutchan5-Sep-13 22:29 
QuestionHow to get text of special symbol font? Pin
yangdp15-Sep-13 18:07
yangdp15-Sep-13 18:07 
AnswerRe: How to get text of special symbol font? Pin
JoneLe865-Sep-13 21:51
JoneLe865-Sep-13 21:51 
AnswerRe: How to get text of special symbol font? Pin
Richard MacCutchan5-Sep-13 22:05
mveRichard MacCutchan5-Sep-13 22:05 
GeneralRe: How to get text of special symbol font? Pin
yangdp15-Sep-13 22:54
yangdp15-Sep-13 22:54 
GeneralRe: How to get text of special symbol font? Pin
Richard MacCutchan5-Sep-13 23:40
mveRichard MacCutchan5-Sep-13 23:40 
QuestionConverting std::vector<BYTE> to CString Pin
Don Guy5-Sep-13 13:13
Don Guy5-Sep-13 13:13 
AnswerRe: Converting std::vector<BYTE> to CString Pin
Richard MacCutchan5-Sep-13 22:03
mveRichard MacCutchan5-Sep-13 22:03 
QuestionEnsuring the continuous physical allocation(storage) of a file in Hard disk Pin
VCSharp0075-Sep-13 8:41
VCSharp0075-Sep-13 8:41 
AnswerRe: Ensuring the continuous physical allocation(storage) of a file in Hard disk Pin
jschell5-Sep-13 9:23
jschell5-Sep-13 9:23 
QuestionStreaming Image File from MFC app to HTML Page Pin
Don Guy4-Sep-13 11:59
Don Guy4-Sep-13 11:59 
AnswerRe: Streaming Image File from MFC app to HTML Page Pin
Stephen Hewitt4-Sep-13 18:50
Stephen Hewitt4-Sep-13 18:50 
AnswerRe: Streaming Image File from MFC app to HTML Page Pin
Richard MacCutchan4-Sep-13 21:03
mveRichard MacCutchan4-Sep-13 21:03 
QuestionHow to change regional and location setting in C++ Pin
Andraw1114-Sep-13 8:51
Andraw1114-Sep-13 8:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.