Skip to content

Commit

Permalink
Add --pixel-format option
Browse files Browse the repository at this point in the history
Allows forcing yuv420p, needed for screensharing with zoom
  • Loading branch information
James Edwards-Jones authored and RX14 committed Sep 28, 2019
1 parent 8235612 commit e35d174
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions manpage/wf-recorder.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ wf-recorder - A simple screen recording program for wlroots-based compositors
*-m, --muxer*
Set the output format to a specific muxer instead of detecting it from the filename.

*-x, --pixel-format*
Set the output pixel format. These can be found by running : *ffmpeg -pix_fmts*

*-g, --geometry*
Selects a specific part of the screen.

Expand Down
14 changes: 14 additions & 0 deletions src/frame-writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,24 @@ AVPixelFormat FrameWriter::get_input_format()
AV_PIX_FMT_BGR0 : AV_PIX_FMT_RGB0;
}

AVPixelFormat FrameWriter::lookup_pixel_format(std::string pix_fmt)
{
AVPixelFormat fmt = av_get_pix_fmt(pix_fmt.c_str());

if (fmt != AV_PIX_FMT_NONE)
return fmt;

std::cerr << "Failed to find the pixel format: " << pix_fmt << std::endl;
std::exit(-1);
}

AVPixelFormat FrameWriter::choose_sw_format(AVCodec *codec)
{
auto in_fmt = get_input_format();

if (!params.pix_fmt.empty())
return lookup_pixel_format(params.pix_fmt);

/* For codecs such as rawvideo no supported formats are listed */
if (!codec->pix_fmts)
return in_fmt;
Expand Down
2 changes: 2 additions & 0 deletions src/frame-writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct FrameWriterParams

std::string codec;
std::string muxer;
std::string pix_fmt;
std::string hw_device; // used only if codec contains vaapi
std::map<std::string, std::string> codec_options;

Expand Down Expand Up @@ -78,6 +79,7 @@ class FrameWriter
AVBufferRef *hw_device_context = NULL;
AVBufferRef *hw_frame_context = NULL;

AVPixelFormat lookup_pixel_format(std::string pix_fmt);
AVPixelFormat choose_sw_format(AVCodec *codec);
AVPixelFormat get_input_format();
void init_hw_accel();
Expand Down
8 changes: 8 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ With no FILE, start recording the current screen.
-m, --muxer Set the output format to a specific muxer instead of detecting it
from the filename.
-x, --pixel-format Set the output pixel format. These can be found by running:
*ffmpeg -pix_fmts*
-g, --geometry Selects a specific part of the screen.
-h, --help Prints this help screen.
Expand Down Expand Up @@ -583,6 +586,7 @@ int main(int argc, char *argv[])
{ "output", required_argument, NULL, 'o' },
{ "file", required_argument, NULL, 'f' },
{ "muxer", required_argument, NULL, 'm' },
{ "pixel-format", required_argument, NULL, 'x' },
{ "geometry", required_argument, NULL, 'g' },
{ "codec", required_argument, NULL, 'c' },
{ "codec-param", required_argument, NULL, 'p' },
Expand Down Expand Up @@ -614,6 +618,10 @@ int main(int argc, char *argv[])
params.muxer = optarg;
break;

case 'x':
params.pix_fmt = optarg;
break;

case 'g':
selected_region.set_from_string(optarg);
break;
Expand Down

0 comments on commit e35d174

Please sign in to comment.