Skip to content

Video editing with Python

Move ffmpeg_copy into ffmpeg_tools.py where it belongs

osaajani4aea1dbb7c5a
diff --git a/moviepy/video/io/ffmpeg_tools.py b/moviepy/video/io/ffmpeg_tools.py
index 8cb5351c..3d27147d 100644
--- a/moviepy/video/io/ffmpeg_tools.py
+++ b/moviepy/video/io/ffmpeg_tools.py
@@ -3,6 +3,8 @@
import os
import re
import subprocess
+from pathlib import Path
+from typing import Union
from moviepy.config import FFMPEG_BINARY, FFPLAY_BINARY
from moviepy.decorators import convert_parameter_to_seconds, convert_path_to_string
@@ -211,6 +213,48 @@ def ffmpeg_stabilize_video(
subprocess_call(cmd, logger=logger)
+def ffmpeg_copy(input_file: Union[str, Path], output_file: Union[str, Path]):
+ """
+ Re-mix a video file using ffmpeg.
+ This may fix issues with corrupted video file.
+
+ Parameters
+ ----------
+ input_file : str or Path file that will be re-encoded
+ output_file: str or Path path to save the re-encoded file
+
+ Returns
+ -------
+ None
+ """
+ # Convert input and output files to Path objects
+ input_path = Path(input_file).resolve()
+ output_path = Path(output_file).resolve()
+
+ # Check if the input file exists
+ if not input_path.exists():
+ raise FileNotFoundError(f"Input file '{input_file}' not found.")
+
+ if output_path.exists():
+ raise FileExistsError(f"Output file '{output_file}' already exists.")
+
+ try:
+ # Construct the ffmpeg command
+ command = [
+ FFMPEG_BINARY,
+ "-i",
+ str(input_path),
+ "-c",
+ "copy", # Copy streams without re-encoding
+ str(output_path),
+ ]
+
+ # Run the command
+ subprocess.run(command, check=True)
+ except subprocess.CalledProcessError as e:
+ raise IOError(f"Error: ffmpeg command failed with error {e}") from e
+
+
def ffmpeg_version():
"""
Retrieve the FFmpeg version.
diff --git a/moviepy/video/tools/ffmpeg_copy.py b/moviepy/video/tools/ffmpeg_copy.py
deleted file mode 100644
index 207b2776..00000000
--- a/moviepy/video/tools/ffmpeg_copy.py
+++ /dev/null
@@ -1,51 +0,0 @@
-"""Module contains a function to copy a video file using ffmpeg without re-encoding.
-This can be useful for fixing issues with corrupted video files.
-"""
-
-import subprocess
-from pathlib import Path
-from typing import Union
-
-from moviepy.config import FFMPEG_BINARY
-
-
-def ffmpeg_copy(input_file: Union[str, Path], output_file: Union[str, Path]):
- """
- Re-mix a video file using ffmpeg.
- This may fix issues with corrupted video file.
-
- Parameters
- ----------
- input_file : str or Path file that will be re-encoded
- output_file: str or Path path to save the re-encoded file
-
- Returns
- -------
- None
- """
- # Convert input and output files to Path objects
- input_path = Path(input_file).resolve()
- output_path = Path(output_file).resolve()
-
- # Check if the input file exists
- if not input_path.exists():
- raise FileNotFoundError(f"Input file '{input_file}' not found.")
-
- if output_path.exists():
- raise FileExistsError(f"Output file '{output_file}' already exists.")
-
- try:
- # Construct the ffmpeg command
- command = [
- FFMPEG_BINARY,
- "-i",
- str(input_path),
- "-c",
- "copy", # Copy streams without re-encoding
- str(output_path),
- ]
-
- # Run the command
- subprocess.run(command, check=True)
- except subprocess.CalledProcessError as e:
- raise IOError(f"Error: ffmpeg command failed with error {e}") from e