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

IO checks, HiFi-UI and dependencies improvements #128

Merged
merged 186 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
b4b72a3
Merge of vhs_decode branch
VideoMem Mar 23, 2021
0756c7c
typo glitch fix
VideoMem Mar 23, 2021
a9d9471
DC restore intro
VideoMem Mar 26, 2021
ca2e427
DC restore, before sync restore
VideoMem Mar 26, 2021
25086fc
DC restore improved metrics
VideoMem Mar 26, 2021
f37d4b0
DC restore improved metrics, pre merge check
VideoMem Mar 27, 2021
6fab92b
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Mar 27, 2021
2498807
Added chroma trap option to cvbs-decode
VideoMem Mar 27, 2021
6e94ede
Auto-sync level, first try
VideoMem Mar 29, 2021
13c7a2c
Auto-sync level, added to cvbs + wavesink
VideoMem Mar 30, 2021
13dc289
Auto-sync level (block level, not working) , added to cvbs + wavesink
VideoMem Mar 31, 2021
997edff
Auto-sync level (block level, not working) , added to cvbs + wavesink
VideoMem Mar 31, 2021
3c51017
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem Mar 31, 2021
e5c8e63
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem Mar 31, 2021
a692707
Some dead code removal
VideoMem Mar 31, 2021
b571a05
Previous merge commit
VideoMem Apr 9, 2021
79d8c3e
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Apr 9, 2021
20444ee
Merge of oyvindln/vhs_decode changes
VideoMem Apr 9, 2021
41cb814
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Apr 15, 2021
b0e0248
Resync
VideoMem Apr 17, 2021
90a9afb
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem Apr 17, 2021
12fa31f
Moved experimental sync separator code to resync branch
VideoMem Apr 17, 2021
7f68321
Merge remote-tracking branch 'upstream/vhs_decode' into resync
VideoMem Apr 17, 2021
9532e76
Merge branch 'vhs_decode' into resync
VideoMem Apr 17, 2021
0c293c9
Restored deleted files
VideoMem Apr 17, 2021
22de0b8
Comment typo fix
VideoMem Apr 17, 2021
713b963
Comment typo fix
VideoMem Apr 17, 2021
6268034
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem Apr 22, 2021
1439865
Merge branch 'vhs_decode' into resync
VideoMem Apr 22, 2021
b186a26
getpulses_override() keep the last valid blacklevel, synclevel, and v…
VideoMem Apr 23, 2021
9bc0bbb
getpulses_override() keep the last valid blacklevel, synclevel, and v…
VideoMem Apr 23, 2021
ef117c6
Added -palm -pm command line switches and RFParams_MPAL_VHS on format…
VideoMem Apr 25, 2021
ab39624
cvbs-decode / vhs-decode common options deduplication + preliminary P…
VideoMem Apr 25, 2021
921350a
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Apr 25, 2021
9735931
cvbs-decode / vhs-decode common options deduplication + preliminary P…
VideoMem Apr 25, 2021
728767b
Merge branch 'vhs_decode' into resync
VideoMem Apr 26, 2021
d221cf2
VBI serration detection test
VideoMem Apr 26, 2021
5d1ea4e
Merge of vhs_decode branch
VideoMem Mar 23, 2021
dcd838f
typo glitch fix
VideoMem Mar 23, 2021
fc23fd0
Added chroma trap option to cvbs-decode
VideoMem Mar 27, 2021
a497a0f
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem Mar 31, 2021
d1075a4
Some dead code removal
VideoMem Mar 31, 2021
f548509
Merge of oyvindln/vhs_decode changes
VideoMem Apr 9, 2021
ba7972e
Comment typo fix
VideoMem Apr 17, 2021
ca2398a
Comment typo fix
VideoMem Apr 17, 2021
ed0fe1b
getpulses_override() keep the last valid blacklevel, synclevel, and v…
VideoMem Apr 23, 2021
485fd29
getpulses_override() keep the last valid blacklevel, synclevel, and v…
VideoMem Apr 23, 2021
34415e6
Added -palm -pm command line switches and RFParams_MPAL_VHS on format…
VideoMem Apr 25, 2021
d69238d
cvbs-decode / vhs-decode common options deduplication + preliminary P…
VideoMem Apr 25, 2021
81e64a3
cvbs-decode / vhs-decode common options deduplication + preliminary P…
VideoMem Apr 25, 2021
55bc94a
Merge remote-tracking branch 'origin/vhs_decode' into vhs_decode
VideoMem Apr 26, 2021
619d02d
Changes cleanup (vhs-decode/cvbs-decode command line deduplication + …
VideoMem Apr 26, 2021
7d53e05
vsync_levels pre-cleanup
VideoMem Apr 26, 2021
23480a2
VBI vsync autolevels testing
VideoMem Apr 27, 2021
7b0e9c6
Temporarly disabled extra-diff code to force zero crossings, it can b…
VideoMem Apr 28, 2021
6d7e625
Added demodblock() envelope (env) zeroes check, to avoid potential di…
VideoMem Apr 28, 2021
f758599
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Apr 29, 2021
5bdcf3d
- Changed the replace_spikes function as shown before.
VideoMem Apr 29, 2021
14f6375
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Apr 29, 2021
eea6548
- Changed the replace_spikes function to use np.where instead np.argw…
VideoMem Apr 29, 2021
33a2887
- Changed the replace_spikes function to use np.where instead np.argw…
VideoMem Apr 29, 2021
69805a9
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Apr 29, 2021
8596303
- Changed the replace_spikes function to use np.where instead np.argw…
VideoMem Apr 29, 2021
3dbb7ce
Bad signal / 'Chewed tape' sample (preliminary fix) (#24)
VideoMem Apr 25, 2021
c0df694
getpulses_override() keep the last valid blacklevel, synclevel, and v…
VideoMem Mar 23, 2021
194ff0c
Merge remote-tracking branch 'origin/vhs_decode' into vhs_decode
VideoMem Apr 30, 2021
cc5acb0
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 1, 2021
a9cf66c
fixup!
VideoMem May 2, 2021
e404463
Changed min valid levels to report valid serration levels
VideoMem May 2, 2021
93b5a48
Merge branch 'vhs_decode' into resync
VideoMem May 2, 2021
5d96161
chroma loss sample fails
VideoMem May 2, 2021
004c3d7
RuntimeWarning: Div by zero prevented at lddecode/utils.calczc_do()
VideoMem May 3, 2021
77cb1f6
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 3, 2021
f2b16a4
RuntimeWarning: Div by zero prevented at lddecode/utils.calczc_do()
VideoMem May 3, 2021
f3e4df6
Regenerates the sync pulses amplitude
VideoMem May 3, 2021
fdfb2be
Seems to sort a lot of edge cases, saving this
VideoMem May 3, 2021
14f38a9
Merge remote-tracking branch 'origin/resync' into resync
VideoMem May 3, 2021
f6a2861
Added resync branch getpulses_override() logic
VideoMem May 4, 2021
c7814be
Safe clips the bottom of the sync pulses but leaves picture area unch…
VideoMem May 5, 2021
c44e499
Nosync sample decodes
VideoMem May 5, 2021
8e92eea
Serration levels detection adjustments (produces new frames on chewed…
VideoMem May 5, 2021
a6ecc6a
Suggested oyvindln changes over replace_spikes() on diff_demod
VideoMem May 6, 2021
244c35b
Added ldd.core logger, changed the name of the Vsync class to VsyncSe…
VideoMem May 6, 2021
9350ce0
Disabled serration detection in cvbs-decode
VideoMem May 6, 2021
1b84b1a
Encapsulated all the sync search and the serration search into Resync…
VideoMem May 6, 2021
5297a58
Merged resync branch changes
VideoMem May 6, 2021
79b67aa
Merge remote-tracking branch 'origin/vhs_decode' into vhs_decode
VideoMem May 6, 2021
2b99876
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 6, 2021
41406cf
- Corrected the fallback sync logic when serrations not found.
VideoMem May 7, 2021
890228a
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem May 7, 2021
8c5c116
- added a note on what I mean with fallback sync logic
VideoMem May 7, 2021
c1042e2
- Added more debugging if show_decoded is enabled on VsyncSerration()…
VideoMem May 8, 2021
f330c83
Merging oyvindln/vhs_decode updates
VideoMem May 9, 2021
a028776
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem May 15, 2021
be42d96
Added field hash debug info for SysParams and field.data["video"]["de…
VideoMem May 15, 2021
46bb6e6
Added some checks for SysParams consistency, and found the AGC change…
VideoMem May 15, 2021
89d6884
Refactored the moving average filter for re-utilisation on other code…
VideoMem May 16, 2021
064cdf4
Modified fallback sync/levels logic
VideoMem May 16, 2021
a28eb8f
vsync_envelope_simple() not so tested corrections
VideoMem May 17, 2021
880984e
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 17, 2021
6a539f7
Added experimental changes to vsync_envelope_simple(), merged oyvindl…
VideoMem May 17, 2021
d563067
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 17, 2021
d90eff8
fallback logic getLevels fixes + oyvindln process.py changes
VideoMem May 18, 2021
047c548
Some tape batch tests script intro
VideoMem May 22, 2021
16389d0
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 22, 2021
d1f5702
Tape batch tests improvements
VideoMem May 22, 2021
3030325
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 22, 2021
375f89e
Tape batch tests improvements
VideoMem May 23, 2021
3b02962
Passed the optional debug flag to the resync code.
VideoMem May 25, 2021
a4584c4
Restored vsync_envelope_simple() logic, to fix bicycle sample start p…
VideoMem May 25, 2021
188425e
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 29, 2021
9de0e63
Merged from vhs_decode upstream.
VideoMem May 30, 2021
69847ce
ChromaAFC introduction
VideoMem Jun 1, 2021
e3cb9a9
ChromaAFC enable flag -cafc
VideoMem Jun 1, 2021
73413aa
Improved Chroma AFC
VideoMem Jun 5, 2021
8c9dadf
Chroma AFC, now it does something
VideoMem Jun 5, 2021
c08e241
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Jun 6, 2021
107835a
Merge of upstream and Chroma AFC changes
VideoMem Jun 6, 2021
659075f
Chroma AFC measure smoothing changes
VideoMem Jun 6, 2021
38750cc
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Jun 9, 2021
24c0b29
Serration fixes
VideoMem Jun 9, 2021
e027152
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Jun 12, 2021
0c2d602
Added --sync_clip optional flag
VideoMem Jun 12, 2021
e6ff840
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Jun 12, 2021
6918ff6
Improved -cafc
VideoMem Jun 13, 2021
1108e8a
-cafc (only phase, not freq)
VideoMem Jun 19, 2021
51660c4
-cafc (only phase, not freq), enables in try_detect_track
VideoMem Jun 19, 2021
04b7fd0
If -cafc filters chroma after TBC + chroma related refactor
VideoMem Jun 20, 2021
b186fee
Changes IGNORED_LINES in burst phase detection
VideoMem Jun 21, 2021
7ed62ea
-cafc selects the nearest peak harmonic from the chroma channel as ca…
VideoMem Jun 21, 2021
36c7222
-cafc more interesting results
VideoMem Jun 21, 2021
e46c514
-cafc some corrections
VideoMem Jun 21, 2021
8db1264
-cafc searchs peak carrier
VideoMem Jun 26, 2021
2b4ebe5
-cafc max carried dev adjusted to +- 8%
VideoMem Jun 26, 2021
285617e
-cafc restores nearest center carrier selection logic
VideoMem Jun 26, 2021
ef317e8
-cafc fraction of fh selector
VideoMem Jul 4, 2021
6e1c3bc
serration/AGC moving average window adjustments
VideoMem Jul 4, 2021
3e89603
serration/AGC moving average window adjustments
VideoMem Jul 4, 2021
5b56a80
serration/AGC moving average window adjustments
VideoMem Jul 4, 2021
d7aa342
Chroma AFC changes, serration changes, chroma trap regression.
VideoMem Jul 9, 2021
559c6f1
Sync levels adjustments
VideoMem Jul 10, 2021
19b650f
Sync logic fixes and cleanups
VideoMem Jul 10, 2021
8cb54da
Chewed tape case review
VideoMem Jul 10, 2021
434c345
Infinite loop fix
VideoMem Jul 10, 2021
c1e71fb
Cleanup
VideoMem Jul 11, 2021
aed302f
Readme fixes
VideoMem Jul 11, 2021
e2d7c38
Readme fixes
VideoMem Jul 11, 2021
2501727
IGNORED_LINES parameter reversion
VideoMem Jul 17, 2021
0eb5182
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Jul 17, 2021
ba96dcf
Added -cshift option and updated advanced_flags.md
VideoMem Jul 25, 2021
c5641dd
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Aug 5, 2021
9289362
Reverts some auto-format code, adds pdb-attach to pip3 install in REA…
VideoMem Aug 7, 2021
80f140e
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Aug 22, 2021
478c7af
Merge of upstream +
VideoMem Aug 22, 2021
cab24f0
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Sep 25, 2021
2ec912a
Fix typo on gen_chroma_vid_ntsc.sh
VideoMem Sep 25, 2021
6c16c3f
First attempts at HiFi decoding
VideoMem Oct 17, 2021
e154f3b
HiFi code cleanup
VideoMem Oct 17, 2021
2d8f6ec
Merge branch 'vhs_decode_upstream' into vhs_decode
VideoMem Feb 19, 2023
334319b
Updates to main fork changes
VideoMem Feb 19, 2023
f964151
Adds hifi-decode to main branch
VideoMem Feb 19, 2023
3683a59
Adds hifi-decode to setup.py
VideoMem Feb 20, 2023
e30edab
Fixes unwanted changes on cmdcommons.py
VideoMem Feb 20, 2023
6a6596b
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Dec 31, 2023
9284b80
Adds stdin input using - as input filename.
VideoMem Jan 1, 2024
e29494a
Reconfigures NR sidechain gain to higher value.
VideoMem Jan 3, 2024
b994f6e
Fixes --audio_rate parameter.
VideoMem Jan 14, 2024
945f51a
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem Jan 14, 2024
b67e369
Updates HiFiDecode header text comment
VideoMem Jan 15, 2024
397252c
Overrides file close method for stdin to do nothing.
VideoMem Jan 15, 2024
cff7233
Fixes crackling sound when reading from stdin.
VideoMem Jan 15, 2024
f85d2c4
Merge from oln's branch
VideoMem Jan 15, 2024
10e9897
Adjusts block size for speed improvements.
VideoMem Jan 15, 2024
8e6f445
Fixes bug in --preview parameter
VideoMem Jan 15, 2024
796f5c9
Fixes bug in audio dc bias cancel
VideoMem Jan 15, 2024
6fa4c03
Adds hifi-decode UI
VideoMem Jan 22, 2024
a2f104b
Adds audio modes and ld-ldf-reader for (optional) input file decoding.
VideoMem Jan 24, 2024
b9bb089
Audio sample_rate default is 44100
VideoMem Jan 24, 2024
0e1a386
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Jan 24, 2024
f769632
Removes pyhht dependency from HiFi decode to make it portable to Wind…
VideoMem Jan 26, 2024
0e24e0f
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Feb 4, 2024
692a863
Adds better validation checks for input / output filenames.
VideoMem Feb 4, 2024
0d35196
Fixes AttributeError for os.statvfs on Windows
VideoMem Feb 4, 2024
3fb7399
Fixes a typo
VideoMem Feb 4, 2024
549d553
Tries a fix that prevents file opening on windows
VideoMem Feb 5, 2024
0746cf1
Merge branch 'vhs_decode' into vhs_decode
oyvindln Feb 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions cvbsdecode/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
import lddecode.utils as lddu
from lddecode.utils_logging import init_logging
from cvbsdecode.process import CVBSDecode
import vhsdecode.formats as f
from vhsdecode.cmdcommons import (
common_parser,
select_sample_freq,
select_system,
get_basics,
get_rf_options,
get_extra_options,
IOArgsException,
test_input_file,
test_output_file,
)


Expand Down Expand Up @@ -74,7 +76,16 @@ def main(args=None):
)

args = parser.parse_args(args)
filename, outname, firstframe, req_frames = get_basics(args)
try:
filename, outname, firstframe, req_frames = get_basics(args)
except IOArgsException as e:
parser.print_help()
print(e)
print(f"ERROR: input file '{args.infile}' not found" if not test_input_file(args.infile) else "Input file: OK")
print(f"ERROR: output file '{args.outfile}' is not writable" if not test_output_file(
args.outfile) else "Output file: OK")
sys.exit(1)

system = select_system(args)
sample_freq = select_sample_freq(args)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ classifiers = [
"Topic :: Multimedia :: Video",
]
dependencies = [
"numpy>=1.17","numba>=0.48","scipy>=1.3","samplerate", "static-ffmpeg", "cython", "soundfile", "sounddevice", "importlib_resources >= 5.0; python_version < '3.10'"
"numpy>=1.22","numba>=0.58.1","scipy>=1.10.1","samplerate", "static-ffmpeg", "cython", "soundfile", "sounddevice", "importlib_resources >= 5.0; python_version < '3.10'"
]
dynamic = ["version"]
# version = "0.2.1dev0"
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Cython
matplotlib
numba>=0.55.1
numpy
numba>=0.58.1
numpy>=1.22
samplerate
scipy
scipy>=1.10.1
soundfile
sounddevice
115 changes: 111 additions & 4 deletions vhsdecode/cmdcommons.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import argparse
import os
from typing import Optional

import lddecode.utils as lddu
import sys

Expand All @@ -8,6 +11,88 @@
CXADC_TENBIT_FREQ = (8 * 315.0) / 88.0 / 2.0 # 14.318181818
CXADC_TENBIT_FREQ_HIGH = 3150.0 / 88.0 / 2.0 # 17.897727272

DEFAULT_THREADS = 4
DEFAULT_INPUT_FILENAME = ""
DEFAULT_OUTPUT_FILENAME = ""


# size bytes to human-readable string
def sizeof_fmt(num: int, suffix: str = "B") -> str:
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
if abs(num) < 1024.0:
return f"{num:3.1f} {unit}{suffix}"
num /= 1024.0
return f"{num:.1f} Yi{suffix}"


# checks if the input file can be read
def test_input_file(input_file: Optional[str]) -> bool:
if input_file == '-':
return True

if input_file is DEFAULT_INPUT_FILENAME:
print("WARN: input file not specified")
return False

try:
with open(input_file, "rb") as f:
f.close()
pass
except FileNotFoundError:
print(f"WARN: input file '{input_file}' not found")
return False
return True


# checks if the output file can be written
def test_output_file(output_file: Optional[str]) -> bool:

# checks for free space on the output file directory
output_file_dir = '.' if os.path.dirname(output_file) == '' else os.path.dirname(output_file)
if not os.access(output_file_dir, os.W_OK):
print(f"Error: output file directory '{output_file_dir}' is not writable")
return False

# get the free space in the output file directory
try:
statvfs = os.statvfs(output_file_dir)
free_space = statvfs.f_frsize * statvfs.f_bavail
if free_space < 1024 * 1024 * 1024:
print(f"WARN: output file directory {output_file_dir} has {sizeof_fmt(free_space)} free space")
except AttributeError:
pass

try:
with open(output_file, "ab") as f:
f.close()
pass
except FileNotFoundError:
print(f"WARN: output file '{output_file}' not found")
return False

return True


# checks if the input file can be read and the output file can be written
def test_io(input_file: Optional[str], output_file: Optional[str]) -> bool:
if not test_input_file(input_file):
return False
if not test_output_file(output_file):
return False
return True


class TestInputFile(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
if test_input_file(values):
setattr(namespace, self.dest, values)


class TestOutputFile(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
if test_output_file(values):
setattr(namespace, self.dest, values)


def add_argument_hidden_in_gui(parser, use_gui, *args, **kwargs):
if use_gui:
Expand Down Expand Up @@ -48,11 +133,25 @@ def common_parser_gui_inner(meta_title):
return common_parser_gui_inner(meta_title)


def common_parser_cli(meta_title, default_threads=5):
def common_parser_cli(meta_title, default_threads=DEFAULT_THREADS + 1):
parser = argparse.ArgumentParser(description=meta_title)
parser.add_argument("infile", metavar="infile", type=str, help="source file")
parser.add_argument(
"outfile", metavar="outfile", type=str, help="base name for destination files"
"infile",
metavar="infile",
type=str,
help="source file",
nargs='?',
default=DEFAULT_INPUT_FILENAME,
action=TestInputFile
)
parser.add_argument(
"outfile",
metavar="outfile",
type=str,
help="base name for destination files",
nargs='?',
default=DEFAULT_OUTPUT_FILENAME,
action=TestOutputFile
)
# help="Disable AGC (deprecated, already disabled by default)
parser.add_argument(
Expand All @@ -69,7 +168,7 @@ def common_parser_cli(meta_title, default_threads=5):
return common_parser_inner(parser, default_threads=default_threads)


def common_parser_inner(parser, use_gui=False, default_threads=4):
def common_parser_inner(parser, use_gui=False, default_threads=DEFAULT_THREADS):
parser.add_argument(
"--system",
metavar="system",
Expand Down Expand Up @@ -289,7 +388,15 @@ def select_system(args):
return system


class IOArgsException(Exception):
pass


def get_basics(args):
can_io = test_io(args.infile, args.outfile)
if not 'UI' in args:
if not can_io:
raise IOArgsException("Input/output file error")
return args.infile, args.outfile, args.start, args.length


Expand Down
20 changes: 13 additions & 7 deletions vhsdecode/hifi/HifiUi.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,16 +494,14 @@ def on_input_samplerate_changed(self):
else:
self.input_sample_rate = self._input_combo_rates[self.input_samplerate_combo.currentIndex()]

def on_decode_finished(self, decoded_filename: str = 'input stream'):
self.setWindowIcon(QIcon.fromTheme('document-open'))
# alerts user that decode is finished
def generic_message_box(self, title:str, message:str, type:QMessageBox.Icon=QMessageBox.Information):
message_box = QMessageBox(
QMessageBox.Information,
'Decode Finished',
f'Decode of {decoded_filename} finished.',
type,
title,
message,
parent=self
)
message_box.setIcon(QMessageBox.Information)
message_box.setIcon(type)
message_box.setDefaultButton(QMessageBox.Ok)
# dark mode
message_box.setStyleSheet("""
Expand All @@ -518,6 +516,14 @@ def on_decode_finished(self, decoded_filename: str = 'input stream'):
""")
message_box.exec_()

def on_decode_finished(self, decoded_filename: str = 'input stream'):
self.setWindowIcon(QIcon.fromTheme('document-open'))
# alerts user that decode is finished
self.generic_message_box(
"Decode Finished",
f'Decode of {decoded_filename} finished.'
)


class FileOutputDialogUI(HifiUi):
def __init__(self, params: MainUIParameters, title: str = "HiFi File Output", main_layout_callback=None):
Expand Down
30 changes: 25 additions & 5 deletions vhsdecode/hifi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
select_sample_freq,
select_system,
get_basics,
test_input_file,
test_output_file
)
from vhsdecode.hifi.HiFiDecode import HiFiDecode, NoiseReduction, DEFAULT_NR_GAIN_, discard_stereo
from vhsdecode.hifi.TimeProgressBar import TimeProgressBar
import io
import sounddevice as sd

try:
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QApplication, QMessageBox
from vhsdecode.hifi.HifiUi import ui_parameters_to_decode_options, decode_options_to_ui_parameters, \
FileIODialogUI, FileOutputDialogUI
HIFI_UI = True
Expand Down Expand Up @@ -704,9 +706,22 @@ def main() -> int:
# change to output file directory
if os.path.dirname(options["output_file"]) != '':
os.chdir(os.path.dirname(options["output_file"]))
decoder_state = run_decoder(args, options, ui_t=ui_t)
ui_t.window.transport_state = 0
ui_t.window.on_decode_finished()

# test input and output files
if test_input_file(options["input_file"]) and test_output_file(options["output_file"]):
decoder_state = run_decoder(args, options, ui_t=ui_t)
ui_t.window.transport_state = 0
ui_t.window.on_decode_finished()
else:
message = None
if not test_input_file(options['input_file']):
message = f"Input file '{options['input_file']}' not found"
elif not test_output_file(options['output_file']):
message = f"Output file '{options['output_file']}' cannot be created nor overwritten"

ui_t.window.generic_message_box("I/O Error", message, QMessageBox.Critical)
ui_t.window.on_stop_clicked()

ui_t.app.processEvents()
time.sleep(0.01)
ui_t.window.transport_state = 0
Expand All @@ -715,7 +730,12 @@ def main() -> int:

return decoder_state
else:
return run_decoder(args, decode_options)
if test_input_file(filename) and test_output_file(outname):
return run_decoder(args, decode_options)
else:
parser.print_help()
print("ERROR: input file not found" if not test_input_file(filename) else f"ERROR: output file '{outname}' cannot be created nor overwritten")
return 1


if __name__ == "__main__":
Expand Down
12 changes: 11 additions & 1 deletion vhsdecode/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
get_basics,
get_rf_options,
get_extra_options,
IOArgsException,
test_input_file,
test_output_file,
)

supported_tape_formats = {
Expand Down Expand Up @@ -282,7 +285,14 @@ def main(args=None, use_gui=False):

args = parser.parse_args(args)

filename, outname, firstframe, req_frames = get_basics(args)
try:
filename, outname, firstframe, req_frames = get_basics(args)
except IOArgsException as e:
parser.print_help()
print(e)
print(f"ERROR: input file '{args.infile}' not found" if not test_input_file(args.infile) else "Input file: OK")
print(f"ERROR: output file '{args.outfile}' is not writable" if not test_output_file(args.outfile) else "Output file: OK")
sys.exit(1)

if not args.overwrite:
conflicts_ext = [".tbc", "_chroma.tbc", ".log", ".tbc.json"]
Expand Down
Loading