Skip to content

Commit

Permalink
Option for setting muxer
Browse files Browse the repository at this point in the history
  • Loading branch information
James Edwards-Jones authored and RX14 committed Sep 28, 2019
1 parent aa0b257 commit f81bb8d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ to select and limit the recording to a part of the screen.

To specify a codec, use the `-c <codec>` option. To modify codec parameters, use `-p <option_name>=<option_value>`

To set a specific output format use the `--muxer` option. For example, to output to a video4linux2 loopback you might use:
```
wf-recorder --muxer=v4l2 --codec=rawvideo --file=/dev/video2
```

To use gpu encoding, use a VAAPI codec (for ex. `h264_vaapi`) and specify a GPU device to use with the `-d` option:
```
wf-recorder -f test-vaapi.mkv -c h264_vaapi -d /dev/dri/renderD128
Expand Down
3 changes: 3 additions & 0 deletions manpage/wf-recorder.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ wf-recorder - A simple screen recording program for wlroots-based compositors

You can check the muxers that your FFmpeg installation supports by running : *ffmpeg -muxers*

*-m, --muxer*
Set the output format to a specific muxer instead of detecting it from the filename.

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

Expand Down
12 changes: 8 additions & 4 deletions src/frame-writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,15 @@ void FrameWriter::init_sws(AVPixelFormat format)
}
}

static const char* determine_output_format(const std::string& output_name)
static const char* determine_output_format(const FrameWriterParams& params)
{
if (output_name.find("rtmp") == 0)
if (!params.muxer.empty())
return params.muxer.c_str();

if (params.file.find("rtmp") == 0)
return "flv";
if (output_name.find("udp") == 0)

if (params.file.find("udp") == 0)
return "mpegts";

return NULL;
Expand All @@ -324,7 +328,7 @@ FrameWriter::FrameWriter(const FrameWriterParams& _params) :
// Preparing the data concerning the format and codec,
// in order to write properly the header, frame data and end of file.
this->outputFmt = av_guess_format(NULL, params.file.c_str(), NULL);
auto streamFormat = determine_output_format(params.file);
auto streamFormat = determine_output_format(params);
auto context_ret = avformat_alloc_output_context2(&this->fmtCtx, NULL,
streamFormat, params.file.c_str());
if (context_ret < 0)
Expand Down
1 change: 1 addition & 0 deletions src/frame-writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct FrameWriterParams
InputFormat format;

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

Expand Down
8 changes: 8 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,9 @@ With no FILE, start recording the current screen.
You can check the muxers that your FFmpeg installation supports by
running : ffmpeg -muxers
-m, --muxer Set the output format to a specific muxer instead of detecting it
from the filename.
-g, --geometry Selects a specific part of the screen.
-h, --help Prints this help screen.
Expand Down Expand Up @@ -579,6 +582,7 @@ int main(int argc, char *argv[])
struct option opts[] = {
{ "output", required_argument, NULL, 'o' },
{ "file", required_argument, NULL, 'f' },
{ "muxer", required_argument, NULL, 'm' },
{ "geometry", required_argument, NULL, 'g' },
{ "codec", required_argument, NULL, 'c' },
{ "codec-param", required_argument, NULL, 'p' },
Expand Down Expand Up @@ -606,6 +610,10 @@ int main(int argc, char *argv[])
cmdline_output = optarg;
break;

case 'm':
params.muxer = optarg;
break;

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

0 comments on commit f81bb8d

Please sign in to comment.