Create a Console App in Visual Studio on Windows¶
This topic describes the steps needed to configure a C++ Console App in Visual Studio. These steps have been verified to work with Visual Studio 2022 Community Edition, on Windows 11.
The code snippets used in this article are from the simple_converter Windows sample. This sample takes H.264/AVC video and AAC audio in MP4 container as input and converts them to H.265/HEVC video and AAC audio in MP4 container.
Create the Visual Studio project¶
Create a C++, Console App in Visual Studio. Name the project
simple-converter. CheckPlace solution and project in the same directory.Download the 64 bit version of AVBlocks Core (Windows) that matches your machine. Check
$env:PROCESSOR_ARCHITECTURE:AMD64means x64,ARM64means ARM64. The file you need will have a name similar to the following - the version number may differ:Architecture
File
x64 (AMD64)
avblocks-v3.4.0-demo.1-windows.zipARM64
avblocks-v3.4.0-demo.1-windows-arm64.zipYou can also download it with PowerShell from the Visual Studio solution directory:
$BaseUrl = "https://github.com/avblocks/avblocks-core/releases/download" $Version = "v3.4.0-demo.1" # "windows" for x64 (AMD64), "windows-arm64" for ARM64 $Platform = "windows" Invoke-WebRequest ` -Uri "${BaseUrl}/${Version}/avblocks-${Version}-${Platform}.zip" ` -OutFile "avblocks-${Version}-${Platform}.zip"
Extract the ZIP archive in a location of your choice, then copy the
includeandlibdirectories to theavblockssubdirectory of the Visual Studio solution directory. The Visual Studio solution is the directory that contains thesimple-converter.slnsolution file. AVBlocks Plus also needs the header fileavb++.h. Download it from the avblocks-plus repository and save it in theavblocks/include/primo/avblocksdirectory.If you downloaded the archive to the Visual Studio solution directory with PowerShell, you can extract it directly into the
avblockssubdirectory:Expand-Archive ` -Path "avblocks-${Version}-${Platform}.zip" ` -DestinationPath "./avblocks" -Force
You should end up with a directory structure similar to the following:
simple-converter ├───avblocks │ ├───include │ └───lib ├───simple-converter.cpp ├───simple-converter.sln └───simple-converter.vcxproj
Replace the contents of
simple-converter.cppwith this code:#include <primo/avblocks/avb++.h> #include <cstdio> #include <iostream> // link with AVBlocks64.lib #if defined(_M_ARM64) #pragma comment(lib, "./avblocks/lib/arm64/AVBlocks64.lib") #else #pragma comment(lib, "./avblocks/lib/x64/AVBlocks64.lib") #endif using namespace primo::codecs; using namespace primo::avblocks::modern; int wmain() { TLibrary library; const wchar_t* inputFile = L"Wildlife_h264_aac.mp4"; const wchar_t* outputFile = L"Wildlife_h265_aac.mp4"; // transcoder will fail if output exists (by design) _wremove(outputFile); try { // Probe the input file and create the input socket from the probe auto input = TMediaSocketW(TMediaInfoW().file(inputFile).open()); // Demo mode is allowed when using the demo version of the library. TTranscoderW() .allowDemoMode(true) .addInput(input) // The output starts as a copy of the input .addOutput( input.clone() .file(outputFile) .videoInfoRef(0, [](TVideoStreamInfo& video) { // Change the output video stream to H.265/HEVC // Input is H.264/AVC at 700 kbps // With H.265/HEVC we can use lower bitrate, e.g. 500 kbps video.streamType(StreamType::H265) .streamSubType(StreamSubType::HEVC_Annex_B) .bitrate(500'000); }) ) .transcode(); std::wcout << L"Output: " << outputFile << std::endl; return 0; } catch (const TAVBlocksException& ex) { std::wcerr << L"AVBlocks error: " << ex.what() << std::endl; return 1; } }
In Visual Studio, select
Build | Configuration Managerfrom the menu, then select the platform that matches the AVBlocks build you downloaded (x64orARM64) from the solution platforms. If it is not in the list, choose<New...>and create it from the existing platform.In Visual Studio, select
Project | simple-converter Propertiesfrom the menu, thenC++ | General, then add./avblocks/includetoAdditional Include Directories.Build the project (Ctrl + Shift + B).
Copy the file
AVBlocks64.dllfromavblocks/lib/x64tox64/Debug(on ARM64: fromavblocks/lib/arm64toARM64/Debug).
Run the application¶
Download the
Wildlife_h264_aac.mp4sample file and save it in the Visual Studio solution directory (next to thesimple-converter.slnsolution file):Invoke-WebRequest ` -Uri https://archive.org/download/WildlifeSampleVideo/Wildlife.mp4 ` -OutFile Wildlife_h264_aac.mp4
Copy the file
AVBlocks64.dllfromavblocks/lib/x64tox64/Debug(on ARM64: fromavblocks/lib/arm64toARM64/Debug).Run the application in Visual Studio. Wait a few seconds for the Transcoder to finish. The converted file
Wildlife_h265_aac.mp4will be in the solution directory.
Troubleshooting¶
You may get
The program can't start because AVBlocks64.dll is missing from your computer. Try reinstalling the program to fix this problem.or a similar message. To fix that, copy the fileAVBlocks64.dllfromavblocks/lib/x64tox64/Debug(on ARM64: fromavblocks/lib/arm64toARM64/Debug).TTranscoder::openmay fail if there is already a fileWildlife_h265_aac.mp4in the project directory. DeleteWildlife_h265_aac.mp4to solve that.