Skip to content

Commit

Permalink
Added decoding of only keyframes when no video encoding is present
Browse files Browse the repository at this point in the history
  • Loading branch information
Keukhan committed Nov 12, 2024
1 parent 3b3b338 commit 4dff75a
Show file tree
Hide file tree
Showing 22 changed files with 291 additions and 30 deletions.
9 changes: 7 additions & 2 deletions misc/conf_examples/Server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,14 @@
<Type>live</Type>
<OutputProfiles>

<!-- This option is deprecated. Please use the 'HWAccels' option. -->
<!--
<HardwareAcceleration>false</HardwareAcceleration>
Common setting for decoders. Decodes is optional.
<Decodes>
To reduce resource usage, only keyframes are decoded.
It is only activated when image encoding and video bypass are enabled.
<KeyframeOnlyIfNeed>false</KeyframeOnlyIfNeed>
</Decodes>
-->

<!-- Enable this configuration if you want to hardware acceleration using GPU -->
Expand Down
10 changes: 10 additions & 0 deletions src/projects/base/info/video_track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,13 @@ int32_t VideoTrack::GetSkipFramesByConfig() const
{
return _skip_frames_conf;
}

bool VideoTrack::IsKeyframeDecodeOnly() const
{
return _keyframe_decode_only;
}

void VideoTrack::SetKeyframeDecodeOnly(bool keyframe_decode_only)
{
_keyframe_decode_only = keyframe_decode_only;
}
8 changes: 8 additions & 0 deletions src/projects/base/info/video_track.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class VideoTrack
void SetSkipFramesByConfig(int32_t skip_frames);
int32_t GetSkipFramesByConfig() const;

// decoder only parameter
bool IsKeyframeDecodeOnly() const;
void SetKeyframeDecodeOnly(bool keyframe_decode_only);

protected:

// framerate (measurement)
Expand Down Expand Up @@ -148,4 +152,8 @@ class VideoTrack
// -1 : No SkipFrame
// 0 ~ 120 : minimum value of SkipFrames. it is automatically calculated and the SkipFrames value is changed.
int32_t _skip_frames_conf = -1;

// @decoder
// Keyframe Decode Only (set by user)
bool _keyframe_decode_only = false;
};
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ namespace cfg
return CreateConfigErrorPtr("Unknown type: %s", _type.CStr());
});

// TODO: Deprecated
Register<Optional>("Decodes", &_decodes);
Register<Optional>("OutputProfiles", &_output_profiles);
Register<Optional>("Providers", &_providers);
Register<Optional>("Publishers", &_publishers);
// TODO: Deprecated
Register<Optional>("PersistentStreams", &_persistent_streams);
Register<Optional>("TranscodeWebhook", &_transcode_webhook);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//=============================================================================
//
// OvenMediaEngine
//
// Created by Hyunjun Jang
// Copyright (c) 2019 AirenSoft. All rights reserved.
//
//==============================================================================
#pragma once

namespace cfg
{
namespace vhost
{
namespace app
{
namespace oprf
{
struct Decodes : public Item
{
public:
// Informal Option
CFG_DECLARE_CONST_REF_GETTER_OF(IsKeyframeOnlyIfNeed, _keyframe_only_if_need);

protected:
void MakeList() override
{
Register<Optional>("KeyframeOnlyIfNeed", &_keyframe_only_if_need);
}

bool _keyframe_only_if_need = false;
};
} // namespace dec
} // namespace app
} // namespace vhost
} // namespace cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "./output_profile.h"
#include "./hwaccels/hwaccels.h"
#include "./decodes/decodes.h"

namespace cfg
{
Expand All @@ -25,11 +26,12 @@ namespace cfg
bool _hwaccel = false;
HWAccels _hwaccels;
std::vector<OutputProfile> _output_profiles;

Decodes _decodes;
public:
CFG_DECLARE_CONST_REF_GETTER_OF(IsHardwareAcceleration, _hwaccel);
CFG_DECLARE_CONST_REF_GETTER_OF(GetHWAccels, _hwaccels);
CFG_DECLARE_CONST_REF_GETTER_OF(GetOutputProfileList, _output_profiles);
CFG_DECLARE_CONST_REF_GETTER_OF(GetDecodes, _decodes);

protected:
void MakeList() override
Expand All @@ -44,6 +46,7 @@ namespace cfg
);
Register<Optional>({"HWAccels", "hwaccels"}, &_hwaccels);
Register<Optional>("OutputProfile", &_output_profiles);
Register<Optional>({"Decodes", "decodes"}, &_decodes);
}
};
} // namespace oprf
Expand Down
11 changes: 11 additions & 0 deletions src/projects/transcoder/codec/decoder/decoder_avc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ void DecoderAVC::CodecThread()
_pkt->duration = duration;
}

