From c56d33cb01a74c7670fb9d1cde4c2c558f6f472a Mon Sep 17 00:00:00 2001 From: SophiaFrancis1 <112432333+SophiaFrancis1@users.noreply.github.com> Date: Fri, 21 Feb 2025 11:40:08 -0600 Subject: [PATCH 1/8] testchange --- nulrdcscripts/tools/ffplaywindow/main.py | 38 +++++++++++++++--------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/nulrdcscripts/tools/ffplaywindow/main.py b/nulrdcscripts/tools/ffplaywindow/main.py index 126efb9..97633b1 100644 --- a/nulrdcscripts/tools/ffplaywindow/main.py +++ b/nulrdcscripts/tools/ffplaywindow/main.py @@ -1,21 +1,11 @@ import os import subprocess +import tempfile from nulrdcscripts.tools.ffplaywindow.scriptparser import args -def main(): - input_path = os.path.normpath(args.input_path) - ffplay_path = os.path.normpath(args.ffplay_path) - ostype = os.name - fontfile_windows = "/Windows/Fonts/arial.ttf" - fontfile_mac = "" - - if ostype == "nt": - font = fontfile_windows - else: - font = fontfile_mac - - ffplay_filter = ( +def declareFfplayfilter(font): + return ( "-vf split=5[a][b][c][d][e];[a]copy,drawtext=text='%{pts\:hms}':box=1:boxborderw=5:x=(w-text_w)/2:y=h-(text_h*2):fontsize=20:fontfile=" + font + "[a1];[b]field=top,format=yuv422p,waveform=scale=digital:intensity=0.1:mode=column:mirror=1:c=1:f=lowpass:e=instant:graticule=green:flags=numbers+dots[b1];[c]field=bottom,format=yuv422p,waveform=scale=digital:intensity=0.1:mode=column:mirror=1:c=1:f=lowpass:e=instant:graticule=green:flags=numbers+dots[c1];[d]format=yuv422p,vectorscope=i=0.04:mode=color2:c=1:envelope=instant:graticule=green:flags=name,scale=512:512,drawbox=w=9:h=9:t=1:x=128-3:y=512-452-5:c=sienna@0.8,drawbox=w=9:h=9:t=1:x=160-3:y=512-404-5:c=sienna@0.8,drawbox=w=9:h=9:t=1:x=192-3:y=512-354-5:c=sienna@0.8,drawbox=w=9:h=9:t=1:x=224-3:y=512-304-5:c=sienna@0.8,drawgrid=w=32:h=32:t=1:c=white@0.1,drawgrid=w=256:h=256:t=1:c=white@0.2[d1];[e]scale=512:ih,signalstats='out=brng:color=" @@ -23,7 +13,27 @@ def main(): + "'" + "[e1];[a1][b1][c1][e1][d1]xstack=inputs=5:layout='0_0|0_h0|0_h0+h1|w0_0|w0_h0' -af channelmap='0|1:stereo'" ) - command = ffplay_path + " " + "-i" + " " + input_path + " " + ffplay_filter + + +def main(): + input_path = os.path.normpath(args.input_path) + ffplay_path = os.path.normpath(args.ffplay_path) + ostype = os.name + + if ostype == "nt": + font = "/Windows/Fonts/arial.ttf" + ffplayfilter = declareFfplayfilter(font) + command = ffplay_path + " " + "-i" + " " + input_path + " " + ffplayfilter + subprocess.run(command) + else: + font = "" + ffplayfilter = declareFfplayfilter(font) + command = ffplay_path + " " + "-i" + " " + input_path + " " + ffplayfilter + with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp_file: + temp_file.write(command) + temp_file_path = temp_file.name + command = ["command_name", "--input-file", temp_file_path] + subprocess.run(command, capture_output=True, text=True) # This command (above) is from VRecord's Visual filter. We do not own/nor did we come up with this. From 8761e204c54e70a63afc18893772354e2584650b Mon Sep 17 00:00:00 2001 From: SophiaFrancis1 <112432333+SophiaFrancis1@users.noreply.github.com> Date: Fri, 21 Feb 2025 14:13:06 -0600 Subject: [PATCH 2/8] trythis --- nulrdcscripts/tools/ffplaywindow/main.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nulrdcscripts/tools/ffplaywindow/main.py b/nulrdcscripts/tools/ffplaywindow/main.py index 97633b1..a7dd742 100644 --- a/nulrdcscripts/tools/ffplaywindow/main.py +++ b/nulrdcscripts/tools/ffplaywindow/main.py @@ -6,7 +6,7 @@ def declareFfplayfilter(font): return ( - "-vf split=5[a][b][c][d][e];[a]copy,drawtext=text='%{pts\:hms}':box=1:boxborderw=5:x=(w-text_w)/2:y=h-(text_h*2):fontsize=20:fontfile=" + "-vf split=5[a][b][c][d][e];[a]copy,drawtext=text='%{pts\\:hms}':box=1:boxborderw=5:x=(w-text_w)/2:y=h-(text_h*2):fontsize=20:fontfile=" + font + "[a1];[b]field=top,format=yuv422p,waveform=scale=digital:intensity=0.1:mode=column:mirror=1:c=1:f=lowpass:e=instant:graticule=green:flags=numbers+dots[b1];[c]field=bottom,format=yuv422p,waveform=scale=digital:intensity=0.1:mode=column:mirror=1:c=1:f=lowpass:e=instant:graticule=green:flags=numbers+dots[c1];[d]format=yuv422p,vectorscope=i=0.04:mode=color2:c=1:envelope=instant:graticule=green:flags=name,scale=512:512,drawbox=w=9:h=9:t=1:x=128-3:y=512-452-5:c=sienna@0.8,drawbox=w=9:h=9:t=1:x=160-3:y=512-404-5:c=sienna@0.8,drawbox=w=9:h=9:t=1:x=192-3:y=512-354-5:c=sienna@0.8,drawbox=w=9:h=9:t=1:x=224-3:y=512-304-5:c=sienna@0.8,drawgrid=w=32:h=32:t=1:c=white@0.1,drawgrid=w=256:h=256:t=1:c=white@0.2[d1];[e]scale=512:ih,signalstats='out=brng:color=" + args.highlight_color @@ -26,21 +26,22 @@ def main(): command = ffplay_path + " " + "-i" + " " + input_path + " " + ffplayfilter subprocess.run(command) else: - font = "" + font = "/Library/Fonts/Arial.ttf" # Specify a valid font path for macOS ffplayfilter = declareFfplayfilter(font) command = ffplay_path + " " + "-i" + " " + input_path + " " + ffplayfilter with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp_file: temp_file.write(command) temp_file_path = temp_file.name - command = ["command_name", "--input-file", temp_file_path] + command = [ + ffplay_path, + "--input-file", + temp_file_path, + ] # Ensure ffplay is the command subprocess.run(command, capture_output=True, text=True) - # This command (above) is from VRecord's Visual filter. We do not own/nor did we come up with this. - print( "To exit the playback window, while in window use the 'esc' key. To fast-forward or rewind, use the respective arrow keys." ) - subprocess.run(command) if __name__ == "__main__": From 57b37a50ba8316e93b31f69c10539469b8d4fed5 Mon Sep 17 00:00:00 2001 From: SophiaFrancis1 <112432333+SophiaFrancis1@users.noreply.github.com> Date: Fri, 21 Feb 2025 14:16:16 -0600 Subject: [PATCH 3/8] tryagain --- nulrdcscripts/tools/ffplaywindow/main.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/nulrdcscripts/tools/ffplaywindow/main.py b/nulrdcscripts/tools/ffplaywindow/main.py index a7dd742..3fab604 100644 --- a/nulrdcscripts/tools/ffplaywindow/main.py +++ b/nulrdcscripts/tools/ffplaywindow/main.py @@ -22,22 +22,19 @@ def main(): if ostype == "nt": font = "/Windows/Fonts/arial.ttf" - ffplayfilter = declareFfplayfilter(font) - command = ffplay_path + " " + "-i" + " " + input_path + " " + ffplayfilter - subprocess.run(command) else: font = "/Library/Fonts/Arial.ttf" # Specify a valid font path for macOS - ffplayfilter = declareFfplayfilter(font) - command = ffplay_path + " " + "-i" + " " + input_path + " " + ffplayfilter + + ffplayfilter = declareFfplayfilter(font) + command = ffplay_path + " " + "-i" + " " + input_path + " " + ffplayfilter + + try: with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp_file: temp_file.write(command) temp_file_path = temp_file.name - command = [ - ffplay_path, - "--input-file", - temp_file_path, - ] # Ensure ffplay is the command - subprocess.run(command, capture_output=True, text=True) + subprocess.run(["sh", temp_file_path], capture_output=True, text=True) + except Exception as e: + print(f"An error occurred: {e}") print( "To exit the playback window, while in window use the 'esc' key. To fast-forward or rewind, use the respective arrow keys." From e77b9af66e41af84f03c4a22b8339d5a79ff0a6d Mon Sep 17 00:00:00 2001 From: SophiaFrancis1 <112432333+SophiaFrancis1@users.noreply.github.com> Date: Fri, 21 Feb 2025 14:30:59 -0600 Subject: [PATCH 4/8] tryagain --- nulrdcscripts/tools/ffplaywindow/main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nulrdcscripts/tools/ffplaywindow/main.py b/nulrdcscripts/tools/ffplaywindow/main.py index 3fab604..810082f 100644 --- a/nulrdcscripts/tools/ffplaywindow/main.py +++ b/nulrdcscripts/tools/ffplaywindow/main.py @@ -30,9 +30,13 @@ def main(): try: with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp_file: - temp_file.write(command) + temp_file.write("#!/bin/sh\n" + command) temp_file_path = temp_file.name - subprocess.run(["sh", temp_file_path], capture_output=True, text=True) + os.chmod(temp_file_path, 0o755) # Make the temp file executable + print(f"Executing command from temp file: {temp_file_path}") + result = subprocess.run([temp_file_path], capture_output=True, text=True) + print("Command output:", result.stdout) + print("Command error:", result.stderr) except Exception as e: print(f"An error occurred: {e}") From 618e33dee2b0761ba7ba4b3b0db862461174e7b9 Mon Sep 17 00:00:00 2001 From: SophiaFrancis1 <112432333+SophiaFrancis1@users.noreply.github.com> Date: Mon, 24 Feb 2025 10:21:04 -0600 Subject: [PATCH 5/8] trythis --- nulrdcscripts/tools/ffplaywindow/main.py | 34 +++++++++++++----------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/nulrdcscripts/tools/ffplaywindow/main.py b/nulrdcscripts/tools/ffplaywindow/main.py index 810082f..3f98f45 100644 --- a/nulrdcscripts/tools/ffplaywindow/main.py +++ b/nulrdcscripts/tools/ffplaywindow/main.py @@ -22,23 +22,27 @@ def main(): if ostype == "nt": font = "/Windows/Fonts/arial.ttf" - else: - font = "/Library/Fonts/Arial.ttf" # Specify a valid font path for macOS - - ffplayfilter = declareFfplayfilter(font) - command = ffplay_path + " " + "-i" + " " + input_path + " " + ffplayfilter - - try: - with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp_file: - temp_file.write("#!/bin/sh\n" + command) - temp_file_path = temp_file.name - os.chmod(temp_file_path, 0o755) # Make the temp file executable - print(f"Executing command from temp file: {temp_file_path}") - result = subprocess.run([temp_file_path], capture_output=True, text=True) + ffplayfilter = declareFfplayfilter(font) + command = ffplay_path + " " + "-i" + " " + input_path + " " + ffplayfilter + result = subprocess.run(command) print("Command output:", result.stdout) print("Command error:", result.stderr) - except Exception as e: - print(f"An error occurred: {e}") + else: + font = "/Library/Fonts/Arial.ttf" # Specify a valid font path for macOS + ffplayfilter = declareFfplayfilter(font) + command = ffplay_path + " " + "-i" + " " + input_path + " " + ffplayfilter + + try: + with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp_file: + temp_file.write("#!/bin/sh\n" + command) + temp_file_path = temp_file.name + os.chmod(temp_file_path, 0o755) # Make the temp file executable + print(f"Executing command from temp file: {temp_file_path}") + result = subprocess.run([temp_file_path], capture_output=True, text=True) + print("Command output:", result.stdout) + print("Command error:", result.stderr) + except Exception as e: + print(f"An error occurred: {e}") print( "To exit the playback window, while in window use the 'esc' key. To fast-forward or rewind, use the respective arrow keys." From 4ec46a9906691fbf660919cd8bf8da0bde667973 Mon Sep 17 00:00:00 2001 From: SophiaFrancis1 <112432333+SophiaFrancis1@users.noreply.github.com> Date: Mon, 24 Feb 2025 10:26:48 -0600 Subject: [PATCH 6/8] Works --- nulrdcscripts/tools/ffplaywindow/main.py | 36 +++++++++++++----------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/nulrdcscripts/tools/ffplaywindow/main.py b/nulrdcscripts/tools/ffplaywindow/main.py index 3f98f45..5d3ce02 100644 --- a/nulrdcscripts/tools/ffplaywindow/main.py +++ b/nulrdcscripts/tools/ffplaywindow/main.py @@ -1,6 +1,5 @@ import os import subprocess -import tempfile from nulrdcscripts.tools.ffplaywindow.scriptparser import args @@ -24,25 +23,28 @@ def main(): font = "/Windows/Fonts/arial.ttf" ffplayfilter = declareFfplayfilter(font) command = ffplay_path + " " + "-i" + " " + input_path + " " + ffplayfilter - result = subprocess.run(command) - print("Command output:", result.stdout) - print("Command error:", result.stderr) else: font = "/Library/Fonts/Arial.ttf" # Specify a valid font path for macOS ffplayfilter = declareFfplayfilter(font) - command = ffplay_path + " " + "-i" + " " + input_path + " " + ffplayfilter - - try: - with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp_file: - temp_file.write("#!/bin/sh\n" + command) - temp_file_path = temp_file.name - os.chmod(temp_file_path, 0o755) # Make the temp file executable - print(f"Executing command from temp file: {temp_file_path}") - result = subprocess.run([temp_file_path], capture_output=True, text=True) - print("Command output:", result.stdout) - print("Command error:", result.stderr) - except Exception as e: - print(f"An error occurred: {e}") + command = [ + 'ffplay', input_path, + '-vf', ( + 'split=5[a][b][c][d][e];' + '[a]copy,drawtext=text=\'%{pts\\:hms}\':box=1:boxborderw=5:x=(w-text_w)/2:y=h-(text_h*2):fontsize=20:fontfile=font[a1];' + '[b]field=top,format=yuv422p,waveform=scale=digital:intensity=0.1:mode=column:mirror=1:c=1:f=lowpass:e=instant:graticule=green:flags=numbers+dots[b1];' + '[c]field=bottom,format=yuv422p,waveform=scale=digital:intensity=0.1:mode=column:mirror=1:c=1:f=lowpass:e=instant:graticule=green:flags=numbers+dots[c1];' + '[d]format=yuv422p,vectorscope=i=0.04:mode=color2:c=1:envelope=instant:graticule=green:flags=name,scale=512:512,' + 'drawbox=w=9:h=9:t=1:x=128-3:y=512-452-5:c=sienna@0.8,drawbox=w=9:h=9:t=1:x=160-3:y=512-404-5:c=sienna@0.8,' + 'drawbox=w=9:h=9:t=1:x=192-3:y=512-354-5:c=sienna@0.8,drawbox=w=9:h=9:t=1:x=224-3:y=512-304-5:c=sienna@0.8,' + 'drawgrid=w=32:h=32:t=1:c=white@0.1,drawgrid=w=256:h=256:t=1:c=white@0.2[d1];' + '[e]scale=512:ih,signalstats=out=brng:color=red[e1];' + '[a1][b1][c1][e1][d1]xstack=inputs=5:layout=0_0|0_h0|0_h0+h1|w0_0|w0_h0' + ), + '-af', 'channelmap=0|1:stereo' +] + +# Run the ffplay command + subprocess.run(command) print( "To exit the playback window, while in window use the 'esc' key. To fast-forward or rewind, use the respective arrow keys." From 9c3553779d29450f12c3ec4315eef44f9bb65d5f Mon Sep 17 00:00:00 2001 From: SophiaFrancis1 <112432333+SophiaFrancis1@users.noreply.github.com> Date: Mon, 24 Feb 2025 10:28:41 -0600 Subject: [PATCH 7/8] Increasedpoetry --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b24dfcc..aceb3c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nul-rdc-scripts" -version = "0.5.1" +version = "0.5.2" description = "Scripts for NUL RDC Digitization Team" authors = [ "Northwestern University Libraries ", From ddced060d3eb92cefaaa89ffb710891eae01419f Mon Sep 17 00:00:00 2001 From: SophiaFrancis1 <112432333+SophiaFrancis1@users.noreply.github.com> Date: Mon, 24 Feb 2025 10:29:33 -0600 Subject: [PATCH 8/8] Updated README --- nulrdcscripts/tools/ffplaywindow/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nulrdcscripts/tools/ffplaywindow/README.md b/nulrdcscripts/tools/ffplaywindow/README.md index 5a33367..4272a26 100644 --- a/nulrdcscripts/tools/ffplaywindow/README.md +++ b/nulrdcscripts/tools/ffplaywindow/README.md @@ -18,7 +18,7 @@ To run the script. From nul-rdc-scripts ``` poetry run ffplaywindow -i \path\to\input ``` -To change the highlight color for the BRNG filter. Use -hi or --highlight followed by color name or hexcode. +To change the highlight color for the BRNG filter. Use -hi or --highlight followed by color name or hexcode. -- This only works on Windows for now. In order to change you will need to edit the code ``` poetry run ffplaywindow -i \path\to\input -hi 'color name or hexcode' ```