]> git.sesse.net Git - nageru/commitdiff
Add a --disable-audio option to Kaeru, to transcode streams with no audio.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 20 Apr 2019 14:12:59 +0000 (16:12 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 20 Apr 2019 14:12:59 +0000 (16:12 +0200)
nageru/flags.cpp
nageru/flags.h
nageru/kaeru.cpp

index 57e58aecf423053b57d0bdfb00e399bda711dd0c..ed52dc8933fba1f36a1a05c75f8ef85fae7d0691 100644 (file)
@@ -37,6 +37,7 @@ enum LongOption {
        OPTION_HTTP_AUDIO_BITRATE,
        OPTION_HTTP_PORT,
        OPTION_NO_TRANSCODE_AUDIO,
+       OPTION_DISABLE_AUDIO,
        OPTION_FLAT_AUDIO,
        OPTION_GAIN_STAGING,
        OPTION_DISABLE_LOCUT,
@@ -170,6 +171,7 @@ void usage(Program program)
        if (program == PROGRAM_KAERU) {
                fprintf(stderr, "      --no-transcode-audio        copy encoded audio raw from the source stream\n");
                fprintf(stderr, "                                    (requires --http-audio-codec= to be set)\n");
+               fprintf(stderr, "      --disable-audio             do not include any audio in the stream\n");
        }
        if (program == PROGRAM_NAGERU) {
                fprintf(stderr, "      --flat-audio                start with most audio processing turned off\n");
@@ -252,6 +254,7 @@ void parse_flags(Program program, int argc, char * const argv[])
                { "http-audio-bitrate", required_argument, 0, OPTION_HTTP_AUDIO_BITRATE },
                { "http-port", required_argument, 0, OPTION_HTTP_PORT },
                { "no-transcode-audio", no_argument, 0, OPTION_NO_TRANSCODE_AUDIO },
+               { "disable-audio", no_argument, 0, OPTION_DISABLE_AUDIO },
                { "flat-audio", no_argument, 0, OPTION_FLAT_AUDIO },
                { "gain-staging", required_argument, 0, OPTION_GAIN_STAGING },
                { "disable-locut", no_argument, 0, OPTION_DISABLE_LOCUT },
@@ -367,6 +370,10 @@ void parse_flags(Program program, int argc, char * const argv[])
                case OPTION_NO_TRANSCODE_AUDIO:
                        global_flags.transcode_audio = false;
                        break;
+               case OPTION_DISABLE_AUDIO:
+                       global_flags.transcode_audio = false;
+                       global_flags.enable_audio = false;
+                       break;
                case OPTION_HTTP_X264_VIDEO:
                        global_flags.x264_video_to_http = true;
                        break;
@@ -570,7 +577,7 @@ void parse_flags(Program program, int argc, char * const argv[])
                fprintf(stderr, "ERROR: --output-card points to a nonexistant card\n");
                exit(1);
        }
-       if (!global_flags.transcode_audio && global_flags.stream_audio_codec_name.empty()) {
+       if (global_flags.enable_audio && !global_flags.transcode_audio && global_flags.stream_audio_codec_name.empty()) {
                fprintf(stderr, "ERROR: If not transcoding audio, you must specify ahead-of-time what audio codec is in use\n");
                fprintf(stderr, "       (using --http-audio-codec).\n");
                exit(1);
index 3586500c3057232f5f35d3502b4e6f741f774b99..a401dbf53a3e875572d48a9dbf1862935f60bc2f 100644 (file)
@@ -63,6 +63,7 @@ struct Flags {
        bool ten_bit_output = false;  // Implies x264_video_to_disk == true and x264_bit_depth == 10.
        YCbCrInterpretation ycbcr_interpretation[MAX_VIDEO_CARDS];
        bool transcode_audio = true;  // Kaeru only.
+       bool enable_audio = true;  // Kaeru only. If false, then transcode_audio is also false.
        int x264_bit_depth = 8;  // Not user-settable.
        bool use_zerocopy = false;  // Not user-settable.
        bool can_disable_srgb_decoder = false;  // Not user-settable.
index 32b497d200f924c7289c146759094e75bd9c199e..b10324c8b4091516072294a521ce66b76760041e 100644 (file)
@@ -71,8 +71,13 @@ unique_ptr<Mux> create_mux(HTTPD *httpd, AVOutputFormat *oformat, X264Encoder *x
 
        string video_extradata = x264_encoder->get_global_headers();
 
+       // If audio is disabled (ie., we won't ever see any audio packets),
+       // set nullptr here to also not include the stream in the mux.
+       AVCodecParameters *audio_codecpar =
+               global_flags.enable_audio ? audio_encoder->get_codec_parameters().get() : nullptr;
+
        unique_ptr<Mux> mux;
-       mux.reset(new Mux(avctx, global_flags.width, global_flags.height, Mux::CODEC_H264, video_extradata, audio_encoder->get_codec_parameters().get(),
+       mux.reset(new Mux(avctx, global_flags.width, global_flags.height, Mux::CODEC_H264, video_extradata, audio_codecpar,
                get_color_space(global_flags.ycbcr_rec709_coefficients), COARSE_TIMEBASE,
                /*write_callback=*/nullptr, Mux::WRITE_FOREGROUND, { &stream_mux_metrics }));
        stream_mux_metrics.init({{ "destination", "http" }});
@@ -205,7 +210,7 @@ int main(int argc, char *argv[])
        FFmpegCapture video(argv[optind], global_flags.width, global_flags.height);
        video.set_pixel_format(FFmpegCapture::PixelFormat_NV12);
        video.set_frame_callback(bind(video_frame_callback, &video, x264_encoder.get(), audio_encoder.get(), _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11));
-       if (!global_flags.transcode_audio) {
+       if (!global_flags.transcode_audio && global_flags.enable_audio) {
                video.set_audio_callback(bind(audio_frame_callback, http_mux.get(), _1, _2));
        }
        video.configure_card();