Merge branch 'main' into feat/web-editor
This commit is contained in:
commit
f0d4a66ff3
@ -55,7 +55,6 @@ def encode(input_file, codec, remove_source=False, save_log=False):
|
||||
"ffmpeg",
|
||||
"-i", input_file,
|
||||
"-map", "0",
|
||||
"-cq", str(cq),
|
||||
] + extra_params + [
|
||||
"-c:v", ffmpeg_codec,
|
||||
"-preset", "p4",
|
||||
|
@ -55,8 +55,6 @@ def get_video_metadata(file_path):
|
||||
"channels": stream.get("channels", 0),
|
||||
"flags": {
|
||||
"default": stream.get("disposition", {}).get("default", 0) == 1,
|
||||
"forced": stream.get("disposition", {}).get("forced", 0) == 1,
|
||||
"hearing_impaired": stream.get("disposition", {}).get("hearing_impaired", 0) == 1,
|
||||
"visual_impaired": stream.get("disposition", {}).get("visual_impaired", 0) == 1,
|
||||
"original": stream.get("disposition", {}).get("original", 0) == 1,
|
||||
"commentary": stream.get("disposition", {}).get("comment", 0) == 1
|
||||
@ -73,7 +71,6 @@ def get_video_metadata(file_path):
|
||||
"default": stream.get("disposition", {}).get("default", 0) == 1,
|
||||
"forced": stream.get("disposition", {}).get("forced", 0) == 1,
|
||||
"hearing_impaired": stream.get("disposition", {}).get("hearing_impaired", 0) == 1,
|
||||
"visual_impaired": stream.get("disposition", {}).get("visual_impaired", 0) == 1,
|
||||
"original": stream.get("disposition", {}).get("original", 0) == 1,
|
||||
"commentary": stream.get("disposition", {}).get("comment", 0) == 1
|
||||
}
|
||||
@ -86,13 +83,13 @@ def get_video_metadata(file_path):
|
||||
print(f"❌ Error processing {file_path}: {str(e)}")
|
||||
return None
|
||||
|
||||
def process_file(file_path, output_file=None):
|
||||
def process_file(file_path, output_dir=None):
|
||||
"""
|
||||
Process a single video file and write metadata to JSON.
|
||||
|
||||
Args:
|
||||
file_path (str): Path to the video file
|
||||
output_file (str, optional): Path to output JSON file
|
||||
output_dir (str, optional): Directory where the output JSON file will be saved
|
||||
"""
|
||||
if not os.path.isfile(file_path):
|
||||
print(f"❌ File not found: {file_path}")
|
||||
@ -106,27 +103,34 @@ def process_file(file_path, output_file=None):
|
||||
metadata = get_video_metadata(file_path)
|
||||
|
||||
if metadata:
|
||||
if not output_file:
|
||||
# Generate output filename based on input file
|
||||
# Generate output filename based on input file
|
||||
filename = os.path.basename(os.path.splitext(file_path)[0]) + "_metadata.json"
|
||||
|
||||
if output_dir:
|
||||
# Ensure output directory exists
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
output_path = os.path.join(output_dir, filename)
|
||||
else:
|
||||
# If no output directory specified, save in the same directory as the input file
|
||||
base_name = os.path.splitext(file_path)[0]
|
||||
output_file = f"{base_name}_metadata.json"
|
||||
output_path = f"{base_name}_metadata.json"
|
||||
|
||||
# Write metadata to JSON file
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
with open(output_path, 'w', encoding='utf-8') as f:
|
||||
json.dump(metadata, f, indent=2, ensure_ascii=False)
|
||||
|
||||
print(f"✅ Metadata saved to {output_file}")
|
||||
print(f"✅ Metadata saved to {output_path}")
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def process_directory(directory_path, output_file=None):
|
||||
def process_directory(directory_path, output_dir=None):
|
||||
"""
|
||||
Process all video files in a directory and write metadata to JSON.
|
||||
|
||||
Args:
|
||||
directory_path (str): Path to the directory
|
||||
output_file (str, optional): Path to output JSON file
|
||||
output_dir (str, optional): Directory where the output JSON file will be saved
|
||||
"""
|
||||
if not os.path.isdir(directory_path):
|
||||
print(f"❌ Directory not found: {directory_path}")
|
||||
@ -152,31 +156,38 @@ def process_directory(directory_path, output_file=None):
|
||||
print(f"❌ No supported video files found in {directory_path}")
|
||||
return False
|
||||
|
||||
if not output_file:
|
||||
# Generate output filename based on directory name
|
||||
dir_name = os.path.basename(os.path.normpath(directory_path))
|
||||
output_file = f"{dir_name}_metadata.json"
|
||||
# Generate output filename based on directory name
|
||||
dir_name = os.path.basename(os.path.normpath(directory_path))
|
||||
filename = f"{dir_name}_metadata.json"
|
||||
|
||||
if output_dir:
|
||||
# Ensure output directory exists
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
output_path = os.path.join(output_dir, filename)
|
||||
else:
|
||||
# If no output directory specified, save in the current directory
|
||||
output_path = filename
|
||||
|
||||
# Write all metadata to a single JSON file
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
with open(output_path, 'w', encoding='utf-8') as f:
|
||||
json.dump(all_metadata, f, indent=2, ensure_ascii=False)
|
||||
|
||||
print(f"✅ Metadata for {file_count} files saved to {output_file}")
|
||||
print(f"✅ Metadata for {file_count} files saved to {output_path}")
|
||||
return True
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Extract metadata from video files and save as JSON.")
|
||||
parser.add_argument("input", help="Path to input video file or directory")
|
||||
parser.add_argument("-o", "--output", help="Path to output JSON file")
|
||||
parser.add_argument("-o", "--output", help="Directory path where output JSON files will be saved")
|
||||
args = parser.parse_args()
|
||||
|
||||
input_path = args.input
|
||||
output_file = args.output
|
||||
output_dir = args.output
|
||||
|
||||
if os.path.isfile(input_path):
|
||||
process_file(input_path, output_file)
|
||||
process_file(input_path, output_dir)
|
||||
elif os.path.isdir(input_path):
|
||||
process_directory(input_path, output_file)
|
||||
process_directory(input_path, output_dir)
|
||||
else:
|
||||
print(f"❌ Path not found: {input_path}")
|
||||
sys.exit(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user