increase playbackspeed
Browse files- App/Worker.py +45 -1
App/Worker.py
CHANGED
@@ -108,8 +108,51 @@ def create_symlink(source_dir, target_dir, symlink_name):
|
|
108 |
print(f"Symlink '{symlink_name}' already exists.")
|
109 |
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
def download_with_wget(link, download_dir, filename):
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
|
115 |
# @celery.task(name="CopyRemotion")
|
@@ -224,6 +267,7 @@ async def celery_task(video_task: EditorRequest):
|
|
224 |
create_json_file(video_task.assets, assets_dir)
|
225 |
download_assets(video_task.links, temp_dir)
|
226 |
render_video(temp_dir, output_dir)
|
|
|
227 |
# unsilence(temp_dir)
|
228 |
await cleanup_temp_directory(temp_dir, output_dir, video_task)
|
229 |
|
|
|
108 |
print(f"Symlink '{symlink_name}' already exists.")
|
109 |
|
110 |
|
111 |
+
def change_playback_speed(input_path, speed_factor):
|
112 |
+
"""
|
113 |
+
Change the playback speed of a video and overwrite the original file.
|
114 |
+
|
115 |
+
:param input_path: Path to the input video file.
|
116 |
+
:param speed_factor: Factor by which to increase the speed. (e.g., 2.0 for double speed)
|
117 |
+
"""
|
118 |
+
# Create a temporary output file
|
119 |
+
temp_output_path = input_path + ".temp.mp4"
|
120 |
+
|
121 |
+
# Construct the ffmpeg command
|
122 |
+
command = [
|
123 |
+
"ffmpeg",
|
124 |
+
"-i",
|
125 |
+
input_path,
|
126 |
+
"-filter_complex",
|
127 |
+
f"[0:v]setpts={1/speed_factor}*PTS[v];[0:a]atempo={speed_factor}[a]",
|
128 |
+
"-map",
|
129 |
+
"[v]",
|
130 |
+
"-map",
|
131 |
+
"[a]",
|
132 |
+
"-y", # Overwrite the output file if it exists
|
133 |
+
temp_output_path,
|
134 |
+
]
|
135 |
+
|
136 |
+
# Run the command
|
137 |
+
subprocess.run(command, check=True)
|
138 |
+
|
139 |
+
# Replace the original file with the new one
|
140 |
+
os.replace(temp_output_path, input_path)
|
141 |
+
|
142 |
+
|
143 |
def download_with_wget(link, download_dir, filename):
|
144 |
+
headers = [
|
145 |
+
"--header",
|
146 |
+
"Cookie: __Host-session=63EQahvTpHuoFSkEW75hC",
|
147 |
+
"--header",
|
148 |
+
"Cookie: __cf_bm=CDGicP5OErYjDI85UmQSRKlppJLlbcgCXlWcODoIQAI-1716296320-1.0.1.1-4Rm5_wdxupmrDWgddOQjEV01TMFC4UJ479GRIAKKGHNgXu3N8ZkASEZXGwCWaRyUYazsUaLMALk.4frWWJzHQ",
|
149 |
+
]
|
150 |
+
|
151 |
+
# Construct the full command
|
152 |
+
command = ["aria2c"] + headers + [link, "-d", download_dir, "-o", filename]
|
153 |
+
|
154 |
+
# Run the command
|
155 |
+
subprocess.run(command)
|
156 |
|
157 |
|
158 |
# @celery.task(name="CopyRemotion")
|
|
|
267 |
create_json_file(video_task.assets, assets_dir)
|
268 |
download_assets(video_task.links, temp_dir)
|
269 |
render_video(temp_dir, output_dir)
|
270 |
+
change_playback_speed(output_dir, 1.2)
|
271 |
# unsilence(temp_dir)
|
272 |
await cleanup_temp_directory(temp_dir, output_dir, video_task)
|
273 |
|