Skip to content

Commit ca2139e

Browse files
committed
[HEVC-14] Updated all path references to use os.path constructs
1 parent 940e677 commit ca2139e

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

compareEncoding.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import sys
99

1010
parser = argparse.ArgumentParser()
11-
parser.add_argument("filename", help="Source filename (or \"all\" to compare all files which exist in both source/ and hevc/)")
11+
parser.add_argument("filename", help="Source filename (or \"all\" to compare all files which exist in both ./source/ and ./hevc/)")
1212
parser.add_argument("num_frames", nargs="?", default=5, type=int, help="Number of comparison frames to generate")
1313
parser.add_argument("-s", "--stack", action="store_true", help="Also create 2-up stacked comparison")
1414
args = parser.parse_args()
@@ -26,19 +26,19 @@
2626
print("\nComparison frames:\t{frames}".format(frames=args.num_frames))
2727

2828
for source_file in source_files:
29-
source_file_path = os.path.relpath("source/{filename}".format(filename=source_file))
30-
source_file_size = int(os.path.getsize(source_file_path) / 1000000)
29+
source_file_path = os.path.joinpath("source", source_file)
30+
source_file_size = int(os.path.getsize(source_file_path)/1000000)
3131
source_file_handle = cv2.VideoCapture(source_file_path)
3232
hevc_files = [filename for filename in os.listdir("hevc") if filename.startswith(os.path.splitext(source_file)[0])]
3333

3434
for hevc_file in hevc_files:
3535
output_directory = os.path.join(os.path.relpath("comparison"), os.path.splitext(os.path.basename(hevc_file))[0])
36-
hevc_file_path = os.path.relpath("hevc/{filename}".format(filename=hevc_file))
36+
hevc_file_path = os.path.joinpath("hevc", hevc_file)
3737
hevc_file_handle = cv2.VideoCapture(hevc_file_path)
38-
hevc_file_size = int(os.path.getsize(hevc_file_path) / 1000000)
38+
hevc_file_size = int(os.path.getsize(hevc_file_path)/1000000)
3939
compression_ratio = int(100-(hevc_file_size/source_file_size*100))
4040
total_frames = source_file_handle.get(cv2.CAP_PROP_FRAME_COUNT)
41-
stride = int(total_frames / (args.num_frames + 1))
41+
stride = int(total_frames/(args.num_frames+1))
4242

4343
print("\nFilename:\t\t{filename}".format(filename=hevc_file))
4444
if source_file_handle.get(cv2.CAP_PROP_FRAME_COUNT) != hevc_file_handle.get(cv2.CAP_PROP_FRAME_COUNT):

src/TranscodeSession.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self, file, args):
3636
metadata = json.loads(metadata)["streams"][0]
3737

3838
# Populate metadata-based attributes
39-
self.path = {"source": file}
39+
self.path = {"source": os.path.relpath(file)}
4040
self.source = {"height": int(metadata["height"]), "width": int(metadata["width"]), "duration": float(metadata["duration"]), "filename": os.path.splitext(os.path.relpath(self.path["source"], "source"))[0], "filesize": os.path.getsize(self.path["source"]), "bitrate": int(metadata["bit_rate"]), "frames": int(metadata["nb_frames"]), "codec": metadata["codec_name"]}
4141
height = self.source["height"]
4242
if height < 720:
@@ -60,14 +60,14 @@ def __init__(self, file, args):
6060
self.map_options()
6161

6262
self.output["filename"] = self.source["filename"] + self.output["file_decorator"]
63-
self.path["output"] = "hevc/" + self.output["filename"] + ".mp4"
64-
self.path["log"] = "performance/" + self.output["filename"] + ".log"
63+
self.path["output"] = os.path.join("hevc", self.output["filename"] + ".mp4")
64+
self.path["log"] = os.path.join("performance", self.output["filename"] + ".log")
6565

6666
# Verify no attributes are None
6767
self.validate()
6868

6969
# Build HandBrakeCLI command
70-
self.command = "HandBrakeCLI --encoder-preset {encoder_preset} --preset-import-file {json_path} --preset {preset_name} --quality {quality} --encopts {encopts} --input {source_path} --output {output_path}".format(encoder_preset=self.encoder_preset, json_path=os.path.join(sys.path[0], "src/presets.json"), preset_name=self.preset_name, quality=str(self.encoder_quality), encopts=self.encoder_options, source_path=self.path["source"], output_path=self.path["output"])
70+
self.command = "HandBrakeCLI --encoder-preset {encoder_preset} --preset-import-file {json_path} --preset {preset_name} --quality {quality} --encopts {encopts} --input {source_path} --output {output_path}".format(encoder_preset=self.encoder_preset, json_path=os.path.join(sys.path[0], "src", "presets.json"), preset_name=self.preset_name, quality=str(self.encoder_quality), encopts=self.encoder_options, source_path=self.path["source"], output_path=self.path["output"])
7171

7272
def signal_handler(self, sig, frame):
7373
""" Delete output file if ctrl+c is caught, since file will be corrupt

transcode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def link():
104104
print("Use default location? /usr/local/bin")
105105
default_location = get_user_response()
106106
if default_location:
107-
os.symlink(script_realpath, os.path.join("/usr/local/bin", script_name))
107+
os.symlink(script_realpath, os.path.join("usr", "local", "bin", script_name))
108108
sys.exit("Created symlink to {script_name} in /usr/local/bin\n")
109109
else:
110110
print("Use alternate $PATH location?")
@@ -168,7 +168,7 @@ def build_source_list(args):
168168
print("\nBuilding source list...")
169169

170170
if args.all:
171-
source_files = ["source/" + file for file in os.listdir("source") if os.path.splitext(file)[1].lower() in extensions]
171+
source_files = [os.path.join("source", file) for file in os.listdir("source") if os.path.splitext(file)[1].lower() in extensions]
172172
else:
173173
if os.path.splitext(args.file)[1].lower() in extensions:
174174
source_files = [args.file]

0 commit comments

Comments
 (0)