// Keyframe Decode Only
// If set to decode only key frames, non-keyframe packets are dropped.
if(GetRefTrack()->IsKeyframeDecodeOnly() == true)
{
// Drop non-keyframe packets
if (!(_pkt->flags & AV_PKT_FLAG_KEY))
{
break;
}
}

int ret = ::avcodec_send_packet(_context, _pkt);
if (ret == AVERROR(EAGAIN))
{
Expand Down
12 changes: 11 additions & 1 deletion src/projects/transcoder/codec/decoder/decoder_avc_nilogan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,18 @@ void DecoderAVCxNILOGAN::CodecThread()
_pkt->duration = duration;
}

int ret = ::avcodec_send_packet(_context, _pkt);
// Keyframe Decode Only
// If set to decode only key frames, non-keyframe packets are dropped.
if(GetRefTrack()->IsKeyframeDecodeOnly() == true)
{
// Drop non-keyframe packets
if (!(_pkt->flags & AV_PKT_FLAG_KEY))
{
break;
}
}

int ret = ::avcodec_send_packet(_context, _pkt);
if (ret == AVERROR(EAGAIN))
{
// Need more data
Expand Down
12 changes: 11 additions & 1 deletion src/projects/transcoder/codec/decoder/decoder_avc_nv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,18 @@ void DecoderAVCxNV::CodecThread()
_pkt->duration = duration;
}

int ret = ::avcodec_send_packet(_context, _pkt);
// Keyframe Decode Only
// If set to decode only key frames, non-keyframe packets are dropped.
if(GetRefTrack()->IsKeyframeDecodeOnly() == true)
{
// Drop non-keyframe packets
if (!(_pkt->flags & AV_PKT_FLAG_KEY))
{
break;
}
}

int ret = ::avcodec_send_packet(_context, _pkt);
if (ret == AVERROR(EAGAIN))
{
// Need more data
Expand Down
12 changes: 11 additions & 1 deletion src/projects/transcoder/codec/decoder/decoder_avc_qsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,18 @@ void DecoderAVCxQSV::CodecThread()
_pkt->duration = duration;
}

int ret = ::avcodec_send_packet(_context, _pkt);
// Keyframe Decode Only
// If set to decode only key frames, non-keyframe packets are dropped.
if(GetRefTrack()->IsKeyframeDecodeOnly() == true)
{
// Drop non-keyframe packets
if (!(_pkt->flags & AV_PKT_FLAG_KEY))
{
break;
}
}

int ret = ::avcodec_send_packet(_context, _pkt);
if (ret == AVERROR(EAGAIN))
{
// Need more data
Expand Down
12 changes: 11 additions & 1 deletion src/projects/transcoder/codec/decoder/decoder_avc_xma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,18 @@ void DecoderAVCxXMA::CodecThread()
_pkt->duration = duration;
}

int ret = ::avcodec_send_packet(_context, _pkt);
// Keyframe Decode Only
// If set to decode only key frames, non-keyframe packets are dropped.
if(GetRefTrack()->IsKeyframeDecodeOnly() == true)
{
// Drop non-keyframe packets
if (!(_pkt->flags & AV_PKT_FLAG_KEY))
{
break;
}
}

int ret = ::avcodec_send_packet(_context, _pkt);
if (ret == AVERROR(EAGAIN))
{
// Need more data
Expand Down
12 changes: 11 additions & 1 deletion src/projects/transcoder/codec/decoder/decoder_hevc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,18 @@ void DecoderHEVC::CodecThread()
_pkt->duration = duration;
}

int ret = ::avcodec_send_packet(_context, _pkt);
// Keyframe Decode Only
// If set to decode only key frames, non-keyframe packets are dropped.
if(GetRefTrack()->IsKeyframeDecodeOnly() == true)
{
// Drop non-keyframe packets
if (!(_pkt->flags & AV_PKT_FLAG_KEY))
{
break;
}
}

