[feat] update-video.py
This commit is contained in:
17
.idea/.idea.Abyss/.idea/workspace.xml
generated
17
.idea/.idea.Abyss/.idea/workspace.xml
generated
@@ -10,21 +10,8 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="bf317275-3039-49bb-a475-725a800a0cce" name="Changes" comment="">
|
<list default="true" id="bf317275-3039-49bb-a475-725a800a0cce" name="Changes" comment="">
|
||||||
<change afterPath="$PROJECT_DIR$/Abyss/Toolkits/image-creator.py" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/Abyss/Toolkits/image-sum.py" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/Abyss/Toolkits/update-tags.py" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/Abyss/Toolkits/update-video.py" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/.idea.Abyss/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.Abyss/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/.idea.Abyss/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.Abyss/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Abyss.sln.DotSettings.user" beforeDir="false" afterPath="$PROJECT_DIR$/Abyss.sln.DotSettings.user" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Abyss/Toolkits/update-video.py" beforeDir="false" afterPath="$PROJECT_DIR$/Abyss/Toolkits/update-video.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Abyss/Components/Controllers/Media/ImageController.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Abyss/Components/Controllers/Media/ImageController.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/Abyss/Components/Controllers/Media/VideoController.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Abyss/Components/Controllers/Media/VideoController.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/Abyss/Components/Services/ConfigureService.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Abyss/Components/Services/ConfigureService.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/Abyss/Components/Services/ResourceService.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Abyss/Components/Services/ResourceService.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/Abyss/Components/Services/UserService.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Abyss/Components/Services/UserService.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/Abyss/Components/Tools/NaturalStringComparer.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Abyss/Components/Tools/NaturalStringComparer.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/Abyss/Model/Bookmark.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Abyss/Model/Bookmark.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/Abyss/Model/Comic.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Abyss/Model/Comic.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/Abyss/Properties/launchSettings.json" beforeDir="false" afterPath="$PROJECT_DIR$/Abyss/Properties/launchSettings.json" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -92,7 +79,7 @@
|
|||||||
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"XThreadsFramesViewSplitterKey": "0.30266345",
|
"XThreadsFramesViewSplitterKey": "0.30266345",
|
||||||
"git-widget-placeholder": "dev-task",
|
"git-widget-placeholder": "main",
|
||||||
"last_opened_file_path": "/storage/Images/31/summary.json",
|
"last_opened_file_path": "/storage/Images/31/summary.json",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
|
|||||||
@@ -68,6 +68,45 @@ def create_thumbnails(video_path, gallery_path, num_thumbnails=10):
|
|||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f" Error extracting thumbnail {i}.jpg: {e}")
|
print(f" Error extracting thumbnail {i}.jpg: {e}")
|
||||||
|
|
||||||
|
def create_cover(video_path, output_path, time_percent):
|
||||||
|
"""
|
||||||
|
Creates a cover image from a video at a specified time percentage.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
subprocess.run(['ffmpeg', '-version'], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||||
|
print("Error: ffmpeg is not installed or not in your PATH. Cannot create cover.")
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
duration_cmd = [
|
||||||
|
'ffprobe', '-v', 'error', '-show_entries', 'format=duration',
|
||||||
|
'-of', 'default=noprint_wrappers=1:nokey=1', str(video_path)
|
||||||
|
]
|
||||||
|
result = subprocess.run(duration_cmd, capture_output=True, text=True, check=True)
|
||||||
|
duration = float(result.stdout)
|
||||||
|
except (subprocess.CalledProcessError, ValueError) as e:
|
||||||
|
print(f"Could not get duration for '{video_path}': {e}. Cannot create cover.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if duration <= 0:
|
||||||
|
print(f"Warning: Invalid video duration for '{video_path}'. Cannot create cover.")
|
||||||
|
return
|
||||||
|
|
||||||
|
timestamp = duration * time_percent
|
||||||
|
|
||||||
|
ffmpeg_cmd = [
|
||||||
|
'ffmpeg', '-ss', str(timestamp), '-i', str(video_path),
|
||||||
|
'-vframes', '1', str(output_path), '-y'
|
||||||
|
]
|
||||||
|
|
||||||
|
print(f"Creating cover image from video at {timestamp:.2f} seconds...")
|
||||||
|
try:
|
||||||
|
subprocess.run(ffmpeg_cmd, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
print(f"Cover image created at {output_path}")
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"Error creating cover image: {e}")
|
||||||
|
|
||||||
def update_summary(base_path, name_input=None, author_input=None):
|
def update_summary(base_path, name_input=None, author_input=None):
|
||||||
"""
|
"""
|
||||||
Updates the summary.json file for a given path.
|
Updates the summary.json file for a given path.
|
||||||
@@ -141,6 +180,7 @@ def main():
|
|||||||
print("Commands:")
|
print("Commands:")
|
||||||
print(" -u <path> Update the summary.json in the specified path.")
|
print(" -u <path> Update the summary.json in the specified path.")
|
||||||
print(" -a <video_file> <path> Add a new video project in a new directory under the specified path.")
|
print(" -a <video_file> <path> Add a new video project in a new directory under the specified path.")
|
||||||
|
print(" -c <path> <time> Create a cover image from the video in the specified path at a given time percentage (0.0-1.0).")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
command = sys.argv[1]
|
command = sys.argv[1]
|
||||||
@@ -185,20 +225,49 @@ def main():
|
|||||||
shutil.copy(video_source_path, new_project_path / "video.mp4")
|
shutil.copy(video_source_path, new_project_path / "video.mp4")
|
||||||
print(f"Video copied to {new_project_path / 'video.mp4'}")
|
print(f"Video copied to {new_project_path / 'video.mp4'}")
|
||||||
|
|
||||||
# --- 新增功能:自动生成缩略图 ---
|
# Auto-generate thumbnails
|
||||||
video_dest_path = new_project_path / "video.mp4"
|
video_dest_path = new_project_path / "video.mp4"
|
||||||
create_thumbnails(video_dest_path, gallery_path)
|
create_thumbnails(video_dest_path, gallery_path)
|
||||||
# ------------------------------------
|
|
||||||
|
|
||||||
# Get user input for name and author
|
# Get user input for name and author, with a prompt for default values
|
||||||
video_name = input("Enter the video name: ")
|
print("\nEnter the video name (press Enter to use the original filename):")
|
||||||
video_author = input("Enter the author's name: ")
|
video_name = input(f"Video Name [{video_source_path.stem}]: ")
|
||||||
|
if not video_name:
|
||||||
|
video_name = video_source_path.stem
|
||||||
|
|
||||||
# Update the summary with user input
|
print("\nEnter the author's name (press Enter to use 'Anonymous'):")
|
||||||
|
video_author = input("Author Name [Anonymous]: ")
|
||||||
|
if not video_author:
|
||||||
|
video_author = "Anonymous"
|
||||||
|
|
||||||
|
# Update the summary with user input or default values
|
||||||
update_summary(new_project_path, name_input=video_name, author_input=video_author)
|
update_summary(new_project_path, name_input=video_name, author_input=video_author)
|
||||||
|
|
||||||
|
elif command == '-c':
|
||||||
|
if len(sys.argv) != 4:
|
||||||
|
print("Usage: python script.py -c <path> <time>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
base_path = Path(sys.argv[2])
|
||||||
|
video_path = base_path / "video.mp4"
|
||||||
|
cover_path = base_path / "cover.jpg"
|
||||||
|
|
||||||
|
try:
|
||||||
|
time_percent = float(sys.argv[3])
|
||||||
|
if not 0.0 <= time_percent <= 1.0:
|
||||||
|
raise ValueError
|
||||||
|
except ValueError:
|
||||||
|
print("Error: Time value must be a number between 0.0 and 1.0.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if not video_path.exists() or not video_path.is_file():
|
||||||
|
print(f"Error: video.mp4 not found at {video_path}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
create_cover(video_path, cover_path, time_percent)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Invalid command. Use -u or -a.")
|
print("Invalid command. Use -u, -a, or -c.")
|
||||||
print("Usage: python script.py <command> [arguments]")
|
print("Usage: python script.py <command> [arguments]")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user