mgbam commited on
Commit
a5cec01
·
verified ·
1 Parent(s): cc3065b

Update pipelines/video_process.py

Browse files
Files changed (1) hide show
  1. pipelines/video_process.py +33 -8
pipelines/video_process.py CHANGED
@@ -1,13 +1,23 @@
1
  import subprocess
 
2
 
3
  def extract_audio_ffmpeg(in_video, out_audio="temp_audio.wav"):
 
 
 
 
 
 
 
 
 
4
  cmd = [
5
  "ffmpeg", "-y",
6
  "-i", in_video,
7
- "-vn",
8
  "-acodec", "pcm_s16le",
9
- "-ar", "16000",
10
- "-ac", "1",
11
  out_audio
12
  ]
13
  result = subprocess.run(cmd, capture_output=True)
@@ -15,13 +25,28 @@ def extract_audio_ffmpeg(in_video, out_audio="temp_audio.wav"):
15
  raise RuntimeError(f"FFmpeg audio extraction failed: {result.stderr.decode()}")
16
  return out_audio
17
 
 
18
  def apply_edits(original_video, edit_instructions):
19
  """
20
- Suppose edit_instructions is a JSON or dictionary specifying which segments to keep.
21
- We'll write them to a concat file or do a more advanced approach.
 
 
 
 
 
 
22
  """
23
- # parse or generate concat script
24
- # run ffmpeg to produce "edited_video.mp4"
 
25
  out_path = "edited_video.mp4"
26
- # ...
 
 
 
 
 
 
 
27
  return out_path
 
1
  import subprocess
2
+ import os
3
 
4
  def extract_audio_ffmpeg(in_video, out_audio="temp_audio.wav"):
5
+ """
6
+ Extracts the audio track from the given video file using FFmpeg.
7
+ Saves it to the specified WAV file.
8
+
9
+ :param in_video: Path to the input video file (e.g., MP4).
10
+ :param out_audio: Path to the output WAV file.
11
+ :return: The path to the output WAV file (same as out_audio).
12
+ :raises RuntimeError: If the ffmpeg command fails.
13
+ """
14
  cmd = [
15
  "ffmpeg", "-y",
16
  "-i", in_video,
17
+ "-vn", # disable video
18
  "-acodec", "pcm_s16le",
19
+ "-ar", "16000", # sample rate
20
+ "-ac", "1", # mono
21
  out_audio
22
  ]
23
  result = subprocess.run(cmd, capture_output=True)
 
25
  raise RuntimeError(f"FFmpeg audio extraction failed: {result.stderr.decode()}")
26
  return out_audio
27
 
28
+
29
  def apply_edits(original_video, edit_instructions):
30
  """
31
+ Applies editing instructions (e.g., cut segments, transitions) to the original video
32
+ and produces a final edited video file named 'edited_video.mp4'.
33
+
34
+ :param original_video: Path to the original video file.
35
+ :param edit_instructions: JSON/dict specifying which segments to keep,
36
+ transitions, or other advanced edits.
37
+ :return: Path to the newly created 'edited_video.mp4'.
38
+ :raises RuntimeError: If ffmpeg or any editing command fails.
39
  """
40
+ # In a real implementation, you'd parse 'edit_instructions' to build an ffmpeg
41
+ # filter or a concat script. For now, we'll just return a placeholder path.
42
+
43
  out_path = "edited_video.mp4"
44
+
45
+ # Example placeholder: direct copy (no edits).
46
+ # cmd = ["ffmpeg", "-y", "-i", original_video, "-c", "copy", out_path]
47
+ # result = subprocess.run(cmd, capture_output=True)
48
+ # if result.returncode != 0:
49
+ # raise RuntimeError(f"FFmpeg editing error: {result.stderr.decode()}")
50
+
51
+ # Return the output path (in a real scenario, ensure the final file is actually created).
52
  return out_path