Fits a 16:9 video into a 4:3 frame by resizing and padding the picture, using AVBlocks Transcoder with hardcoded input and output file paths.
This sample demonstrates the basic AVBlocks video padding workflow:
- Initialize the AVBlocks library
- Create a
MediaInfoobject to probe the input file - Create an input
MediaSocketfrom the probed media info - Clone the input socket to start with an identical output configuration
- Set the output frame size to 640x480 and the display ratio to 4:3
- Set
Pad.Top/Pad.Bottomparameters on the output video pin so the original 16:9 picture is centered and padded to fit the 4:3 frame - Set the resize interpolation method to
Superfor best quality when downscaling - Configure a
Transcoderwith the input and output sockets - Run the transcode operation
No command line parsing is used -- the input and output file paths are hardcoded in the source code.
From the repository root:
mkdir -Force -Path build\debug_x64
cd build\debug_x64
cmake -G 'Ninja' -DCMAKE_BUILD_TYPE=debug -DPLATFORM=x64 ../../samples
ninjaThe built executable will be placed in bin\x64\simple_video_pad.exe.
-
Download the sample video, the MP4 file from the TED talk video What's the next window into our universe? by Andrew Connolly (Wide 480p, 854x480, 16:9):
Invoke-WebRequest -Uri "https://archive.org/download/AndrewConnolly_2014/AndrewConnolly_2014.mp4" -OutFile AndrewConnolly_2014.mp4
-
Run the sample from the sample directory (the input/output file paths are relative to the working directory):
cd samples\windows\simple_video_pad ..\..\..\bin\x64\simple_video_pad.exe -
The padded output file
AndrewConnolly_2014_640x480_Padded.mp4will be created in thesamples\windows\simple_video_paddirectory.
- The input file
AndrewConnolly_2014.mp4and output fileAndrewConnolly_2014_640x480_Padded.mp4paths are hardcoded insimple_video_pad.cpp. They are relative to the working directory from which the executable is run. - If
transcoder->open()fails, it may be becauseAndrewConnolly_2014_640x480_Padded.mp4already exists in the directory. Delete the output file and try again. - The source video is 16:9 at 854x480. The output frame is 640x480 (4:3), so the picture is squeezed to 640x270 (
640 * 9 / 16) and padded by 105 pixels on top and bottom to preserve the original 16:9 aspect ratio within the 4:3 frame.