Skip to content

Commit

Permalink
Use int(input_height/2) to compute low quality video layer height.
Browse files Browse the repository at this point in the history
It should fix issue with aspect ratio other than 16:9.
  • Loading branch information
DerouineauNicolas committed Jul 27, 2022
1 parent ee7a84e commit 407a8ed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
12 changes: 7 additions & 5 deletions backend/StreamServerApp/database_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ def prepare_video(video_full_path,
audio_codec_type = audio_stream['codec_name']
audio_elementary_stream_path = "{}.m4a".format(
os.path.splitext(video_full_path)[0])
video_elementary_stream_path_480 = "{}_480.264".format(
os.path.splitext(video_full_path)[0])

video_elementary_stream_path_high_layer = "{}_{}.264".format(
os.path.splitext(video_full_path)[0], video_height)

Expand All @@ -380,6 +379,9 @@ def prepare_video(video_full_path,
24 * 4 * (high_layer_compression_ratio/100.0)
print("high_layer_bitrate = {}".format(high_layer_bitrate))
low_layer_bitrate = int(os.getenv('480P_LAYER_BITRATE', 400000))
low_layer_height = int(video_height / 2.0)
video_elementary_stream_path_low_layer = "{}_low.264".format(
os.path.splitext(video_full_path)[0])

h264_encoder(
video_full_path,
Expand All @@ -388,7 +390,7 @@ def prepare_video(video_full_path,
if low_layer_bitrate > 0:
h264_encoder(
video_full_path,
video_elementary_stream_path_480, 480, low_layer_bitrate)
video_elementary_stream_path_low_layer, low_layer_height, low_layer_bitrate)

relative_path = os.path.relpath(video_full_path, video_path)

Expand All @@ -403,13 +405,13 @@ def prepare_video(video_full_path,
generate_thumbnail(video_full_path, duration, thumbnail_fullpath)

#Dash_packaging
dash_packager(video_elementary_stream_path_480, low_layer_bitrate,
dash_packager(video_elementary_stream_path_low_layer, low_layer_bitrate, low_layer_height,
video_elementary_stream_path_high_layer, high_layer_bitrate, video_height, audio_elementary_stream_path,
dash_output_directory)

os.remove(video_elementary_stream_path_high_layer)
if low_layer_bitrate > 0:
os.remove(video_elementary_stream_path_480)
os.remove(video_elementary_stream_path_low_layer)
os.remove(audio_elementary_stream_path)

if not keep_files:
Expand Down
6 changes: 3 additions & 3 deletions backend/StreamServerApp/media_management/dash_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import json


def dash_packager(video_layer_480p, low_layer_bitrate, video_layer_high_quality, high_layer_bitrate, high_layer_resolution, audio_layer, outputdirectory):
def dash_packager(video_layer_low_quality , low_layer_bitrate, low_layer_height, video_layer_high_quality, high_layer_bitrate, high_layer_resolution, audio_layer, outputdirectory):
command = 'MP4Box -dash 4000 -frag 4000 -rap \
-segment-name \'segment_$RepresentationID$_\' -fps 24 '

if low_layer_bitrate > 0:
command += '"{video_layer_low}"#video:id=480p:#Bitrate={low_layer_bitrate} '.format(
video_layer_low=video_layer_480p, low_layer_bitrate=low_layer_bitrate)
command += '"{video_layer_low}"#video:id={low_layer_height}p:#Bitrate={low_layer_bitrate} '.format(
video_layer_low=video_layer_low_quality, low_layer_bitrate=low_layer_bitrate, low_layer_height=low_layer_height)

command += '"{video_layer_high}"#video:id={high_layer_resolution}p:#Bitrate={high_layer_bitrate} \
"{audio_layer}"#audio:id=English:role=main \
Expand Down
12 changes: 8 additions & 4 deletions backend/StreamServerApp/tests/tests_dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ def setUp(self):
print("Init keyframe_analysis test ")

def test_dash_packaging(self):
input_height = 720
low_layer_height = int(input_height / 2.0)
h264_encoder(
"/usr/src/app/Videos/The.Big.Lebowski.1998.720p.BrRip.x264.YIFY.mp4",
"/usr/src/app/Videos/lebowsky_720.264", 720, 1800000)
h264_encoder(
"/usr/src/app/Videos/The.Big.Lebowski.1998.720p.BrRip.x264.YIFY.mp4",
"/usr/src/app/Videos/lebowsky_480.264", 480, 800000)
"/usr/src/app/Videos/lebowsky_low.264", low_layer_height, 800000)
aac_encoder(
"/usr/src/app/Videos/The.Big.Lebowski.1998.720p.BrRip.x264.YIFY.mp4",
"/usr/src/app/Videos/lebowsky.m4a")
dash_packager("/usr/src/app/Videos/lebowsky_480.264",
dash_packager("/usr/src/app/Videos/lebowsky_low.264",
800000,
low_layer_height,
"/usr/src/app/Videos/lebowsky_720.264",
1800000,
720,
Expand All @@ -48,10 +51,11 @@ def test_dash_packaging(self):
self.assertEqual(os.path.isfile(
"/usr/src/app/Videos/lebowskydash/segment_720p_1.m4s"), True)
self.assertEqual(os.path.isfile(
"/usr/src/app/Videos/lebowskydash/segment_480p_1.m4s"), True)
"/usr/src/app/Videos/lebowskydash/segment_{}p_1.m4s".format(low_layer_height)), True)

dash_packager("/usr/src/app/Videos/lebowsky_480.264",
0,
low_layer_height,
"/usr/src/app/Videos/lebowsky_720.264",
1800000,
720,
Expand All @@ -61,4 +65,4 @@ def test_dash_packaging(self):
self.assertEqual(os.path.isfile(
"/usr/src/app/Videos/lebowskydash2/segment_720p_1.m4s"), True)
self.assertEqual(os.path.isfile(
"/usr/src/app/Videos/lebowskydash2/segment_480p_1.m4s"), False)
"/usr/src/app/Videos/lebowskydash2/segment_{}p_1.m4s".format(low_layer_height)), False)

0 comments on commit 407a8ed

Please sign in to comment.