-HTTPD::Stream::Stream(AVOutputFormat *oformat, int width, int height, int time_base, int bit_rate)
-{
- AVFormatContext *avctx = avformat_alloc_context();
- avctx->oformat = oformat;
- uint8_t *buf = (uint8_t *)av_malloc(MUX_BUFFER_SIZE);
- avctx->pb = avio_alloc_context(buf, MUX_BUFFER_SIZE, 1, this, nullptr, &HTTPD::Stream::write_packet_thunk, nullptr);
-
- Mux::Codec video_codec;
- if (global_flags.uncompressed_video_to_http) {
- video_codec = Mux::CODEC_NV12;
- } else {
- video_codec = Mux::CODEC_H264;
- }
-
- avctx->flags = AVFMT_FLAG_CUSTOM_IO;
-
- // TODO: This is an ugly place to have this logic.
- const string codec_name = global_flags.stream_audio_codec_name.empty() ?
- AUDIO_OUTPUT_CODEC_NAME :
- global_flags.stream_audio_codec_name;
-
- AVCodec *codec_audio = avcodec_find_encoder_by_name(codec_name.c_str());
- if (codec_audio == nullptr) {
- fprintf(stderr, "ERROR: Could not find codec '%s'\n", codec_name.c_str());
- exit(1);
- }
-
- mux.reset(new Mux(avctx, width, height, video_codec, codec_audio, time_base, bit_rate));
-}
-