Re-use h264 keyframes

This commit is contained in:
Kamil Trzcinski 2022-04-08 11:09:47 +02:00
parent 1352df220b
commit 3a8574de66
3 changed files with 21 additions and 14 deletions

View File

@ -55,6 +55,7 @@ bool http_h264_needs_buffer();
void http_h264_capture(buffer_t *buf);
void http_h264_lowres_capture(buffer_t *buf);
void http_h264_video(http_worker_t *worker, FILE *stream);
bool h264_is_key_frame(buffer_t *buf);
void http_mkv_video(http_worker_t *worker, FILE *stream);
void http_mp4_video(http_worker_t *worker, FILE *stream);
void http_mov_video(http_worker_t *worker, FILE *stream);

View File

@ -255,14 +255,8 @@ static int http_ffmpeg_copy_packets(http_ffmpeg_status_t *status)
static int http_ffmpeg_video_buf_part(buffer_lock_t *buf_lock, buffer_t *buf, int frame, http_ffmpeg_status_t *status)
{
unsigned char *data = buf->start;
if (buf->v4l2_buffer.flags & V4L2_BUF_FLAG_KEYFRAME) {
status->had_key_frame = true;
E_LOG_DEBUG(buf, "Got key frame (from V4L2)!");
} else if (buf->used >= 5 && (data[4] & 0x1F) == 0x07) {
status->had_key_frame = true;
E_LOG_DEBUG(buf, "Got key frame (from buffer)!");
if (!status->had_key_frame) {
status->had_key_frame = h264_is_key_frame(buf);
}
if (!status->had_key_frame) {

View File

@ -47,16 +47,28 @@ typedef struct {
bool requested_key_frame;
} http_video_status_t;
bool h264_is_key_frame(buffer_t *buf)
{
unsigned char *data = buf->start;
device_t *camera = buf->buf_list->device;
if (buf->v4l2_buffer.flags & V4L2_BUF_FLAG_KEYFRAME) {
E_LOG_DEBUG(buf, "Got key frame (from V4L2)!");
return true;
} else if (buf->used >= 5 && (data[4] & 0x1F) == 0x07) {
E_LOG_DEBUG(buf, "Got key frame (from buffer)!");
return true;
}
return false;
}
int http_video_buf_part(buffer_lock_t *buf_lock, buffer_t *buf, int frame, http_video_status_t *status)
{
unsigned char *data = buf->start;
if (buf->v4l2_buffer.flags & V4L2_BUF_FLAG_KEYFRAME) {
status->had_key_frame = true;
E_LOG_DEBUG(buf, "Got key frame (from V4L2)!");
} else if (buf->used >= 5 && (data[4] & 0x1F) == 0x07) {
status->had_key_frame = true;
E_LOG_DEBUG(buf, "Got key frame (from buffer)!");
if (!status->had_key_frame) {
status->had_key_frame = h264_is_key_frame(buf);
}
if (!status->had_key_frame) {