儲存庫 vbox 的更動 42434
- 時間撮記:
- 2012-7-27 下午12:42:05 (12 年 以前)
- 位置:
- trunk/src/VBox/Frontends/VBoxHeadless/VideoCapture
- 檔案:
-
- 修改 2 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Frontends/VBoxHeadless/VideoCapture/FFmpegFB.cpp
r42341 r42434 44 44 */ 45 45 extern "C" DECLEXPORT(HRESULT) VBoxRegisterFFmpegFB(ULONG width, 46 47 48 46 ULONG height, ULONG bitrate, 47 com::Bstr filename, 48 IFramebuffer **retVal) 49 49 { 50 50 Log2(("VBoxRegisterFFmpegFB: called\n")); … … 176 176 int rc = do_rgb_to_yuv_conversion(); 177 177 if (rc == S_OK) 178 do_encoding_and_write();178 VideoRecEncodeAndWrite(pVideoRecContext, mFrameWidth, mFrameHeight, mYUVBuffer); 179 179 # if 1 180 180 /* Add another 10 seconds. */ 181 181 for (int i = 10*25; i > 0; i--) 182 do_encoding_and_write();182 VideoRecEncodeAndWrite(pVideoRecContext, mFrameWidth, mFrameHeight, mYUVBuffer); 183 183 # endif 184 Ebml_WriteWebMFileFooter(&ebml, 0); 185 if(ebml.stream) 186 fclose(ebml.stream); 187 vpx_codec_destroy(&mVpxCodec); 184 VideoRecContextClose(pVideoRecContext); 188 185 RTCritSectDelete(&mCritSect); 189 186 … … 270 267 271 268 #ifdef VBOX_WITH_VPX 272 mFrameCount = 0; 273 memset(&ebml, 0, sizeof(struct EbmlGlobal)); 274 ebml.last_pts_ms = -1; 269 270 rc = VideoRecContextCreate(&pVideoRecContext); 275 271 rc = RTCritSectInit(&mCritSect); 276 272 AssertReturn(rc == VINF_SUCCESS, E_UNEXPECTED); 277 rcOpenFile = open_output_file(); 278 AssertReturn(rcOpenFile == S_OK, rcOpenFile); 279 rcOpenCodec = open_codec(); 280 AssertReturn(rcOpenCodec == S_OK, rcOpenCodec); 273 274 if(rc == VINF_SUCCESS) 275 rc = VideoRecContextInit(pVideoRecContext, mFileName, mFrameWidth, mFrameHeight); 281 276 #else 282 277 rc = RTCritSectInit(&mCritSect); … … 525 520 if (rc != S_OK) 526 521 { 527 copy_to_intermediate_buffer(x, y, w, h); 522 #ifdef VBOX_WITH_VPX 523 VideoRecCopyToIntBuffer(pVideoRecContext, x, y, w, h, mPixelFormat, 524 mBitsPerPixel, mBytesPerLine, mFrameWidth, 525 mFrameHeight, mGuestHeight, mGuestWidth, 526 mBufferAddress, mTempRGBBuffer); 527 #else 528 copy_to_intermediate_buffer(x, y, w, h); 529 #endif 528 530 return rc; 529 531 } … … 531 533 if (rc != S_OK) 532 534 { 535 #ifdef VBOX_WITH_VPX 536 VideoRecCopyToIntBuffer(pVideoRecContext, x, y, w, h, mPixelFormat, 537 mBitsPerPixel, mBytesPerLine, mFrameWidth, 538 mFrameHeight, mGuestHeight, mGuestWidth, 539 mBufferAddress, mTempRGBBuffer); 540 #else 533 541 copy_to_intermediate_buffer(x, y, w, h); 542 #endif 543 534 544 return rc; 535 545 } … … 548 558 if (rc != S_OK) 549 559 { 560 #ifdef VBOX_WITH_VPX 561 VideoRecCopyToIntBuffer(pVideoRecContext, x, y, w, h, mPixelFormat, 562 mBitsPerPixel, mBytesPerLine, mFrameWidth, 563 mFrameHeight, mGuestHeight, mGuestWidth, 564 mBufferAddress, mTempRGBBuffer); 565 #else 550 566 copy_to_intermediate_buffer(x, y, w, h); 567 #endif 551 568 return rc; 552 569 } … … 556 573 /* Finally we copy the updated data to the intermediate buffer, 557 574 ready for the next update. */ 575 #ifdef VBOX_WITH_VPX 576 VideoRecCopyToIntBuffer(pVideoRecContext, x, y, w, h, mPixelFormat, 577 mBitsPerPixel, mBytesPerLine, mFrameWidth, 578 mFrameHeight, mGuestHeight, mGuestWidth, 579 mBufferAddress, mTempRGBBuffer); 580 581 #else 558 582 copy_to_intermediate_buffer(x, y, w, h); 583 #endif 559 584 return S_OK; 560 585 } … … 826 851 #endif 827 852 853 #ifndef VBOX_WITH_VPX 828 854 /** 829 855 * Open the FFmpeg codec and set it up (width, etc) for our MPEG file. … … 836 862 HRESULT FFmpegFB::open_codec() 837 863 { 838 #ifdef VBOX_WITH_VPX839 vpx_codec_err_t res;840 /* Populate encoder configuration */841 if ((res = vpx_codec_enc_config_default(interface, &mVpxConfig, 0)))842 {843 LogFlow(("Failed to configure codec \n"));844 AssertReturn(res == 0, E_UNEXPECTED);845 }846 847 mVpxConfig.rc_target_bitrate = 512;848 mVpxConfig.g_w = mFrameWidth;849 mVpxConfig.g_h = mFrameHeight;850 mVpxConfig.g_timebase.den = 30;851 mVpxConfig.g_timebase.num = 1;852 mVpxConfig.g_threads = 8;853 854 vpx_rational ebmlFPS = mVpxConfig.g_timebase;855 struct vpx_rational arg_framerate = {30, 1};856 Ebml_WriteWebMFileHeader(&ebml, &mVpxConfig, &arg_framerate);857 mDuration = (float)arg_framerate.den / (float)arg_framerate.num * 1000;858 859 /* Initialize codec */860 if (vpx_codec_enc_init(&mVpxCodec, interface, &mVpxConfig, 0))861 {862 LogFlow(("Failed to initialize encoder"));863 AssertReturn(res == 0, E_UNEXPECTED);864 }865 #else866 864 Assert(mpFormatContext != 0); 867 865 Assert(mpStream != 0); … … 898 896 int rcOpenCodec = avcodec_open(pCodecContext, pCodec); 899 897 AssertReturn(rcOpenCodec >= 0, E_UNEXPECTED); 900 #endif901 898 return S_OK; 902 899 } … … 913 910 HRESULT FFmpegFB::open_output_file() 914 911 { 915 #ifdef VBOX_WITH_VPX916 char szFileName[RTPATH_MAX];917 strcpy(szFileName, com::Utf8Str(mFileName).c_str());918 ebml.stream = fopen(szFileName, "wb");919 if (!ebml.stream)920 {921 LogFlow(("Failed to open the output File \n"));922 return E_FAIL;923 }924 return S_OK;925 #else926 912 char szFileName[RTPATH_MAX]; 927 913 Assert(mpFormatContext); … … 933 919 mfUrlOpen = true; 934 920 av_write_header(mpFormatContext); 935 #endif 936 return S_OK; 937 } 938 921 return S_OK; 922 } 923 #endif 939 924 940 925 /** … … 970 955 else 971 956 destX = x + xDiff; 957 972 958 if (LONG(h) + yDiff + LONG(y) <= 0) /* nothing visible */ 973 959 return; … … 1093 1079 1094 1080 #ifdef VBOX_WITH_VPX 1095 vpx_image_t VpxRawImage; 1096 vpx_codec_err_t res; 1097 const vpx_codec_cx_pkt_t *pkt; 1098 vpx_codec_iter_t iter = NULL; 1099 1100 if (mFrameWidth < 16 || mFrameWidth%2 || mFrameHeight <16 || mFrameHeight%2) 1101 LogFlow(("Invalid resolution: %ldx%ld", mFrameWidth, mFrameHeight)); 1102 1103 if (!vpx_img_alloc(&VpxRawImage, VPX_IMG_FMT_YV12, mFrameWidth, mFrameHeight, 1)) 1104 { 1105 LogFlow(("Faile tod allocate image", mFrameWidth, mFrameHeight)); 1106 return E_OUTOFMEMORY; 1107 } 1108 1109 if (mYUVBuffer != NULL) 1110 { 1111 // BOGUS! AssertReturn(VpxRawImage.w*VpxRawImage.h*3/2 <= sizeof(mYUVFrameSize), E_UNEXPECTED); 1112 memcpy(VpxRawImage.planes[0], (uint8_t *)mYUVBuffer, VpxRawImage.w*VpxRawImage.h*3/2); 1113 } 1114 1115 if ((res = vpx_codec_encode(&mVpxCodec, &VpxRawImage , mFrameCount, 1116 mDuration, 0, VPX_DL_REALTIME))) 1117 { 1118 LogFlow(("Failed to encode: %s\n", vpx_codec_err_to_string(res))); 1119 AssertReturn(res != 0, E_UNEXPECTED); 1120 1121 } 1122 while ((pkt = vpx_codec_get_cx_data(&mVpxCodec, &iter))) 1123 { 1124 switch (pkt->kind) 1125 { 1126 case VPX_CODEC_CX_FRAME_PKT: 1127 Ebml_WriteWebMBlock(&ebml, &mVpxConfig, pkt); 1128 break; 1129 default: 1130 break; 1131 } 1132 } 1133 mFrameCount++; 1081 VideoRecEncodeAndWrite(pVideoRecContext, mFrameWidth, mFrameHeight, mYUVBuffer); 1134 1082 #else 1135 1083 AVCodecContext *pContext = mpStream->codec; -
trunk/src/VBox/Frontends/VBoxHeadless/VideoCapture/FFmpegFB.h
r42340 r42434 31 31 #ifdef VBOX_WITH_VPX 32 32 #include "EbmlWriter.h" 33 #include "EncodeAndWrite.h" 33 34 #include <stdarg.h> 34 35 #include <string.h> … … 51 52 #endif 52 53 54 #ifdef VBOX_WITH_VPX 55 PVIDEORECCONTEXT pVideoRecContext; 56 #endif 53 57 54 58 class FFmpegFB : VBOX_SCRIPTABLE_IMPL(IFramebuffer)
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器