/
15_gst_transcode_plus_scale_la.sh
executable file
·214 lines (195 loc) · 8.52 KB
/
15_gst_transcode_plus_scale_la.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
#
# Copyright 2020-2022, Xilinx, Inc.
# Copyright 2022, Advanced Micro Device, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# pre-requisite to run this script: source /opt/xilinx/vvas/setup.sh
# This script assumes an 8-bit, YUV420, pre-encoded 60FPS contrainer with h.264 content as input. It will scale this input into multiple renditions of various sizes, and sends them to the encoder targeting various bitrates (as defined by the target-bitrate property of encoder). All outputs will be stored at /tmp/
# This script uses lookahead kernel used to improve the accuracy of rate control by enabling the encoder to buffer a specified number of frames
# The 1080p60 input is scaled down to the following resolutions, framerates, and bitrates (respectively):
# 720p60 4.0 Mbps
# 720p30 3.0 Mbps
# 848p30 2.5 Mbps
# 360p30 1.25 Mbps
# 288p30 0.625 Mbps
# You may edit this to enable other output bitrates (target-bitrate)
# You may change the output framerate via the framerate property
# You may change the target codecs to HEVC by changing:
# the h264parse plugin to h265parse plugin for decoding from HEVC
# Removing qtdemux script supports the input h.264 files instead of MP4 with h.264 content
if [ $# -lt 3 ]; then
echo -e "\e[01;31m"WARNING : Script did not run. Check the below help on how to run the script and arguments to be given"\e[0m"
echo "$0 <device index> <Input 1080p60 H264 File> <num instances, 1 to 4> <Number of buffers> <fakesink 0/1>"
echo ""
echo -e "\e[01;31m"e.g $0 0 bbb_sunflower_1080p_60fps_normal.mp4 2 2000 0"\e[0m"
echo "<Number of buffers> - Input number of buffers to be processed from input file (each buffer is of size 4K)"
echo "NOTE: Running this script displays the average fps values on terminal for all instances using notation <reoslution>_<deviceid>_<instance_number>"
echo "e.g. sink_720p60_0_2: last-message = rendered: 4443, dropped: 0, current: 93.77, average: 61.89."
echo "This shows 72p60 ladder for device 0 and instance 2 is running at 61.89 fps"
echo "This script runs all the instances in the background and can not be killed using ctrl+C"
echo "Ensure that the input MP4 stream resolution given as input argument is not beyond 1080p60"
echo ""
exit 1
fi
#check if the input stream is compatiable with this script
container=`gst-discoverer-1.0 $2 | grep "container:" | cut -d":" -f2`
codec_type=`gst-discoverer-1.0 $2 | grep "video codec:" | cut -d":" -f2 | awk '{print $1;}'`
echo $container
echo $codec_type
if [ -z "$container" ] && [ -z "$codec_type" ]; then
echo "Input file is of unknown/unsupported type"
exit -1
elif [ -z "$container" ] && [ "$codec_type" = "H.264" ]; then
echo "Input file is of type H.264";
demuxer="";
elif [ -z "$container" ] && [ "$codec_type" = "H.265" ]; then
echo "Input file is of type H.265. Invalid for this script";
exit -1
elif [ $container = "Quicktime" ] && [ "$codec_type" = "H.264" ]; then
echo "Input file is of type Quicktime H.264";
demuxer="! qtdemux ! queue"
elif [ $container = "Quicktime" ] && [ "$codec_type" = "H.265" ]; then
echo "Input file is of type Quicktime H.265. Invalid for this script";
exit -1
else
echo "Input file is of unknown/unsupported type"
exit -1
fi
#number of supported devices
num_dev=$(xbutil list | grep xilinx_u30 | wc -l)
#check if argument1 is an integer
re='^[0-9]+$'
if ! [[ $1 =~ $re ]] ; then
echo "error: Give a number for argument 1 with in the range of 0 to $num_dev"; exit 1
fi
#Check if valid device index is given as argument 1
if [ $1 -ge $num_dev ]; then
echo "Device index is not correct, exiting"
exit
else
di=$1
fi
#check if input_file extension is mp4
input_file=$2
if [ $3 -gt 4 ]; then
echo "you gave $3. Num instances can not be more than 4, exiting"
exit
fi
if [ -z "$4" ]; then
echo "num-buffers not passed, setting to 2000"
num=2000
else
echo "num-buffers defined"
num=$4
fi
d=$di
num_instance=$3
#Check if number of instances is given a value of at least <1>
if [ $3 -lt 1 ]; then
echo "Num instances are not correct. It should be 1 at least. Run $0 for help"
exit
fi
for (( c = 0; c < $num_instance; c++ ))
do
sc_name="sc_"$c$d
tee_name="tee_"$c$d
enc_720p60="enc_720p60_dev"$d"_"$c
enc_720p30="enc_720p30_dev"$d"_"$c
enc_480p30="enc_480p30_dev"$d"_"$c
enc_360p30="enc_360p30_dev"$d"_"$c
enc_160p30="enc_160p30_dev"$d"_"$c
fps_sink_720p60="sink_xcode_scale_720p60_dev"$d"_"$c
fps_sink_720p30="sink_xcode_scale_720p30_dev"$d"_"$c
fps_sink_480p30="sink_xcode_scale_480p30_dev"$d"_"$c
fps_sink_360p30="sink_xcode_scale_360p30_dev"$d"_"$c
fps_sink_160p30="sink_xcode_scale_160p30_dev"$d"_"$c
if [[ $5 -eq 0 ]]; then
echo "Script is running for filesink...."
muxer="! qtmux"
sink_720p60="\"filesink location=/\tmp/\xil_la_xcode_scale_720p60_dev_${Depth}_${d}_${c}.mp4 async=false\""
sink_720p30="\"filesink location=/\tmp/\xil_la_xcode_scale_720p30_dev_${Depth}_${d}_${c}.mp4 async=false\""
sink_480p30="\"filesink location=/\tmp/\xil_la_xcode_scale_480p30_dev_${Depth}_${d}_${c}.mp4 async=false\""
sink_360p30="\"filesink location=/\tmp/\xil_la_xcode_scale_360p30_dev_${Depth}_${d}_${c}.mp4 async=false\""
sink_160p30="\"filesink location=/\tmp/\xil_la_xcode_scale_160p30_dev_${Depth}_${d}_${c}.mp4 async=false\""
else
echo "Script is running for fakesink...."
muxer=
sink_720p60="\"fakesink async=false\""
sink_720p30="\"fakesink async=false\""
sink_480p30="\"fakesink async=false\""
sink_360p30="\"fakesink async=false\""
sink_160p30="\"fakesink async=false\""
fi
pipe="gst-launch-1.0 filesrc num-buffers=$num location=$input_file
${demuxer}
! h264parse
! vvas_xvcudec dev-idx=$di ! queue
! vvas_xabrscaler avoid-output-copy=true dev-idx=$di ppc=4 scale-mode=2 name=$sc_name
$sc_name.src_0
! queue
! video/x-raw, width=1280, height=720
! tee name=$tee_name
$tee_name.
! queue
! videorate
! video/x-raw, framerate=60/1
! vvas_xlookahead codec-type=0 spatial-aq=1 temporal-aq=1 lookahead-depth=8 dev-idx=$di
! vvas_xvcuenc name=$enc_720p60 dev-idx=$di target-bitrate=4000 rc-mode=1
! h264parse
${muxer}
! fpsdisplaysink name=$fps_sink_720p60 video-sink=$sink_720p60 text-overlay=false sync=false
$tee_name.
! queue
! videorate
! video/x-raw, framerate=30/1
! vvas_xlookahead codec-type=0 spatial-aq=1 temporal-aq=1 lookahead-depth=8 dev-idx=$di
! vvas_xvcuenc name=$enc_720p30 dev-idx=$di target-bitrate=3000 rc-mode=1
! h264parse
${muxer}
! fpsdisplaysink name=$fps_sink_720p30 video-sink=$sink_720p30 text-overlay=false sync=false
$sc_name.src_1
! queue
! video/x-raw, width=848, height=480
! videorate
! video/x-raw, framerate=30/1
! vvas_xlookahead codec-type=0 spatial-aq=1 temporal-aq=1 lookahead-depth=8 dev-idx=$di
! vvas_xvcuenc name=$enc_480p30 dev-idx=$di target-bitrate=2500 rc-mode=1
! h264parse
${muxer}
! fpsdisplaysink name=$fps_sink_480p30 video-sink=$sink_480p30 text-overlay=false sync=false
$sc_name.src_2
! queue
! video/x-raw, width=640, height=360
! videorate
! video/x-raw, framerate=30/1
! vvas_xlookahead codec-type=0 spatial-aq=1 temporal-aq=1 lookahead-depth=8 dev-idx=$di
! vvas_xvcuenc name=$enc_360p30 dev-idx=$di target-bitrate=1250 rc-mode=1
! h264parse
${muxer}
! fpsdisplaysink name=$fps_sink_360p30 video-sink=$sink_360p30 text-overlay=false sync=false
$sc_name.src_3
! queue
! video/x-raw, width=288, height=160
! videorate
! video/x-raw, framerate=30/1
! vvas_xlookahead codec-type=0 spatial-aq=1 temporal-aq=1 lookahead-depth=8 dev-idx=$di
! vvas_xvcuenc name=$enc_160p30 dev-idx=$di target-bitrate=625 rc-mode=1
! h264parse
${muxer}
! fpsdisplaysink name=$fps_sink_160p30 video-sink=$sink_160p30 text-overlay=false sync=false -v"
#pipe="gst-launch-1.0 "$pipe
$pipe &
done
wait