Skip to content

Commit

Permalink
H265: Support HEVC over RTMP or HTTP-FLV. (#3272)
Browse files Browse the repository at this point in the history
1. Support configure with --h265=on.
2. Parse HEVC(H.265) from FLV or RTMP packet.
3. Support HEVC over RTMP or HTTP-FLV.

Co-authored-by: runner365 <shi.weibd@hotmail.com>
  • Loading branch information
winlinvip and runner365 authored Nov 23, 2022
1 parent 7e02d97 commit 178e40a
Show file tree
Hide file tree
Showing 17 changed files with 440 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
which make gcc g++ patch cmake pkg-config uname grep sed &&
(make --version; gcc --version; patch --version; cmake --version; pkg-config --version) &&
(aclocal --version; autoconf --version; automake --version; uname -a) &&
cd $(cygpath -u $SRS_WORKSPACE)/trunk && ./configure && make
cd $(cygpath -u $SRS_WORKSPACE)/trunk && ./configure --gb28181=on --h265=on && make
##################################################################################################################
- name: Package SRS
env:
Expand Down
2 changes: 1 addition & 1 deletion trunk/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ WORKDIR /srs/trunk

# Build and install SRS.
# Note that SRT is enabled by default, so we configure without --srt=on.
RUN ./configure --gb28181=on --sanitizer-static=on && make && make install
RUN ./configure --gb28181=on --h265=on --sanitizer-static=on && make && make install

# All config files for SRS.
RUN cp -R conf /usr/local/srs/conf && \
Expand Down
10 changes: 5 additions & 5 deletions trunk/Dockerfile.builds
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN cd /srs/trunk && ./configure --srt=off --gb28181=off --nasm=off --srtp-nasm=

FROM ossrs/srs:dev-cache AS centos7-all
COPY . /srs
RUN cd /srs/trunk && ./configure --srt=on --gb28181=on && make
RUN cd /srs/trunk && ./configure --srt=on --gb28181=on --h265=on && make

FROM ossrs/srs:dev-cache AS centos7-ansi-no-ffmpeg
COPY . /srs
Expand All @@ -26,7 +26,7 @@ RUN cd /srs/trunk && ./configure --srt=off --gb28181=off --cxx11=off --cxx14=off

FROM ossrs/srs:dev6-cache AS centos6-all
COPY . /srs
RUN cd /srs/trunk && ./configure --srt=on --gb28181=on --cxx11=off --cxx14=off --sanitizer=off && make
RUN cd /srs/trunk && ./configure --srt=on --gb28181=on --h265=on --cxx11=off --cxx14=off --sanitizer=off && make

########################################################
FROM ossrs/srs:ubuntu16-cache AS ubuntu16-baseline
Expand All @@ -35,7 +35,7 @@ RUN cd /srs/trunk && ./configure --srt=off --gb28181=off && make

FROM ossrs/srs:ubuntu16-cache AS ubuntu16-all
COPY . /srs
RUN cd /srs/trunk && ./configure --srt=on --gb28181=on && make
RUN cd /srs/trunk && ./configure --srt=on --gb28181=on --h265=on && make

########################################################
FROM ossrs/srs:ubuntu18-cache AS ubuntu18-baseline
Expand All @@ -44,7 +44,7 @@ RUN cd /srs/trunk && ./configure --srt=off --gb28181=off && make

FROM ossrs/srs:ubuntu18-cache AS ubuntu18-all
COPY . /srs
RUN cd /srs/trunk && ./configure --srt=on --gb28181=on && make
RUN cd /srs/trunk && ./configure --srt=on --gb28181=on --h265=on && make

########################################################
FROM ossrs/srs:ubuntu20-cache AS ubuntu20-baseline
Expand All @@ -53,7 +53,7 @@ RUN cd /srs/trunk && ./configure --srt=off --gb28181=off && make

FROM ossrs/srs:ubuntu20-cache AS ubuntu20-all
COPY . /srs
RUN cd /srs/trunk && ./configure --srt=on --gb28181=on && make
RUN cd /srs/trunk && ./configure --srt=on --gb28181=on --h265=on && make

########################################################
FROM ossrs/srs:ubuntu16-cross-arm AS ubuntu16-cross-armv7
Expand Down
2 changes: 1 addition & 1 deletion trunk/Dockerfile.cov
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ COPY . /srs
WORKDIR /srs/trunk

# Note that we must enable the gcc7 or link failed.
RUN scl enable devtoolset-7 -- ./configure --srt=on --gb28181=on --utest=on --gcov=on --sanitizer=off
RUN scl enable devtoolset-7 -- ./configure --srt=on --gb28181=on --h265=on --utest=on --gcov=on --sanitizer=off
RUN scl enable devtoolset-7 -- make utest
2 changes: 1 addition & 1 deletion trunk/Dockerfile.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ RUN yum install -y zip
# Build and install SRS.
ADD srs-server-${version}.tar.gz /srs
WORKDIR /srs/srs-server-${version}/trunk
RUN ./scripts/package.sh --x86-x64 --tag=${version}
RUN ./scripts/package.sh --x86-x64 --gb28181=on --h265=on --tag=${version}

2 changes: 1 addition & 1 deletion trunk/Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ COPY . /srs
WORKDIR /srs/trunk

# Note that we must enable the gcc7 or link failed.
RUN scl enable devtoolset-7 -- ./configure --srt=on --gb28181=on --utest=on
RUN scl enable devtoolset-7 -- ./configure --srt=on --gb28181=on --h265=on --utest=on
RUN scl enable devtoolset-7 -- make utest

# Build benchmark tool.
Expand Down
6 changes: 6 additions & 0 deletions trunk/auto/auto_headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ else
srs_undefine_macro "SRS_FFMPEG_FIT" $SRS_AUTO_HEADERS_H
fi

if [[ $SRS_H265 == YES ]]; then
srs_define_macro "SRS_H265" $SRS_AUTO_HEADERS_H
else
srs_undefine_macro "SRS_H265" $SRS_AUTO_HEADERS_H
fi

if [[ $SRS_SIMULATOR == YES ]]; then
srs_define_macro "SRS_SIMULATOR" $SRS_AUTO_HEADERS_H
else
Expand Down
4 changes: 4 additions & 0 deletions trunk/auto/options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ help=no
SRS_HDS=NO
SRS_SRT=YES
SRS_RTC=YES
SRS_H265=NO
SRS_GB28181=NO
SRS_CXX11=YES
SRS_CXX14=NO
Expand Down Expand Up @@ -136,6 +137,7 @@ Features:
--cxx14=on|off Whether enable the C++14. Default: $(value2switch $SRS_CXX14)
--backtrace=on|off Whether show backtrace when crashing. Default: $(value2switch $SRS_BACKTRACE)
--ffmpeg-fit=on|off Whether enable the FFmpeg fit(source code). Default: $(value2switch $SRS_FFMPEG_FIT)
--h265=on|off Whether build the HEVC(H.265) support. Default: $(value2switch $SRS_H265)
--prefix=<path> The absolute installation path. Default: $SRS_PREFIX
--config=<path> The default config file for SRS. Default: $SRS_DEFAULT_CONFIG
Expand Down Expand Up @@ -305,6 +307,7 @@ function parse_user_option() {
--generate-objs) SRS_GENERATE_OBJS=$(switch2value $value) ;;
--single-thread) SRS_SINGLE_THREAD=$(switch2value $value) ;;
--ffmpeg-fit) SRS_FFMPEG_FIT=$(switch2value $value) ;;
--h265) SRS_H265=$(switch2value $value) ;;
--gb28181) SRS_GB28181=$(switch2value $value) ;;

