/
12_ffmpeg_streaming_transcode_from_file.sh
executable file
·86 lines (71 loc) · 4.73 KB
/
12_ffmpeg_streaming_transcode_from_file.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
#!/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.
#
# This script accepts an 8-bit, YUV420, pre-encoded h264 file and will send the encoded h.264 output in a set of HLS streams located at /var/www/html/xil_xcode_stream_scale_*.m3u8
# You may edit this to enable other output bitrates (-b:v).
# The 1080p60 input is scaled down to the following resolutions, framerates, and bitrates (respectively):
# 720p60 4.0 Mbps
# 720p30 3.0 Mbps
# 480p30 2.5 Mbps
# 360p30 1.25 Mbps
# 160p30 0.625 Mbps
# Most webservers host their "accessible locations" from /var/www/html/. This will not exist without a webserver (e.g. Apache2) installed. Please ensure one is installed and the directory is writable; otherwise this script will fail.
# You may change the target codecs to HEVC by changing:
# the first instance of (-c:v mpsoc_vcu_h264) to (-c:v mpsoc_vcu_hevc) for decoding from HEVC
# the second instance of (-c:v mpsoc_vcu_h264) to (-c:v mpsoc_vcu_hevc) for encoding into HEVC
# Stream settings may be changed to accomodate different needs:
# "-hls_time 4"
# Sets the segment length to 4 seconds
# "-hls_list_size 5"
# Sets the number of 4-second segments to 5 to be saved in the playlist/manifest
# "-hls_flags delete_segments"
# Deletes segments after reaching the specificed list size (in this case 5)
# The command below doesn't handle the audio channel of the input video. For an example of how to include
# audio in the output streams, refer to the example commented out at the bottom of this script.
if [ $# -ne 1 ]
then
echo "Incorrect arguments supplied"
echo "Usage: $(basename $0) <1080p60 h264 clip>"
exit 1
fi
ffmpeg -c:v mpsoc_vcu_h264 -i $1 \
-filter_complex "multiscale_xma=outputs=4: \
out_1_width=1280: out_1_height=720: out_1_rate=full: \
out_2_width=848: out_2_height=480: out_2_rate=half: \
out_3_width=640: out_3_height=360: out_3_rate=half: \
out_4_width=288: out_4_height=160: out_4_rate=half \
[a][b][c][d]; [a]split[aa][ab]; [ab]fps=30[abb]" \
-map "[aa]" -b:v 4M -c:v mpsoc_vcu_h264 -f hls -hls_time 4 -hls_list_size 5 -hls_flags delete_segments -y /var/www/html/xil_xcode_stream_scale_720p60.m3u8 \
-map "[abb]" -b:v 3M -c:v mpsoc_vcu_h264 -f hls -hls_time 4 -hls_list_size 5 -hls_flags delete_segments -y /var/www/html/xil_xcode_stream_scale_720p30.m3u8 \
-map "[b]" -b:v 2500K -c:v mpsoc_vcu_h264 -f hls -hls_time 4 -hls_list_size 5 -hls_flags delete_segments -y /var/www/html/xil_xcode_stream_scale_480p30.m3u8 \
-map "[c]" -b:v 1250K -c:v mpsoc_vcu_h264 -f hls -hls_time 4 -hls_list_size 5 -hls_flags delete_segments -y /var/www/html/xil_xcode_stream_scale_360p30.m3u8 \
-map "[d]" -b:v 625K -c:v mpsoc_vcu_h264 -f hls -hls_time 4 -hls_list_size 5 -hls_flags delete_segments -y /var/www/html/xil_xcode_stream_scale_160p30.m3u8
# FFmpeg command to process audio as well as video.
# Should only be used if the input video has an audio channel.
# ffmpeg -c:v mpsoc_vcu_h264 -i $1 \
# -filter_complex "multiscale_xma=outputs=4: \
# out_1_width=1280: out_1_height=720: out_1_rate=full: \
# out_2_width=848: out_2_height=480: out_2_rate=half: \
# out_3_width=640: out_3_height=360: out_3_rate=half: \
# out_4_width=288: out_4_height=160: out_4_rate=half \
# [a][b][c][d]; [a]split[aa][ab]; [ab]fps=30[abb]; \
# [0:1]asplit=outputs=5[aud1][aud2][aud3][aud4][aud5]" \
# -map "[aa]" -b:v 4M -c:v mpsoc_vcu_h264 -map "[aud1]" -f hls -hls_time 4 -hls_list_size 5 -hls_flags delete_segments -y /var/www/html/xil_xcode_stream_scale_720p60.m3u8 \
# -map "[abb]" -b:v 3M -c:v mpsoc_vcu_h264 -map "[aud2]" -f hls -hls_time 4 -hls_list_size 5 -hls_flags delete_segments -y /var/www/html/xil_xcode_stream_scale_720p30.m3u8 \
# -map "[b]" -b:v 2500K -c:v mpsoc_vcu_h264 -map "[aud3]" -f hls -hls_time 4 -hls_list_size 5 -hls_flags delete_segments -y /var/www/html/xil_xcode_stream_scale_480p30.m3u8 \
# -map "[c]" -b:v 1250K -c:v mpsoc_vcu_h264 -map "[aud4]" -f hls -hls_time 4 -hls_list_size 5 -hls_flags delete_segments -y /var/www/html/xil_xcode_stream_scale_360p30.m3u8 \
# -map "[d]" -b:v 625K -c:v mpsoc_vcu_h264 -map "[aud5]" -f hls -hls_time 4 -hls_list_size 5 -hls_flags delete_segments -y /var/www/html/xil_xcode_stream_scale_160p30.m3u8