Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'decoder' parameter to VideoFileClip and ffmpeg_reader - v2 (dev) #2230

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions moviepy/video/io/VideoFileClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class VideoFileClip(VideoClip):
'rgb24' will be used as the default format unless ``has_mask`` is set
as ``True``, then 'rgba' will be used.

decoder:
The decoder used to decode the video file. FFmpeg's native VPx decoders
don't decode alpha. You have to use the libvpx decoder. Set this to
'libvpx-vp9' if you want to preserve transparency in .webm video.


Attributes
----------
Expand Down Expand Up @@ -95,6 +100,7 @@ def __init__(
audio_nbytes=2,
fps_source="fps",
pixel_format=None,
decoder=None,
):
VideoClip.__init__(self)

Expand All @@ -108,6 +114,7 @@ def __init__(
target_resolution=target_resolution,
resize_algo=resize_algorithm,
fps_source=fps_source,
decoder=decoder,
)

# Make some of the reader's attributes accessible from the clip
Expand All @@ -119,6 +126,7 @@ def __init__(
self.rotation = self.reader.rotation

self.filename = filename
self.decoder = decoder

if has_mask:
self.make_frame = lambda t: self.reader.get_frame(t)[:, :, :3]
Expand Down
25 changes: 16 additions & 9 deletions moviepy/video/io/ffmpeg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(
target_resolution=None,
resize_algo="bicubic",
fps_source="fps",
decoder=None,
):
self.filename = filename
self.proc = None
Expand Down Expand Up @@ -54,6 +55,7 @@ def __init__(
else:
self.size = target_resolution
self.resize_algo = resize_algo
self.decoder = decoder

self.duration = infos["video_duration"]
self.ffmpeg_duration = infos["duration"]
Expand Down Expand Up @@ -83,18 +85,23 @@ def initialize(self, start_time=0):
"""
self.close(delete_lastread=False) # if any

i_arg = ['-c:v', self.decoder] if self.decoder else []

if start_time != 0:
offset = min(1, start_time)
i_arg = [
"-ss",
"%.06f" % (start_time - offset),
"-i",
self.filename,
"-ss",
"%.06f" % offset,
]
i_arg = (
i_arg
+ [
"-ss",
"%.06f" % (start_time - offset),
"-i",
self.filename,
"-ss",
"%.06f" % offset,
]
)
else:
i_arg = ["-i", self.filename]
i_arg = i_arg + ["-i", self.filename]

cmd = (
[FFMPEG_BINARY]
Expand Down