--cxx11) SRS_CXX11=$(switch2value $value) ;;
Expand Down Expand Up @@ -587,6 +590,7 @@ function regenerate_options() {
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cherrypy=$(value2switch $SRS_CHERRYPY)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --srt=$(value2switch $SRS_SRT)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --rtc=$(value2switch $SRS_RTC)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --h265=$(value2switch $SRS_H265)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gb28181=$(value2switch $SRS_GB28181)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --simulator=$(value2switch $SRS_SIMULATOR)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cxx11=$(value2switch $SRS_CXX11)"
Expand Down
18 changes: 18 additions & 0 deletions trunk/conf/hevc.flv.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
listen 1935;
max_connections 1000;
daemon off;
srs_log_tank console;
http_api {
enabled on;
listen 1985;
}
http_server {
enabled on;
listen 8080;
}
vhost __defaultVhost__ {
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
}
}
3 changes: 2 additions & 1 deletion trunk/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ The changelog for SRS.

## SRS 6.0 Changelog

* v5.0, 2022-11-22, Merge [#3268](https://github.com/ossrs/srs/pull/3268): H265: Update mpegts.js to play HEVC over HTTP-TS/FLV. v6.0.1
* v6.0, 2022-11-22, Merge [#3272](https://github.com/ossrs/srs/pull/3272): H265: Support HEVC over RTMP or HTTP-FLV. v6.0.2
* v6.0, 2022-11-22, Merge [#3268](https://github.com/ossrs/srs/pull/3268): H265: Update mpegts.js to play HEVC over HTTP-TS/FLV. v6.0.1
* v6.0, 2022-11-22, Init SRS 6. v6.0.0

<a name="v5-changes"></a>
Expand Down
2 changes: 1 addition & 1 deletion trunk/ide/srs_clion/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ProcessorCount(JOBS)
# We should always configure SRS for switching between branches.
IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
EXECUTE_PROCESS(
COMMAND ./configure --osx --srt=on --gb28181=on --utest=on --jobs=${JOBS}
COMMAND ./configure --osx --srt=on --gb28181=on --h265=on --utest=on --jobs=${JOBS}
WORKING_DIRECTORY ${SRS_DIR} RESULT_VARIABLE ret)
ELSE ()
EXECUTE_PROCESS(
Expand Down
32 changes: 21 additions & 11 deletions trunk/src/app/srs_app_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,13 @@ srs_error_t SrsGopCache::cache(SrsSharedPtrMessage* shared_msg)

// got video, update the video count if acceptable
if (msg->is_video()) {
// drop video when not h.264
if (!SrsFlvVideo::h264(msg->payload, msg->size)) {
return err;
}

// Drop video when not h.264 or h.265.
bool codec_ok = SrsFlvVideo::h264(msg->payload, msg->size);
#ifdef SRS_H265
codec_ok = codec_ok ? : SrsFlvVideo::hevc(msg->payload, msg->size);
#endif
if (!codec_ok) return err;

cached_video_count++;
audio_after_last_video_count = 0;
}
Expand Down Expand Up @@ -1063,14 +1065,22 @@ srs_error_t SrsOriginHub::on_video(SrsSharedPtrMessage* shared_video, bool is_se

// when got video stream info.
SrsStatistic* stat = SrsStatistic::instance();
if ((err = stat->on_video_info(req_, SrsVideoCodecIdAVC, c->avc_profile, c->avc_level, c->width, c->height)) != srs_success) {

if (c->id == SrsVideoCodecIdAVC) {
err = stat->on_video_info(req_, c->id, c->avc_profile, c->avc_level, c->width, c->height);
srs_trace("%dB video sh, codec(%d, profile=%s, level=%s, %dx%d, %dkbps, %.1ffps, %.1fs)",
msg->size, c->id, srs_avc_profile2str(c->avc_profile).c_str(), srs_avc_level2str(c->avc_level).c_str(),
c->width, c->height, c->video_data_rate / 1000, c->frame_rate, c->duration);
#ifdef SRS_H265
} else if (c->id == SrsVideoCodecIdHEVC) {
// TODO: FIXME: Use the correct information for HEVC.
err = stat->on_video_info(req_, c->id, c->avc_profile, c->avc_level, c->width, c->height);
srs_trace("%dB video sh, codec(%d)", msg->size, c->id);
#endif
}
if (err != srs_success) {
return srs_error_wrap(err, "stat video");
}

srs_trace("%dB video sh, codec(%d, profile=%s, level=%s, %dx%d, %dkbps, %.1ffps, %.1fs)",
msg->size, c->id, srs_avc_profile2str(c->avc_profile).c_str(),
srs_avc_level2str(c->avc_level).c_str(), c->width, c->height,
c->video_data_rate / 1000, c->frame_rate, c->duration);
}

// Ignore video data when no sps/pps
Expand Down
11 changes: 11 additions & 0 deletions trunk/src/app/srs_app_statistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,17 @@ void SrsStatistic::dumps_hints_kv(std::stringstream & ss)
if (kbps->get_send_kbps_30s()) {
ss << "&send=" << kbps->get_send_kbps_30s();
}

#ifdef SRS_H265
// For HEVC, we should check active stream which is HEVC codec.
for (std::map<std::string, SrsStatisticStream*>::iterator it = streams.begin(); it != streams.end(); it++) {
SrsStatisticStream* stream = it->second;
if (stream->vcodec == SrsVideoCodecIdHEVC) {
ss << "&h265=1";
break;
}
}
#endif
}

void SrsStatistic::dumps_cls_summaries(SrsClsSugar* sugar)
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 1
#define VERSION_REVISION 2

#endif
Loading

0 comments on commit 178e40a

Please sign in to comment.