]> git.sesse.net Git - nageru/blobdiff - nageru/video_encoder.cpp
Make it possible to siphon out a single MJPEG stream.
[nageru] / nageru / video_encoder.cpp
index 42247e9cd0bda138ca49a1615ee58acc7cdb66ab..2ac606ec5aea8674f1a31cc2ea763134d75deea4 100644 (file)
@@ -15,10 +15,10 @@ extern "C" {
 #include "defs.h"
 #include "shared/ffmpeg_raii.h"
 #include "flags.h"
-#include "httpd.h"
-#include "mux.h"
+#include "shared/httpd.h"
+#include "shared/mux.h"
 #include "quicksync_encoder.h"
-#include "timebase.h"
+#include "shared/timebase.h"
 #include "x264_encoder.h"
 
 class RefCountedFrame;
@@ -35,7 +35,7 @@ string generate_local_dump_filename(int frame)
        localtime_r(&now, &now_tm);
 
        char timestamp[64];
-       strftime(timestamp, sizeof(timestamp), "%F-%T%z", &now_tm);
+       strftime(timestamp, sizeof(timestamp), "%F-%H%M%S%z", &now_tm);
 
        // Use the frame number to disambiguate between two cuts starting
        // on the same second.
@@ -193,7 +193,8 @@ void VideoEncoder::open_output_stream()
                video_extradata = x264_encoder->get_global_headers();
        }
 
-       stream_mux.reset(new Mux(avctx, width, height, video_codec, video_extradata, stream_audio_encoder->get_codec_parameters().get(), COARSE_TIMEBASE,
+       stream_mux.reset(new Mux(avctx, width, height, video_codec, video_extradata, stream_audio_encoder->get_codec_parameters().get(),
+               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" }});
 }
@@ -216,9 +217,9 @@ int VideoEncoder::write_packet2(uint8_t *buf, int buf_size, AVIODataMarkerType t
 
        if (type == AVIO_DATA_MARKER_HEADER) {
                stream_mux_header.append((char *)buf, buf_size);
-               httpd->set_header(stream_mux_header);
+               httpd->set_header(HTTPD::StreamID{ HTTPD::MAIN_STREAM, 0 }, stream_mux_header);
        } else {
-               httpd->add_data((char *)buf, buf_size, type == AVIO_DATA_MARKER_SYNC_POINT, time, AVRational{ AV_TIME_BASE, 1 });
+               httpd->add_data(HTTPD::StreamID{ HTTPD::MAIN_STREAM, 0 }, (char *)buf, buf_size, type == AVIO_DATA_MARKER_SYNC_POINT, time, AVRational{ AV_TIME_BASE, 1 });
        }
        return buf_size;
 }