Compare commits

..

2 Commits

Author SHA1 Message Date
7fc9beec45 updated check_metadata 2022-08-25 10:36:37 +02:00
7740b2e300 allow basic filtering and export 2022-02-26 19:33:38 +01:00
7 changed files with 17 additions and 158 deletions

9
.gitignore vendored
View File

@ -138,8 +138,11 @@ dmypy.json
# Cython debug symbols
cython_debug/
av1output/
*.mp4
*.mkv
*.png
*.mkv
*.mp4

View File

@ -13,6 +13,8 @@ import subprocess
import datetime
from dataclasses import dataclass
from tqdm import tqdm
import operator
@dataclass
class MediaFile:
@ -97,8 +99,11 @@ def scan_files(path):
return media_files
def print_all(media_files):
media_files.sort(key=lambda x: x.size, reverse=True)
for media_file in media_files:
print ("{:<64} | {:<8} | {:<16} | {:<8} | {:<16}".format(cut_file_name(media_file.name, 64), str(datetime.timedelta(seconds=media_file.duration)).split(".")[0], human_readable_size(media_file.size), media_file.codec, str(media_file.resolution[0])+"x"+str(media_file.resolution[1])))
#print ("{:<64} | {:<8} | {:<16} | {:<8} | {:<16}".format(cut_file_name(media_file.name, 64), str(datetime.timedelta(seconds=media_file.duration)).split(".")[0], human_readable_size(media_file.size), media_file.codec, str(media_file.resolution[0])+"x"+str(media_file.resolution[1])))
if int(media_file.resolution[0]) == 1920 and media_file.codec != "av1" and media_file.codec != "vp9":
print ('"' + media_file.name + '"')
def print_codecs(media_files):
codecs = list()
@ -134,8 +139,8 @@ def main() -> None:
print("")
print_all(media_files)
print("")
print_codecs(media_files)
#print("")
#print_codecs(media_files)
if __name__ == "__main__":

View File

@ -1,12 +0,0 @@
from setuptools import setup
setup(
name="checkMetadata",
version="0.0.1",
packages=["checkMetadata"],
entry_points={
"console_scripts": [
"checkMetadata = checkMetadata.__main__:main"
]
},
)

View File

@ -3,7 +3,7 @@
""" Author: Hendrik Schutter, localhorst@mosad.xyz
Date of creation: 2022/01/22
Date of last modification: 2022/08/25
Date of last modification: 2022/01/25
"""
import os
@ -134,7 +134,7 @@ def human_readable_size(size, decimal_places=2):
size /= 1024.0
return f"{size:.{decimal_places}f} {unit}"
def main():
def main() -> None:
if(len(sys.argv) != 3):
print("Bad usage!")
print("Usage: python ./codec_analyzer.py file file")
@ -182,4 +182,4 @@ def main():
delete_temp_dir()
if __name__ == "__main__":
main()
main()

View File

@ -1,15 +0,0 @@
from setuptools import setup
setup(
name="codecVis",
version="0.0.1",
packages=["codecVis"],
entry_points={
"console_scripts": [
"codecVis = codecVis.__main__:main"
]
},
install_requires=[
'Pillow>=9.2.0'
]
)

View File

@ -1,43 +0,0 @@
#! /bin/sh
####################################### HOW TO USE ################################################
# manually set MOVIES_DIR
# manually create and set OUTPUT_DIR
# manually set movies names in array
#####################################################################################################
MOVIES_DIR=/home/hendrik/git/media_management_scripts/codec_visualizer/
OUTPUT_DIR=/home/hendrik/git/media_management_scripts/av1output/
movies=("test.mp4")
echo "starting script ..."
echo " "
for movie in ${movies[@]}; do
echo "loop for $movie"
NEW_MOVIE_NAME=$"$(b=${movie##*/}; echo ${b%.*}).mkv"
TMP_MOVIE_NAME=$"tmp_$(b=${movie##*/}; echo ${b%.*}).mkv"
SCREENSHOT_MOVIE_NAME=$"tmp_$(b=${movie##*/}; echo ${b%.*}).png"
echo "NEW_MOVIE_NAME: $NEW_MOVIE_NAME"
echo "TMP_MOVIE_NAME: $TMP_MOVIE_NAME"
if [ -f "$OUTPUT_DIR$TMP_MOVIE_NAME" ]; then
echo "warning: tmp file exists --> delete $TMP_MOVIE_NAME"
rm "$OUTPUT_DIR$TMP_MOVIE_NAME"
fi
if [ -f "$OUTPUT_DIR$NEW_MOVIE_NAME" ]; then
echo "$NEW_MOVIE_NAME exists."
else
#ffmpeg -i $MOVIES_DIR$movie -c:v libaom-av1 -c:a libopus -mapping_family 1 -af aformat=channel_layouts=5.1 -c:s copy -map 0 -crf 24 -b:v 0 -b:a 128k -cpu-used 4 -row-mt 1 -tiles 2x2 $OUTPUT_DIR$TMP_MOVIE_NAME
ffmpeg -i $MOVIES_DIR$movie -vcodec libx264 -acodec aac $OUTPUT_DIR$TMP_MOVIE_NAME
mv $OUTPUT_DIR$TMP_MOVIE_NAME $OUTPUT_DIR$NEW_MOVIE_NAME
echo "$NEW_MOVIE_NAME converted."
codecVis $MOVIES_DIR$movie $OUTPUT_DIR$NEW_MOVIE_NAME
mv output.png $OUTPUT_DIR$SCREENSHOT_MOVIE_NAME
fi
done

View File

@ -1,79 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Author: Hendrik Schutter, localhorst@mosad.xyz
Date of creation: 2023/02/22
Date of last modification: 2023/02/22
"""
import os
import sys
import time
import subprocess
import datetime
from dataclasses import dataclass
from tqdm import tqdm
import operator
@dataclass
class MediaFile:
name: str #without extension
extension: str #without dot
full_path: str
def supported_file_extension(filename):
if filename.endswith('.mp4') or filename.endswith('.mkv') or filename.endswith('.m4v'):
return True
return False
def get_number_of_files(path):
#filter(supported_file_extension, files)
return sum([len(list(filter(supported_file_extension, files))) for r, d, files in os.walk(path)])
def cut_file_name(filename, max_lenght, ellipsis="..."):
if len(filename) > max_lenght:
return filename[:max_lenght-len(ellipsis)] + ellipsis
else:
return filename
def scan_files(path):
total_numbers_to_scan = get_number_of_files(path)
media_files = list() #stores all found files with metadata
pbar = tqdm(total=total_numbers_to_scan) #print progress bar
for root, dirs, files in os.walk(path, topdown=True):
for name in filter(supported_file_extension, files):
pbar.set_description("Processing %s" % str("{:<32}".format(cut_file_name(name, 32))))
full_path = os.path.join(root, name)
media_files.append(MediaFile(name=os.path.splitext(name)[0], extension=os.path.splitext(name)[1], full_path=full_path))
pbar.update(1)
pbar.close()
return media_files
def print_all(media_files, path):
for media_file in media_files:
if (media_file.extension == ".mp4"):
#print(media_file.name)
file_test_path = path + media_file.name + ".mkv"
#print("Testing for: " + file_test_path)
if (os.path.isfile(file_test_path)):
print(media_file.full_path)
#os.remove(media_file.full_path)
def main() -> None:
if(len(sys.argv) != 2):
path = '.' #use current pwd
else:
path = sys.argv[1] #use arg0 as path
media_files = scan_files(path) #scan all media files
print("")
print_all(media_files, path)
if __name__ == "__main__":
main()