/useful/trunk-1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/useful/trunk-1

« back to all changes in this revision

Viewing changes to scripts/video2lbry.sh

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-13 18:44:02 UTC
  • Revision ID: git-v1:0dbf5fcfbb68944b25dbeeeceb02ac414ac330ad
Inital code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env bash
 
2
###################
 
3
# FILE NAME: video2lbry.sh
 
4
#
 
5
# Encodes videos so they are ready to be uploaded to LBRY.
 
6
#
 
7
####################
 
8
ARGS=()
 
9
ARGS="${@}"
 
10
 
 
11
__IN_NAME=
 
12
__OUT_NAME=
 
13
 
 
14
__help () {
 
15
  echo "video2lbry.sh -- Make vide ready for upload to LBRY."
 
16
  echo " "
 
17
  echo "-i <input video file>     Input Video File."
 
18
  echo " "
 
19
  echo "-o <output video file>    Output Video File"
 
20
  echo "                          (_lbry.mp4 will be added to the end)."
 
21
  echo " "
 
22
}
 
23
 
 
24
__enc_mp4 () {
 
25
  ffmpeg -y -i "$__IN_NAME"\
 
26
          -threads 7\
 
27
          -c:v libx264\
 
28
          -crf 21\
 
29
          -preset slower\
 
30
          -pix_fmt yuv420p\
 
31
          -maxrate 5000K\
 
32
          -bufsize 5000K\
 
33
          -vf 'scale=if(gte(iw\,ih)\,min(2560\,iw)\,-2):if(lt(iw\,ih)\,min(2560\,ih)\,-2)'\
 
34
          -movflags +faststart\
 
35
          -c:a aac\
 
36
          -b:a 256k\
 
37
          "${__OUT_NAME}_lbry.mp4"
 
38
}
 
39
 
 
40
__parse_args() {
 
41
  if [ -z "$1" ]
 
42
  then
 
43
    echo "Try --help or -h."
 
44
    exit 1
 
45
  fi
 
46
  
 
47
  
 
48
  while [[ $# -gt 0 ]]
 
49
  do
 
50
    eval key="${1}"
 
51
    
 
52
    case "${1}" in
 
53
      -i)
 
54
      __IN_NAME="$2"
 
55
      shift
 
56
      shift
 
57
      ;;
 
58
      -o)
 
59
      __OUT_NAME="$2"
 
60
      shift
 
61
      shift
 
62
      ;;
 
63
      -m)
 
64
      __USE_WEBM=true
 
65
      shift
 
66
      ;;
 
67
      -h|--help)
 
68
      __help
 
69
      shift
 
70
      ;;
 
71
      *)
 
72
      __help
 
73
      exit
 
74
      shift
 
75
      ;;
 
76
      --)
 
77
      shift
 
78
      break
 
79
      ;;
 
80
    esac
 
81
  done
 
82
}
 
83
 
 
84
__main () {
 
85
  if [ ! -e "$__IN_NAME" ]
 
86
  then
 
87
    echo "missing input audio. Please provide."
 
88
    exit 1
 
89
  fi
 
90
  
 
91
  if [ $__OUT_NAME == "" ]
 
92
  then
 
93
    echo "missing output file name. Please provide."
 
94
    exit 1
 
95
  fi
 
96
  
 
97
  
 
98
  if [ $__IN_NAME = ${__OUT_NAME}_lbry.mp4 ]
 
99
  then
 
100
    echo "Filenames can't be the same."
 
101
    exit
 
102
  fi
 
103
  __enc_mp4
 
104
}
 
105
 
 
106
__parse_args "${@}"
 
107
__main