Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HEVC: Support DVR HEVC stream to MP4. v6.0.14 #3360

Merged
merged 6 commits into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions trunk/3rdparty/srs-bench/blackbox/dvr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,112 @@ func TestFast_RtmpPublish_DvrFlv_Basic(t *testing.T) {
}
}
}

func TestFast_RtmpPublish_DvrMp4_Basic(t *testing.T) {
// This case is run in parallel.
t.Parallel()

// Setup the max timeout for this case.
ctx, cancel := context.WithTimeout(logger.WithContext(context.Background()), time.Duration(*srsTimeout)*time.Millisecond)
defer cancel()

// Check a set of errors.
var r0, r1, r2, r3, r4, r5, r6 error
defer func(ctx context.Context) {
if err := filterTestError(ctx.Err(), r0, r1, r2, r3, r4, r5, r6); err != nil {
t.Errorf("Fail for err %+v", err)
} else {
logger.Tf(ctx, "test done with err %+v", err)
}
}(ctx)

var wg sync.WaitGroup
defer wg.Wait()

// Start hooks service.
hooks := NewHooksService()
wg.Add(1)
go func() {
defer wg.Done()
r6 = hooks.Run(ctx, cancel)
}()

// Start SRS server and wait for it to be ready.
svr := NewSRSServer(func(v *srsServer) {
v.envs = []string{
"SRS_VHOST_DVR_ENABLED=on",
"SRS_VHOST_DVR_DVR_PLAN=session",
"SRS_VHOST_DVR_DVR_PATH=./objs/nginx/html/[app]/[stream].[timestamp].mp4",
fmt.Sprintf("SRS_VHOST_DVR_DVR_DURATION=%v", *srsFFprobeDuration),
"SRS_VHOST_HTTP_HOOKS_ENABLED=on",
fmt.Sprintf("SRS_VHOST_HTTP_HOOKS_ON_DVR=http://localhost:%v/api/v1/dvrs", hooks.HooksAPI()),
}
})
wg.Add(1)
go func() {
defer wg.Done()
<-hooks.ReadyCtx().Done()
r0 = svr.Run(ctx, cancel)
}()

// Start FFmpeg to publish stream.
duration := time.Duration(*srsFFprobeDuration) * time.Millisecond
streamID := fmt.Sprintf("stream-%v-%v", os.Getpid(), rand.Int())
streamURL := fmt.Sprintf("rtmp://localhost:%v/live/%v", svr.RTMPPort(), streamID)
ffmpeg := NewFFmpeg(func(v *ffmpegClient) {
// When process quit, still keep case to run.
v.cancelCaseWhenQuit, v.ffmpegDuration = false, duration
v.args = []string{
"-stream_loop", "-1", "-re", "-i", *srsPublishAvatar, "-c", "copy", "-f", "flv", streamURL,
}
})
wg.Add(1)
go func() {
defer wg.Done()
<-svr.ReadyCtx().Done()
r1 = ffmpeg.Run(ctx, cancel)
}()

// Start FFprobe to detect and verify stream.
ffprobe := NewFFprobe(func(v *ffprobeClient) {
v.dvrByFFmpeg, v.streamURL = false, streamURL
v.duration, v.timeout = duration, time.Duration(*srsFFprobeTimeout)*time.Millisecond

wg.Add(1)
go func() {
defer wg.Done()
for evt := range hooks.HooksEvents() {
if onDvrEvt, ok := evt.(*HooksEventOnDvr); ok {
fp := path.Join(svr.WorkDir(), onDvrEvt.File)
logger.Tf(ctx, "FFprobe: Set the dvrFile=%v from callback", fp)
v.dvrFile = fp
}
}
}()
})
wg.Add(1)
go func() {
defer wg.Done()
<-svr.ReadyCtx().Done()
r2 = ffprobe.Run(ctx, cancel)
}()

// Fast quit for probe done.
select {
case <-ctx.Done():
case <-ffprobe.ProbeDoneCtx().Done():
defer cancel()

str, m := ffprobe.Result()
if len(m.Streams) != 2 {
r3 = errors.Errorf("invalid streams=%v, %v, %v", len(m.Streams), m.String(), str)
}

if ts := 90; m.Format.ProbeScore < ts {
r4 = errors.Errorf("low score=%v < %v, %v, %v", m.Format.ProbeScore, ts, m.String(), str)
}
if dv := m.Duration(); dv < duration/2 {
r5 = errors.Errorf("short duration=%v < %v, %v, %v", dv, duration/2, m.String(), str)
}
}
}
232 changes: 232 additions & 0 deletions trunk/3rdparty/srs-bench/blackbox/hevc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,235 @@ func TestSlow_RtmpPublish_HlsPlay_HEVC_Basic(t *testing.T) {
}
}
}