int ret = ::avcodec_send_packet(_context, _pkt);
if (ret == AVERROR(EAGAIN))
{
// Need more data
Expand Down
12 changes: 11 additions & 1 deletion src/projects/transcoder/codec/decoder/decoder_hevc_nilogan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,18 @@ void DecoderHEVCxNILOGAN::CodecThread()
_pkt->duration = duration;
}

int ret = ::avcodec_send_packet(_context, _pkt);
// Keyframe Decode Only
// If set to decode only key frames, non-keyframe packets are dropped.
if(GetRefTrack()->IsKeyframeDecodeOnly() == true)
{
// Drop non-keyframe packets
if (!(_pkt->flags & AV_PKT_FLAG_KEY))
{
break;
}
}

int ret = ::avcodec_send_packet(_context, _pkt);
if (ret == AVERROR(EAGAIN))
{
// Need more data
Expand Down
12 changes: 11 additions & 1 deletion src/projects/transcoder/codec/decoder/decoder_hevc_nv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,18 @@ void DecoderHEVCxNV::CodecThread()
_pkt->duration = duration;
}

int ret = ::avcodec_send_packet(_context, _pkt);
// Keyframe Decode Only
// If set to decode only key frames, non-keyframe packets are dropped.
if(GetRefTrack()->IsKeyframeDecodeOnly() == true)
{
// Drop non-keyframe packets
if (!(_pkt->flags & AV_PKT_FLAG_KEY))
{
break;
}
}

int ret = ::avcodec_send_packet(_context, _pkt);
if (ret == AVERROR(EAGAIN))
{
// Need more data
Expand Down
12 changes: 11 additions & 1 deletion src/projects/transcoder/codec/decoder/decoder_hevc_qsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,18 @@ void DecoderHEVCxQSV::CodecThread()
_pkt->duration = duration;
}

int ret = ::avcodec_send_packet(_context, _pkt);
// Keyframe Decode Only
// If set to decode only key frames, non-keyframe packets are dropped.
if(GetRefTrack()->IsKeyframeDecodeOnly() == true)
{
// Drop non-keyframe packets
if (!(_pkt->flags & AV_PKT_FLAG_KEY))
{
break;
}
}

int ret = ::avcodec_send_packet(_context, _pkt);
if (ret == AVERROR(EAGAIN))
{
// Need more data
Expand Down
12 changes: 11 additions & 1 deletion src/projects/transcoder/codec/decoder/decoder_hevc_xma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,18 @@ void DecoderHEVCxXMA::CodecThread()
_pkt->duration = duration;
}

int ret = ::avcodec_send_packet(_context, _pkt);
// Keyframe Decode Only
// If set to decode only key frames, non-keyframe packets are dropped.
if(GetRefTrack()->IsKeyframeDecodeOnly() == true)
{
// Drop non-keyframe packets
if (!(_pkt->flags & AV_PKT_FLAG_KEY))
{
break;
}
}

int ret = ::avcodec_send_packet(_context, _pkt);
if (ret == AVERROR(EAGAIN))
{
// Need more data
Expand Down
12 changes: 11 additions & 1 deletion src/projects/transcoder/codec/decoder/decoder_vp8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,18 @@ void DecoderVP8::CodecThread()
_pkt->duration = duration;
}

int ret = ::avcodec_send_packet(_context, _pkt);
// Keyframe Decode Only
// If set to decode only key frames, non-keyframe packets are dropped.
if(GetRefTrack()->IsKeyframeDecodeOnly() == true)
{
// Drop non-keyframe packets
if (!(_pkt->flags & AV_PKT_FLAG_KEY))
{
break;
}
}

int ret = ::avcodec_send_packet(_context, _pkt);
if (ret == AVERROR(EAGAIN))
{
// Need more data
Expand Down
3 changes: 3 additions & 0 deletions src/projects/transcoder/codec/encoder/encoder_png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ bool EncoderPNG::SetCodecParams()
_codec_context->width = GetRefTrack()->GetWidth();
_codec_context->height = GetRefTrack()->GetHeight();

// Set the compression level
_codec_context->compression_level = 1;

_bitstream_format = cmn::BitstreamFormat::PNG;

_packet_type = cmn::PacketType::RAW;
Expand Down
Loading

0 comments on commit 4dff75a

Please sign in to comment.