139 lines
4.0 KiB
Python
139 lines
4.0 KiB
Python
import argparse
|
|
|
|
from tsmark.video_annotator import Marker
|
|
|
|
VERSION = "0.7.8"
|
|
|
|
|
|
class SmartFormatter(argparse.HelpFormatter):
|
|
"""Thanks to https://stackoverflow.com/users/1307905/anthon"""
|
|
|
|
def _split_lines(self, text, width):
|
|
if text.startswith("R|"):
|
|
return text[2:].splitlines()
|
|
return argparse.HelpFormatter._split_lines(self, text, width)
|
|
|
|
|
|
def get_options():
|
|
|
|
parser = argparse.ArgumentParser(description="Video timestamping tool", formatter_class=SmartFormatter)
|
|
parser.add_argument(
|
|
"--ts",
|
|
action="store",
|
|
dest="timestamps",
|
|
default=None,
|
|
required=False,
|
|
help="Comma separated list of predefined timestamps, in seconds, or HH:MM:SS.ss, or input CSV file. You can use the -o output file as input via --ts $( cut -d, -f1 ts.csv | xargs printf '%%s,' )",
|
|
)
|
|
parser.add_argument(
|
|
"-o",
|
|
action="store",
|
|
dest="output",
|
|
default=None,
|
|
required=False,
|
|
help="Save timestamps to a CSV file",
|
|
)
|
|
parser.add_argument(
|
|
"--op",
|
|
action="store",
|
|
dest="output_points",
|
|
default=None,
|
|
required=False,
|
|
help="Save points to a JSON file",
|
|
)
|
|
parser.add_argument(
|
|
"--ip",
|
|
action="store",
|
|
dest="input_points",
|
|
default=None,
|
|
required=False,
|
|
help="Load points from a JSON file",
|
|
)
|
|
parser.add_argument(
|
|
"--max-track",
|
|
action="store",
|
|
dest="max_track",
|
|
type=float,
|
|
default=4,
|
|
required=False,
|
|
help="Length of tracking segment in seconds: %(default)s",
|
|
)
|
|
parser.add_argument(
|
|
"--fps",
|
|
action="store",
|
|
dest="fps",
|
|
default=None,
|
|
required=False,
|
|
type=float,
|
|
help="Force FPS to play video",
|
|
)
|
|
parser.add_argument(
|
|
"--crop",
|
|
action="store",
|
|
dest="crop",
|
|
default=None,
|
|
required=False,
|
|
type=str,
|
|
help="predefined crop. Syntax: 'w:h:x:y' example: 1280:720:30:20",
|
|
)
|
|
parser.add_argument(
|
|
"--ss",
|
|
action="store",
|
|
dest="start_time",
|
|
default=None,
|
|
required=False,
|
|
type=str,
|
|
help="Starting position as frame (int) or HH:MM:SS.ss",
|
|
)
|
|
parser.add_argument(
|
|
"--max-res",
|
|
action="store",
|
|
dest="max_res",
|
|
default="1280x720",
|
|
type=str,
|
|
help="Max resolution of video viewer: %(default)s",
|
|
)
|
|
parser.add_argument(
|
|
"--ffmpeg-copy",
|
|
action="store_true",
|
|
default=False,
|
|
required=False,
|
|
help="Print FFMPEG commands: Copy instead of recompress. If video is cropped, it must be recompressed",
|
|
)
|
|
parser.add_argument(
|
|
"--ffmpeg-args",
|
|
action="store",
|
|
default="-i {input} {crop} -c:v mpeg2video -q:v 3 -g 1 -c:a libmp3lame -ar 44100 -b:a 192k -ss {start_time} -to {end_time} {output}.mpeg",
|
|
required=False,
|
|
help="""R|FFMPEG arguments.
|
|
Default: '%(default)s'
|
|
Note: {output} is without extension. -i and -ss should switch, depending on input and output formats.
|
|
Other useful arguments:
|
|
'-i {input} -c:v copy -an -ss {start_time} -to {end_time} {output}.mpeg'
|
|
'-ss {start_time} -to {end_time} -i {input} {crop} -g 250 -c:v libx264 -crf 23 -c:a aac -movflags faststart -strict -2 -y {output}.mp4'
|
|
""",
|
|
)
|
|
parser.add_argument(
|
|
"--ffmpeg-run",
|
|
action="store_true",
|
|
default=False,
|
|
required=False,
|
|
help="Run FFMPEG commands instead of just printing them",
|
|
)
|
|
parser.add_argument(
|
|
"--plugin",
|
|
action="store",
|
|
dest="plugin",
|
|
default=None,
|
|
type=str,
|
|
help="Name of plugin class to use, ex. myplugin:ClassName. Plugins loaded from ~/.config/tsmark/plugins/ (try hello:World)",
|
|
)
|
|
parser.add_argument("--version", action="version", version=VERSION)
|
|
parser.add_argument(action="store", dest="video")
|
|
return parser.parse_args()
|
|
|
|
|
|
def main():
|
|
opts = get_options()
|
|
Marker(opts)
|