func TestSlow_RtmpPublish_DvrFlv_HEVC_Basic(t *testing.T) {
// This case is run in parallel.
t.Parallel()

// Setup the max timeout for this case.
ctx, cancel := context.WithTimeout(logger.WithContext(context.Background()), time.Duration(*srsTimeout)*time.Millisecond)
defer cancel()

// Check a set of errors.
var r0, r1, r2, r3, r4, r5, r6 error
defer func(ctx context.Context) {
if err := filterTestError(ctx.Err(), r0, r1, r2, r3, r4, r5, r6); err != nil {
t.Errorf("Fail for err %+v", err)
} else {
logger.Tf(ctx, "test done with err %+v", err)
}
}(ctx)

var wg sync.WaitGroup
defer wg.Wait()

// Start hooks service.
hooks := NewHooksService()
wg.Add(1)
go func() {
defer wg.Done()
r6 = hooks.Run(ctx, cancel)
}()

// Start SRS server and wait for it to be ready.
svr := NewSRSServer(func(v *srsServer) {
v.envs = []string{
"SRS_VHOST_DVR_ENABLED=on",
"SRS_VHOST_DVR_DVR_PLAN=session",
"SRS_VHOST_DVR_DVR_PATH=./objs/nginx/html/[app]/[stream].[timestamp].flv",
fmt.Sprintf("SRS_VHOST_DVR_DVR_DURATION=%v", *srsFFprobeDuration),
"SRS_VHOST_HTTP_HOOKS_ENABLED=on",
fmt.Sprintf("SRS_VHOST_HTTP_HOOKS_ON_DVR=http://localhost:%v/api/v1/dvrs", hooks.HooksAPI()),
}
})
wg.Add(1)
go func() {
defer wg.Done()
<-hooks.ReadyCtx().Done()
r0 = svr.Run(ctx, cancel)
}()

// Start FFmpeg to publish stream.
duration := time.Duration(*srsFFprobeDuration) * time.Millisecond
streamID := fmt.Sprintf("stream-%v-%v", os.Getpid(), rand.Int())
streamURL := fmt.Sprintf("rtmp://localhost:%v/live/%v", svr.RTMPPort(), streamID)
ffmpeg := NewFFmpeg(func(v *ffmpegClient) {
// When process quit, still keep case to run.
v.cancelCaseWhenQuit, v.ffmpegDuration = false, duration
v.args = []string{
"-stream_loop", "-1", "-re", "-i", *srsPublishAvatar, "-acodec", "copy", "-vcodec", "libx265",
"-profile:v", "main", "-preset", "ultrafast", "-f", "flv", streamURL,
}
})
wg.Add(1)
go func() {
defer wg.Done()
<-svr.ReadyCtx().Done()
r1 = ffmpeg.Run(ctx, cancel)
}()

// Start FFprobe to detect and verify stream.
ffprobe := NewFFprobe(func(v *ffprobeClient) {
v.dvrByFFmpeg, v.streamURL = false, streamURL
v.duration, v.timeout = duration, time.Duration(*srsFFprobeTimeout)*time.Millisecond

wg.Add(1)
go func() {
defer wg.Done()
for evt := range hooks.HooksEvents() {
if onDvrEvt, ok := evt.(*HooksEventOnDvr); ok {
fp := path.Join(svr.WorkDir(), onDvrEvt.File)
logger.Tf(ctx, "FFprobe: Set the dvrFile=%v from callback", fp)
v.dvrFile = fp
}
}
}()
})
wg.Add(1)
go func() {
defer wg.Done()
<-svr.ReadyCtx().Done()
r2 = ffprobe.Run(ctx, cancel)
}()

// Fast quit for probe done.
select {
case <-ctx.Done():
case <-ffprobe.ProbeDoneCtx().Done():
defer cancel()

str, m := ffprobe.Result()
if len(m.Streams) != 2 {
r3 = errors.Errorf("invalid streams=%v, %v, %v", len(m.Streams), m.String(), str)
}

if ts := 90; m.Format.ProbeScore < ts {
r4 = errors.Errorf("low score=%v < %v, %v, %v", m.Format.ProbeScore, ts, m.String(), str)
}
if dv := m.Duration(); dv < duration/2 {
r5 = errors.Errorf("short duration=%v < %v, %v, %v", dv, duration/2, m.String(), str)
}

if v := m.Video(); v == nil {
r5 = errors.Errorf("no video %v, %v", m.String(), str)
} else if v.CodecName != "hevc" {
r6 = errors.Errorf("invalid video codec=%v, %v, %v", v.CodecName, m.String(), str)
}
}
}

