Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigns standard values to matroska video properties #251

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nkaplan4250
Copy link

This application checks if a matroska video is consistent with a set of
standards properties and if so, it will assign expected values to other
properties that are either undefined or differ from expectations. The
properties that will be changed to their expected values are as
follows:
Interlaced = 1
Display width = 4
Display height = 3
Display unit = 3
Colour range = 1
Colour transfer = 1
Colour primaries = 6
If these properties are already defined but differ from the value above
the user will be asked if they would like to change the assigned value
to the expected value. Using -f will force the changes to the
properties regardless of existing values and without requesting any
further user input. Using -r will retain any existing values assigned
to properties without requiring user input. Undefined properties will
be assigned their expected values in either case.

This application checks if a matroska video is consistent with a set of
standards properties and if so, it will assign expected values to other
properties that are either undefined or differ from expectations. The
properties that will be changed to their expected values are as
follows:
Interlaced = 1
Display width = 4
Display height = 3
Display unit = 3
Colour range = 1
Colour transfer = 1
Colour primaries = 6
If these properties are already defined but differ from the value above
the user will be asked if they would like to change the assigned value
to the expected value. Using -f will force the changes to the
properties regardless of existing values and without requesting any
further user input. Using -r will retain any existing values assigned
to properties without requiring user input. Undefined properties will
be assigned their expected values in either case.
standardguess Outdated
#!/bin/bash
#checks to see if a video's properties are consistent with a set of standards and if so it assigns expected values to other properties if they are undefined or differ from expectations

SCRIPTDIR=$(dirname $(which "${0}"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth quoting the $() layer too, such as SCRIPTDIR="$(dirname $(which "${0}")")

standardguess Outdated
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ;};

_get_frame_rate(){
FRAMERATE=$(ffprobe -i "${1}" -v error -select_streams v:0 -show_entries stream=avg_frame_rate -of default=noprint_wrappers=1:nokey=0 | grep "^avg_frame_rate=" | cut -d = -f 2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add a dependency check on the tools used, such as ffprobe, mkvinfo, and mkvpropedit. The dependencies are listed in an array such as

DEPENDENCIES=(ffmpeg ffprobe)
and then checked with a function from mmfunction such as

mm/fix_rewrap

Line 21 in 437c6c7

_check_dependencies "${DEPENDENCIES[@]}"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also is -v error useful here, it may just make the output noisy.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you set nokey=1 then you won't need to pipe to grep and cut to parse the value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that -v error tells ffprobe to report errors only. Without it prints out all the version info for ffmpeg, ffprobe, etc...

standardguess Outdated
EXPECTATION="$3"
MKVINFO_PROP=$(mkvinfo -t "${1}")
SELECTED_ELEMENT=$(echo "${MKVINFO_PROP}" | grep -c "+ ${ELEMENT}:")
SELECTED_ELEMENT_VALUE=$(echo "${MKVINFO_PROP}" | grep -i "+ ${ELEMENT}: " | cut -d: -f 2 | sed 's/ //g' | sed 's/(aspectratio)//g')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is aspectratio referenced like this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aspect ratio shows up in the MKVinfo report next to the assigned value. I used sed to take it out and just get the value but now I'm thinking that if there was any other value assigned to the display unit it might the definition too, so i have changed that line to:

SELECTED_ELEMENT_VALUE=$(echo "${MKVINFO_PROP}" | grep -i "+ ${ELEMENT}: " | cut -d: -f 2 | cut -d" " -f 2) 

standardguess Outdated
echo
echo "Height"
_MKV_Prop_Check "${INPUT}" "Display height" "3"
_MKV_HEIGHT "${INPUT}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These prior two lines seem to do the same thing.

standardguess Outdated
}
_MKV_PRIMARIES(){
MKVPRIMARIES=$(_MKV_Prop_Check "${1}" "Colour primaries" "6")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these above functions needed, from _MKV_Interlaced through _MKV_PRIMARIES? It seems that when they are used below the _MKV_Prop_Check version is also used, so many tests happen twice.

standardguess Outdated
fi
}
_usage(){
echo "This application checks if a matroska video is consistent with a set of standards properties and if so, it will assign expected values to other properties that are either undefined or differ from expectations. The properties that will be changed to their expected values are as follows:"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC this would only apply these properties if the input is NTSC. If so then the usage should clarify this.

standardguess Outdated
continue
fi


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lots of multiple consecutive line breaks in this doc can be removed.

standardguess Outdated
#EXPECTATION is expected value of property
#MKVINFO_PROP generates mkvINFO report
#SELECTED_ELEMENT checks to see if property is present in the mkvINFO report
#SELECTED_ELEMENT_VALUE checks the value of the value of the property
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep indentation consistent

standardguess Outdated
fi
else
echo "${ELEMENT} already set to expected value of ${EXPECTATION}"
fi
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above section seems to be re-used within the context of several different properties. It make reduce line count and make this easier to maintain if this section was adjusted to be a generic function which could be re-used within each context.

standardguess Outdated
echo "${ELEMENT} already set to expected value of ${EXPECTATION}"
fi
done
exit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An exit as a last line is not needed.

In addition to a minor additions the following changes were made:
-Dependencies added and checked
-Redundant functions and variables were eliminated
-Usage clarifies that this is application if for NTSC inputs
-_ASSESSMENT function added
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants