v04 zip mode

This commit is contained in:
13339479676 2022-01-19 10:10:55 +08:00
parent 3f932dc786
commit 5702bbd0a1
4 changed files with 13 additions and 5 deletions

View File

@ -268,6 +268,8 @@ python opencv_webcam.py -isasf -ic
python opencv_webcam.py -isasf -ic -zn test02.zip
# 自动命名压缩文件
python opencv_webcam.py -isasf -ic -isazn
# 自定义压缩模式,默认为写覆盖
python opencv_webcam.py -isasf -ic -zn test03.zip -zm a # 追加模式
```

View File

@ -69,6 +69,8 @@ def parse_args(known=False):
action='store_true', help='is auto zip name')
parser.add_argument('--zipName', '-zn',
default="test.zip", type=str, help='zip save name')
parser.add_argument('--zipMode', '-zm',
default="w", type=str, help='zip save mode')
args = parser.parse_known_args()[0] if known else parser.parse_args()
return args
@ -95,7 +97,8 @@ def webcam_opencv(device_index="0",
logMode="a",
is_compress=False,
is_autoZipName=False,
zipName="test.zip"):
zipName="test.zip",
zipMode="w"):
keyList = [quit_key, frame_capKey, pause_key] # 快捷键列表
hotkey_judge(keyList) # 快捷键冲突判断
@ -190,7 +193,7 @@ def webcam_opencv(device_index="0",
# ------------------压缩文件------------------
if (is_compress):
# 自定义压缩文件名称
webcam_zip(is_autoZipName, f'{ROOT_PATH}/{zipName}', frame_savePath)
webcam_zip(is_autoZipName, f'{ROOT_PATH}/{zipName}', frame_savePath, zipMode)
def main(args):
@ -220,6 +223,7 @@ def main(args):
is_compress = args.is_compress
is_autoZipName = args.is_autoZipName
zipName = args.zipName
zipMode = args.zipMode
argsYaml(args) # 脚本参数
@ -245,7 +249,8 @@ def main(args):
logMode,
is_compress,
is_autoZipName,
zipName)
zipName,
zipMode)
if __name__ == '__main__':

View File

@ -18,13 +18,13 @@ def is_zipFile(zipName):
# zip压缩
def webcam_zip(is_autoZipName, zipName, preZipFilePath):
def webcam_zip(is_autoZipName, zipName, preZipFilePath, zipMode):
if (is_autoZipName):
zipNameTmp = str(preZipFilePath).split('/')[-1]
zipName = f'{ROOT_PATH}/{zipNameTmp}.zip'
else:
is_zipFile(zipName)
zip_file = zipfile.ZipFile(zipName, 'a')
zip_file = zipfile.ZipFile(zipName, zipMode)
# ----------压缩开始----------
file_list = os.listdir(preZipFilePath)

1
v04.md
View File

@ -11,6 +11,7 @@
- 加入视频帧压缩功能
- 加入自定义压缩文件名称
- 加入自动命名压缩文件名称
- 加入自定义压缩模式
### BUG修复