func TestSlow_RtmpPublish_DvrMp4_HEVC_Basic(t *testing.T) {
// This case is run in parallel.
t.Parallel()

// Setup the max timeout for this case.
ctx, cancel := context.WithTimeout(logger.WithContext(context.Background()), time.Duration(*srsTimeout)*time.Millisecond)
defer cancel()

// Check a set of errors.
var r0, r1, r2, r3, r4, r5, r6 error
defer func(ctx context.Context) {
if err := filterTestError(ctx.Err(), r0, r1, r2, r3, r4, r5, r6); err != nil {
t.Errorf("Fail for err %+v", err)
} else {
logger.Tf(ctx, "test done with err %+v", err)
}
}(ctx)

var wg sync.WaitGroup
defer wg.Wait()

// Start hooks service.
hooks := NewHooksService()
wg.Add(1)
go func() {
defer wg.Done()
r6 = hooks.Run(ctx, cancel)
}()

// Start SRS server and wait for it to be ready.
svr := NewSRSServer(func(v *srsServer) {
v.envs = []string{
"SRS_VHOST_DVR_ENABLED=on",
"SRS_VHOST_DVR_DVR_PLAN=session",
"SRS_VHOST_DVR_DVR_PATH=./objs/nginx/html/[app]/[stream].[timestamp].mp4",
fmt.Sprintf("SRS_VHOST_DVR_DVR_DURATION=%v", *srsFFprobeDuration),
"SRS_VHOST_HTTP_HOOKS_ENABLED=on",
fmt.Sprintf("SRS_VHOST_HTTP_HOOKS_ON_DVR=http://localhost:%v/api/v1/dvrs", hooks.HooksAPI()),
}
})
wg.Add(1)
go func() {
defer wg.Done()
<-hooks.ReadyCtx().Done()
r0 = svr.Run(ctx, cancel)
}()

// Start FFmpeg to publish stream.
duration := time.Duration(*srsFFprobeDuration) * time.Millisecond
streamID := fmt.Sprintf("stream-%v-%v", os.Getpid(), rand.Int())
streamURL := fmt.Sprintf("rtmp://localhost:%v/live/%v", svr.RTMPPort(), streamID)
ffmpeg := NewFFmpeg(func(v *ffmpegClient) {
// When process quit, still keep case to run.
v.cancelCaseWhenQuit, v.ffmpegDuration = false, duration
v.args = []string{
"-stream_loop", "-1", "-re", "-i", *srsPublishAvatar, "-acodec", "copy", "-vcodec", "libx265",
"-profile:v", "main", "-preset", "ultrafast", "-f", "flv", streamURL,
}
})
wg.Add(1)
go func() {
defer wg.Done()
<-svr.ReadyCtx().Done()
r1 = ffmpeg.Run(ctx, cancel)
}()

// Start FFprobe to detect and verify stream.
ffprobe := NewFFprobe(func(v *ffprobeClient) {
v.dvrByFFmpeg, v.streamURL = false, streamURL
v.duration, v.timeout = duration, time.Duration(*srsFFprobeTimeout)*time.Millisecond

wg.Add(1)
go func() {
defer wg.Done()
for evt := range hooks.HooksEvents() {
if onDvrEvt, ok := evt.(*HooksEventOnDvr); ok {
fp := path.Join(svr.WorkDir(), onDvrEvt.File)
logger.Tf(ctx, "FFprobe: Set the dvrFile=%v from callback", fp)
v.dvrFile = fp
}
}
}()
})
wg.Add(1)
go func() {
defer wg.Done()
<-svr.ReadyCtx().Done()
r2 = ffprobe.Run(ctx, cancel)
}()

// Fast quit for probe done.
select {
case <-ctx.Done():
case <-ffprobe.ProbeDoneCtx().Done():
defer cancel()

str, m := ffprobe.Result()
if len(m.Streams) != 2 {
r3 = errors.Errorf("invalid streams=%v, %v, %v", len(m.Streams), m.String(), str)
}

if ts := 90; m.Format.ProbeScore < ts {
r4 = errors.Errorf("low score=%v < %v, %v, %v", m.Format.ProbeScore, ts, m.String(), str)
}
if dv := m.Duration(); dv < duration/2 {
r5 = errors.Errorf("short duration=%v < %v, %v, %v", dv, duration/2, m.String(), str)
}

if v := m.Video(); v == nil {
r5 = errors.Errorf("no video %v, %v", m.String(), str)
} else if v.CodecName != "hevc" {
r6 = errors.Errorf("invalid video codec=%v, %v, %v", v.CodecName, m.String(), str)
}
}
}
1 change: 1 addition & 0 deletions trunk/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The changelog for SRS.

