Skip to content

Commit

Permalink
[swapchain] fix image swapchain format detection
Browse files Browse the repository at this point in the history
add correct pix_fmt string to ffmpeg parameter, based swapchain surface
format. If surface format is `bgra` instead of `rgba`, ffmpeg now gets
the correct parameter
  • Loading branch information
tgfrerer committed Oct 3, 2023
1 parent 798d1b5 commit 2ccdd45
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/le_renderer/le_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class RendererInfoBuilder {
T& parent;
le_swapchain_settings_t::img_settings_t& settings;

static constexpr auto default_pipe_cmd = "ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - -threads 0 -preset fast -y -pix_fmt yuv420p isl%s.mp4";
static constexpr auto default_pipe_cmd = "ffmpeg -r 60 -f rawvideo -pix_fmt %s -s %dx%d -i - -threads 0 -preset fast -y -pix_fmt yuv420p isl%s.mp4";

public:
ImgSwapchainInfoBuilder( T& parent_ )
Expand Down
31 changes: 23 additions & 8 deletions modules/le_swapchain_vk/le_swapchain_img.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,23 +367,38 @@ static le_swapchain_o* swapchain_img_create( le_backend_o* backend, const le_swa

timestamp_tag << std::put_time( std::localtime( &time_now ), "_%y-%m-%d_%OH-%OM-%OS" );

std::string pix_fmt = "rgba";

switch ( self->windowSurfaceFormat.format ) {
case ( VK_FORMAT_R8G8B8A8_UNORM ): // fall-through
case ( VK_FORMAT_R8G8B8A8_SRGB ):
pix_fmt = "rgba";
break;
case ( VK_FORMAT_B8G8R8A8_UNORM ):
case ( VK_FORMAT_B8G8R8A8_SRGB ):
pix_fmt = "bgra";
break;
default:
pix_fmt = "rgba";
}

// -- Initialise ffmpeg as a receiver for our frames by selecting one of
// these possible command line options.
const char* commandLines[] = {
"ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - -threads 0 -vcodec h264_nvenc -preset llhq -rc:v vbr_minqp -qmin:v 19 -qmax:v 21 -b:v 2500k -maxrate:v 5000k -profile:v high isl%s.mp4",
"ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - -filter_complex \"[0:v] fps=30,split [a][b];[a] palettegen [p];[b][p] paletteuse\" isl%s.gif",
"ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - -threads 0 -vcodec nvenc_hevc -preset llhq -rc:v vbr_minqp -qmin:v 0 -qmax:v 4 -b:v 2500k -maxrate:v 50000k -vf \"minterpolate=mi_mode=blend:mc_mode=aobmc:mi_mode=mci,framerate=30\" isl%s.mov",
"ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - -threads 0 -vcodec h264_nvenc -preset llhq -rc:v vbr_minqp -qmin:v 0 -qmax:v 10 -b:v 5000k -maxrate:v 50000k -pix_fmt yuv420p -r 60 -profile:v high isl%s.mp4",
"ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - -threads 0 -preset fast -y -pix_fmt yuv420p isl%s.mp4",
"ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - -threads 0 isl%s_%%03d.png",
"ffmpeg -r 60 -f rawvideo -pix_fmt %s -s %dx%d -i - -threads 0 -vcodec h264_nvenc -preset llhq -rc:v vbr_minqp -qmin:v 19 -qmax:v 21 -b:v 2500k -maxrate:v 5000k -profile:v high isl%s.mp4",
"ffmpeg -r 60 -f rawvideo -pix_fmt %s -s %dx%d -i - -filter_complex \"[0:v] fps=30,split [a][b];[a] palettegen [p];[b][p] paletteuse\" isl%s.gif",
"ffmpeg -r 60 -f rawvideo -pix_fmt %s -s %dx%d -i - -threads 0 -vcodec nvenc_hevc -preset llhq -rc:v vbr_minqp -qmin:v 0 -qmax:v 4 -b:v 2500k -maxrate:v 50000k -vf \"minterpolate=mi_mode=blend:mc_mode=aobmc:mi_mode=mci,framerate=30\" isl%s.mov",
"ffmpeg -r 60 -f rawvideo -pix_fmt %s -s %dx%d -i - -threads 0 -vcodec h264_nvenc -preset llhq -rc:v vbr_minqp -qmin:v 0 -qmax:v 10 -b:v 5000k -maxrate:v 50000k -pix_fmt yuv420p -r 60 -profile:v high isl%s.mp4",
"ffmpeg -r 60 -f rawvideo -pix_fmt %s -s %dx%d -i - -threads 0 -preset fast -y -pix_fmt yuv420p isl%s.mp4",
"ffmpeg -r 60 -f rawvideo -pix_fmt %s -s %dx%d -i - -threads 0 isl%s_%%03d.png",
};

char cmd[ 1024 ]{};

if ( self->pipe_cmd.empty() ) {
snprintf( cmd, sizeof( cmd ), commandLines[ 3 ], self->mSwapchainExtent.width, self->mSwapchainExtent.height, timestamp_tag.str().c_str() );
snprintf( cmd, sizeof( cmd ), commandLines[ 3 ], pix_fmt.c_str(), self->mSwapchainExtent.width, self->mSwapchainExtent.height, timestamp_tag.str().c_str() );
} else {
snprintf( cmd, sizeof( cmd ), self->pipe_cmd.c_str(), self->mSwapchainExtent.width, self->mSwapchainExtent.height, timestamp_tag.str().c_str() );
snprintf( cmd, sizeof( cmd ), self->pipe_cmd.c_str(), pix_fmt.c_str(), self->mSwapchainExtent.width, self->mSwapchainExtent.height, timestamp_tag.str().c_str() );
}

logger.info( "Image swapchain opening pipe using command line: '%s'", cmd );
Expand Down

0 comments on commit 2ccdd45

Please sign in to comment.