forked from mediamicroservices/mm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeyoutube
More file actions
executable file
·108 lines (96 loc) · 4.2 KB
/
makeyoutube
File metadata and controls
executable file
·108 lines (96 loc) · 4.2 KB
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
#!/bin/bash
# makeyoutube
# makes a file appropriate for uploading to youtube
version="1.0"
unset dependencies
dependencies=(ffmpeg)
deliverdir=""
scriptdir=$(dirname "$0")
. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;};
usage(){
echo
echo "$(basename $0) ${version}"
echo "This application will create a high quality h264 file (suitable for uploading to YouTube) from a video file or package input with the following options."
echo "Dependencies: ${dependencies[@]}"
echo "Usage: $(basename $0) [ -d /path/to/deliver/to/ ] fileorpackage1 [ fileorpackage2 ...]"
echo " -d directory ( directory to deliver the resulting file to )"
echo " -h ( display this help )"
echo
exit
}
[ "$#" = 0 ] && usage
check_dependencies "${dependencies[@]}"
cleanup(){
log -a "Process aborted"
exit 1
}
trap cleanup SIGHUP SIGINT SIGTERM
# command-line options to set mediaid and original variables
OPTIND=1
while getopts ":hd:" opt; do
case "$opt" in
h) usage ;;
d)
deliverdir="$OPTARG"
[ ! -d "$deliverdir" ] && report -wt "The delivery directory, ${deliverdir}, does not exist. Can not deliver the output of $(basename "$0")."
;;
*) echo "bad option -$OPTARG" ; usage ;;
:) echo "Option -$OPTARG requires an argument" ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
while [ "$*" != "" ] ; do
input="$1"
[ -d "$input" ] && { outputdir="$input/objects/access/youtube_up" && logdir="$input/metadata/submissionDocumentation/logs" ;};
[ -f "$input" ] && { outputdir=$(dirname "$input")"/access/youtube_up" && logdir="$(dirname "$input")/access/logs" ;};
[ ! "$outputdir" ] && { outputdir="$input/objects/access/youtube_up" && logdir="$input/metadata/submissionDocumentation/logs" ;};
find_input "$input"
filename=$(basename "$sourcefile")
mediaid=$(basename "$1" | cut -d. -f1)
log -b
youtubeoutput="${outputdir}/${mediaid%.*}.mp4"
[ -s "${youtubeoutput}" ] && { report -wt "WARNING ${youtubeoutput} already exists, skipping transcode" ; [ "$#" = 1 ] && exit 86 || { shift ; continue ;} ;};
mkdir -p "${outputdir}"
get_height "${sourcefile}"
get_width "${sourcefile}"
unset inputoptions
inputoptions+=(-vsync 0)
unset middleoptions
middleoptions+=(-movflags faststart)
middleoptions+=(-pix_fmt yuv420p)
middleoptions+=(-c:v libx264)
middleoptions+=(-crf 18)
if [ "${height}" -eq "486" -a "${width}" -eq "720" ] ; then
middleoptions+=(-vf "crop=720:480:0:4,yadif")
elif [ "${height}" -eq "512" -a "${width}" -eq "720" ] ;then
middleoptions+=(-vf "crop=720:480:0:32,yadif")
else
middleoptions+=(-vf yadif)
fi
middleoptions+=(-c:a libfaac)
middleoptions+=(-b:a 128k)
middleoptions+=(-f mp4)
if [ "${logdir}" != "" ] ; then
mkdir -p "${logdir}"
export FFREPORT="file=${logdir}/%p_%t_$(basename $0)_${version}.txt"
inputoptions+=(-v warning -stats)
fi
report -dt "Working on $(basename ${youtubeoutput}) for youtube upload."
report -dt "Running: ffmpeg ${inputoptions[@]} -i \"${sourcefile}\" ${middleoptions[@]} \"${youtubeoutput}\""
ffmpeg ${inputoptions[@]} -i "${sourcefile}" ${middleoptions[@]} "${youtubeoutput}"
echo
#chapterlist=$(ffmpeg -i "$sourcefile" 2>&1 | grep "Chapter #0." | awk '{print $4}' | tr -d "\n" | sed '$s/.$//') && { chaptered="Y" ; report "Found chapters found in $sourcefile" ;};
#if [ chaptered="Y" ] ; then
#if [ "$logdir" != "" ] ; then
#export FFREPORT="file=${logdir}/%p_%t_$(basename $0)_segmented_${version}.txt"
#fi
#-force_key_frames $chapterlist
#segmentcommand="ffmpeg $inputoptions -i \"$sourcefile\" $middleoptions -r:v ntsc -map 0:v -map 0:a -f segment -segment_times $chapterlist -reset_timestamps 1 #-segment_start_number 1 -segment_time_delta 0.05 \"${youtubeoutput%.*}_S%02d.mp4\""
#report -dt "Running: $segmentcommand"
#eval "$segmentcommand"
#fi
report -dt "$(basename ${youtubeoutput}) is done."
[ -d "${deliverdir}" ] && { report -dt "Delivering output" ; cp -av "${youtubeoutput}" "${deliverdir}/" ;};
shift
log -e
done