本帖最后由 slimay 于 2021-8-16 18:11 编辑
>>> 改进的控制台显示视频第三方 bmp2.exe <<<
可以实现瞬时逆放视频, 最高 每秒1000张图片的显示速度.音轨同步, 也算是一个视频播放器吧, 但是是控制台下的,只有23KB.
附件下载(cmd1152的网站)文件区\bmp2窗口播放视频.zip
http://cmd1152.ys168.com/
基础用法:
bmp2 "第一张图" "最后一张图" 延时 "背景音乐"
bmp2 "第一张图" "最后一张图" 延时 位置的横坐标 位置的纵坐标 "背景音乐"
开放源码- #include <stdio.h>
- #include <windows.h>
- #include <gdiplus.h>
- #include<mmsystem.h>
- #pragma comment(lib,"Winmm.lib")
- #pragma comment(lib,"Gdiplus.lib")
-
- using namespace Gdiplus;
-
- #define USAGE_INFORMATION "\
- Usage: bmp2 [start picture] [end picture] [delayed time]\n\
- bmp2 [start picture] [end picture] [delayed time] [mp3]\n\
- bmp2 [start picture] [end picture] [delayed time] [x position] [y position]\n\
- bmp2 [start picture] [end picture] [delayed time] [x position] [y position] [mp3]\n\
- Made by Slimay.\n"
-
- extern "C" HWND WINAPI GetConsoleWindow();
-
- int main( int argc, char** argv )
- {
- if( argc - 1 < 3 || argc - 1 > 6 )
- {
- printf( USAGE_INFORMATION );
- exit( 1 );
- }
-
- if( argc - 1 == 4 || argc - 1 == 6 )
- {
- char* musicFile = ( argc - 1 == 4 ) ? argv[4] : argv[6];
- char musicStr[512] = {0};
- sprintf( musicStr, "open %s alias bkmusic", musicFile );
- mciSendStringA( musicStr, NULL, 0, NULL );
- mciSendString( "play bkmusic repeat", NULL, 0, NULL );
- }
-
- // 获取前缀名
- int startNum = -1;
- int endNum = -1;
- float delayTime = atof( argv[3] );
- int xPos = ( argc - 1 >= 5 ) ? atoi( argv[4] ) : 0;
- int yPos = ( argc - 1 >= 5 ) ? atoi( argv[5] ) : 0;
-
- int numShowWidth = 1;
- char* preName = NULL;
- char* lastName = NULL;
-
- char* p = argv[1];
- while( *p )
- {
- if( '0' <= *p && *p <= '9' )
- {
- preName = argv[1];
- startNum = atoi( p );
- *p = 0;
-
- p++;
- while( '0' <= *p && *p <= '9' )
- {
- p++;
- numShowWidth ++;
- }
- lastName = p;
- break;
- }
- p++;
- }
-
- p = argv[2];
- while( *p )
- {
- if( '0' <= *p && *p <= '9' )
- {
- endNum = atoi( p );
- break;
- }
- p++;
- }
-
-
- ULONG_PTR gdipludToken;
- GdiplusStartupInput gdiplusInput;
- GdiplusStartup(&gdipludToken,&gdiplusInput,NULL);
- {
- HDC hDC =GetDC(GetConsoleWindow());
- HDC memDC = CreateCompatibleDC( hDC );
- HBITMAP hMemBitmap = CreateCompatibleBitmap(hDC, 1024, 1024);
- SelectObject(memDC, hMemBitmap);
-
- Graphics graph( memDC );
-
- wchar_t wcsPreName[512 * 2];
- char picName[512] = {0};
-
- for( int i = startNum; ( startNum - endNum <= 0 ) ? ( i <= endNum ) : ( i >= endNum ); i += ( ( startNum - endNum <= 0 ) ? ( 1 ) : ( -1 ) ) )
- {
- sprintf( picName, "%s%0*d%s", preName, numShowWidth, i, lastName );
-
- int textlen = MultiByteToWideChar( CP_ACP, 0, picName, -1, NULL, 0 );
- MultiByteToWideChar( CP_ACP, 0, picName, -1, (LPWSTR)wcsPreName, textlen );
- wcsPreName[textlen] = 0x0000;
-
- Image* srcIMG = Image::FromFile(wcsPreName);
- graph.DrawImage(srcIMG, xPos, yPos);
- BitBlt( hDC, xPos, yPos, srcIMG->GetWidth(), srcIMG->GetHeight(), memDC, 0, 0, SRCCOPY );
-
- Sleep( ( int )( delayTime * 1000 ) );
- }
- }
- GdiplusShutdown(gdipludToken);
- return 1;
- }
复制代码
|