Skip to content

Commit

Permalink
vprofile check wip
Browse files Browse the repository at this point in the history
default config and gitignore

dry run added
  • Loading branch information
DeFiYaco committed Dec 19, 2020
1 parent 19317b3 commit 2648884
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data
config
processed_files
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ Usage
- `--delete-on-success` deletes the original file on success instead of renaming it to `<original_filename>.bak`
- `--force-vencode` forces re-encoding of the video, if the codec is supported but the profile level is too high
- `--force-aencode` forces re-encoding of the audio
- `--dry-run` writes out the command on stdout that would be used for the particular file instead of running it
- `--config=/path/to/config` specify where to store configuration. When omitted the default folder `~/.chromecastize` is used.

Changing default options
------------------------
- Copy the example `config.sh` file to your config folder (default location: `~/.chromecastize`).
- Copy the example `config.example` file to your config folder (default location: `~/.chromecastize`).
- Rename it to `config`.
- Uncomment the options which you wish to change by removing the leading `#` symbol.

Authors
Expand Down
33 changes: 28 additions & 5 deletions chromecastize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ UNSUPPORTED_GFORMATS=('BDAV' 'AVI' 'Flash Video' 'DivX')
SUPPORTED_VCODECS=('AVC' 'VP8')
UNSUPPORTED_VCODECS=('MPEG-4 Visual' 'xvid' 'MPEG Video' 'HEVC')

SUPPORTED_VFPROFILE=('[email protected]' 'High@L4' '[email protected]')
UNSUPPORTED_VFPROFILE=('High 10@L5')

SUPPORTED_ACODECS=('AAC' 'MPEG Audio' 'Vorbis' 'Ogg' 'Opus')
UNSUPPORTED_ACODECS=('AC-3' 'DTS' 'E-AC-3' 'PCM' 'TrueHD' 'FLAC')

Expand Down Expand Up @@ -44,7 +47,7 @@ in_array() {
}

print_help() {
echo "Usage: chromecastize.sh [--mp4 | --mkv | --stereo | --force-vencode | --force-aencode | --config=/path/to/config/] <videofile1> [videofile2 ...]"
echo "Usage: chromecastize.sh [--mp4 | --mkv | --stereo | --force-vencode | --force-aencode | --dry-run | --config=/path/to/config/] <videofile1> [videofile2 ...]"
}

unknown_codec() {
Expand Down Expand Up @@ -78,6 +81,17 @@ is_supported_vcodec() {
fi
}

is_supported_vfprofile() {
if in_array "$1" "${SUPPORTED_VFPROFILE[@]}"; then
return 0
elif in_array "$1" "${UNSUPPORTED_VFPROFILE[@]}"; then
return 1
else
unknown_codec "$1"
exit 1
fi
}

is_supported_acodec() {
# Support for multichannel AAC audio has been removed in firmware 1.28.
# Ref. https://issuetracker.google.com/issues/69112577#comment4
Expand Down Expand Up @@ -168,7 +182,7 @@ process_file() {

INPUT_VCODEC=`$MEDIAINFO --Inform="Video;%Format%\n" "$FILENAME" 2> /dev/null | head -n1`
ENCODER_OPTIONS=""
if is_supported_vcodec "$INPUT_VCODEC" && [ -z "$FORCE_VENCODE" ]; then
if is_supported_vcodec "$INPUT_VCODEC" && is_supported_vfprofile "$INPUT_VCODEC_PROFILE" [ -z "$FORCE_VENCODE" ]; then
OUTPUT_VCODEC="copy"
else
OUTPUT_VCODEC="$DEFAULT_VCODEC"
Expand Down Expand Up @@ -205,7 +219,13 @@ process_file() {
# Make sure the encoder options are not escaped with quotes.
IFS=' ' read -r -a ENCODER_OPTIONS_ARRAY <<< "$ENCODER_OPTIONS"

$FFMPEG -loglevel error -stats -i "$FILENAME" -map 0 -scodec copy -vcodec "$OUTPUT_VCODEC" -acodec "$OUTPUT_ACODEC" ${ENCODER_OPTIONS_ARRAY[@]} "$FILENAME.$OUTPUT_GFORMAT" && on_success "$FILENAME" "$DESTINATION_FILENAME" || on_failure "$FILENAME"
COMMAND="$FFMPEG -loglevel error -stats -i "$FILENAME" -map 0 -scodec copy -vcodec "$OUTPUT_VCODEC" -acodec "$OUTPUT_ACODEC" ${ENCODER_OPTIONS_ARRAY[@]} "$FILENAME.$OUTPUT_GFORMAT" && on_success "$FILENAME" "$DESTINATION_FILENAME" || on_failure "$FILENAME""

if [ -z $DRY_RUN ]; then
eval $COMMAND
else
echo $COMMAND
fi
echo ""
fi
}
Expand Down Expand Up @@ -263,6 +283,9 @@ while :; do
--stereo)
STEREO=1
;;
--dry-run)
DRY_RUN=1
;;
--config=?*)
CONFIG_DIRECTORY=${1#*=}
;;
Expand Down Expand Up @@ -315,8 +338,8 @@ if ! [ -w "$CONFIG_DIRECTORY" ]; then
fi

# Load default configuration if it exists.
if [ -f "$CONFIG_DIRECTORY/config.sh" ]; then
. "$CONFIG_DIRECTORY/config.sh"
if [ -f "$CONFIG_DIRECTORY/config" ]; then
. "$CONFIG_DIRECTORY/config"
fi

# Ensure that the processed file list exists and is writeable.
Expand Down
3 changes: 2 additions & 1 deletion config.sh → config.example
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
# Option to recode multichannel audio to stereo. Use this if you have problems
# playing multichannel audio on your device, or if you do not have a surround
# setup.
# STEREO=1
#STEREO=1

# What to do on successful conversion?
# Options are:
Expand All @@ -128,6 +128,7 @@
#SUPPORTED_GFORMATS=('MPEG-4' 'Matroska' 'WebM')
#DEFAULT_GFORMAT=mkv
#SUPPORTED_VCODECS=('AVC' 'VP8')
#SUPPORTED_VFPROFILE=('[email protected]' 'High@L4' '[email protected]')
#DEFAULT_VCODEC=h264
#DEFAULT_VCODEC_OPTS="-preset fast -profile:v high -level 4.2 -crf 17 -pix_fmt yuv420p"
#SUPPORTED_ACODECS=('AAC' 'MPEG Audio' 'Vorbis' 'Ogg' 'Opus')
Expand Down

0 comments on commit 2648884

Please sign in to comment.