]> git.sesse.net Git - nageru/blobdiff - nageru/ffmpeg_capture.cpp
Add a --no-transcode-video flag to Kaeru.
[nageru] / nageru / ffmpeg_capture.cpp
index a8b6f612a06a470eb7427648497dffc4aaf47295..0a328e0182570a8953407541954a2ee5ac7763aa 100644 (file)
@@ -438,9 +438,11 @@ void FFmpegCapture::send_disconnected_frame()
                        memset(video_frame.data + frame_width * frame_height, 128, frame_width * frame_height);  // Valid for both NV12 and planar.
                }
 
-               frame_callback(-1, AVRational{1, TIMEBASE}, -1, AVRational{1, TIMEBASE}, timecode++,
-                       video_frame, /*video_offset=*/0, video_format,
-                       FrameAllocator::Frame(), /*audio_offset=*/0, AudioFormat());
+               if (frame_callback != nullptr) {
+                       frame_callback(-1, AVRational{1, TIMEBASE}, -1, AVRational{1, TIMEBASE}, timecode++,
+                               video_frame, /*video_offset=*/0, video_format,
+                               FrameAllocator::Frame(), /*audio_offset=*/0, AudioFormat());
+               }
                last_frame_was_connected = false;
        }
 
@@ -734,9 +736,11 @@ bool FFmpegCapture::play_video(const string &pathname)
                                        timecode += MAX_FPS * 2 + 1;
                                }
                                last_neutral_color = get_neutral_color(frame->metadata);
-                               frame_callback(frame->pts, video_timebase, audio_pts, audio_timebase, timecode++,
-                                       video_frame.get_and_release(), 0, video_format,
-                                       audio_frame.get_and_release(), 0, audio_format);
+                               if (frame_callback != nullptr) {
+                                       frame_callback(frame->pts, video_timebase, audio_pts, audio_timebase, timecode++,
+                                               video_frame.get_and_release(), 0, video_format,
+                                               audio_frame.get_and_release(), 0, audio_format);
+                               }
                                first_frame = false;
                                last_frame = steady_clock::now();
                                last_frame_was_connected = true;
@@ -841,6 +845,9 @@ AVFrameWithDeleter FFmpegCapture::decode_frame(AVFormatContext *format_ctx, AVCo
                        if (pkt.stream_index == audio_stream_index && audio_callback != nullptr) {
                                audio_callback(&pkt, format_ctx->streams[audio_stream_index]->time_base);
                        }
+                       if (pkt.stream_index == video_stream_index && video_callback != nullptr) {
+                               video_callback(&pkt, format_ctx->streams[video_stream_index]->time_base);
+                       }
                        if (pkt.stream_index == video_stream_index) {
                                if (avcodec_send_packet(video_codec_ctx, &pkt) < 0) {
                                        fprintf(stderr, "%s: Cannot send packet to video codec.\n", pathname.c_str());