## SRS 6.0 Changelog

* v6.0, 2023-01-08, Merge [#3360](https://github.com/ossrs/srs/pull/3360): H265: Support DVR HEVC stream to MP4. v6.0.14
* v6.0, 2023-01-06, Merge [#3363](https://github.com/ossrs/srs/issues/3363): HTTP: Add CORS Header for private network access. v6.0.13
* v6.0, 2023-01-04, Merge [#3362](https://github.com/ossrs/srs/issues/3362): SRT: Upgrade libsrt from 1.4.1 to 1.5.1. v6.0.12
* v6.0, 2023-01-02, For [#465](https://github.com/ossrs/srs/issues/465): HLS: Support HEVC over HLS. v6.0.11
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version6.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#define VERSION_MAJOR 6
#define VERSION_MINOR 0
#define VERSION_REVISION 13
#define VERSION_REVISION 14

#endif
4 changes: 2 additions & 2 deletions trunk/src/kernel/srs_kernel_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@
XX(ERROR_HTTP_URL_UNESCAPE , 3096, "HttpUrlUnescape", "Failed to unescape URL for HTTP") \
XX(ERROR_HTTP_WITH_BODY , 3097, "HttpWithBody", "Failed for HTTP body") \
XX(ERROR_HEVC_DISABLED , 3098, "HevcDisabled", "HEVC is disabled") \
XX(ERROR_HEVC_DECODE_ERROR , 3099, "HevcDecode", "HEVC decode av stream failed")

XX(ERROR_HEVC_DECODE_ERROR , 3099, "HevcDecode", "HEVC decode av stream failed") \
XX(ERROR_MP4_HVCC_CHANGE , 3100, "Mp4HvcCChange", "MP4 does not support video HvcC change")
/**************************************************/
/* HTTP/StreamConverter protocol error. */
#define SRS_ERRNO_MAP_HTTP(XX) \
Expand Down
Loading