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

test possible audio input to write_videofile #1037

Closed
Closed
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
Binary file added media/clip1024.flv
Binary file not shown.
61 changes: 61 additions & 0 deletions tests/test_VideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from moviepy.audio.io.AudioFileClip import AudioFileClip
from moviepy.video.fx.speedx import speedx
from moviepy.utils import close_all_clips
from moviepy.video.io.ffmpeg_reader import ffmpeg_parse_infos

from .test_helper import TMP_DIR

Expand Down Expand Up @@ -150,5 +151,65 @@ def test_withoutaudio():
close_all_clips(locals())


def test_write_videofile_default_audio():
clip = VideoFileClip("media/big_buck_bunny_432_433.webm")
location = os.path.join(TMP_DIR, "test_write_videofile_default_audio.mp4")
clip.write_videofile(location)
d=ffmpeg_parse_infos(location)
assert d['video_found']
assert d['audio_found']


def test_write_videofile_without_audio():
clip = VideoFileClip("media/big_buck_bunny_432_433.webm")
location = os.path.join(TMP_DIR, "test_write_videofile_without_audio.mp4")
clip.write_videofile(location, audio=False)
d=ffmpeg_parse_infos(location)
assert d['video_found']
assert not d['audio_found']


def test_write_videofile_with_audio():
clip = VideoFileClip("media/big_buck_bunny_432_433.webm")
location = os.path.join(TMP_DIR, "test_write_videofile_with_audio.mp4")
clip.write_videofile(location, audio=True)
d=ffmpeg_parse_infos(location)
assert d['video_found']
assert d['audio_found']


def test_write_videofile_with_provided_audio():
clip = VideoFileClip("media/big_buck_bunny_432_433.webm")
location = os.path.join(TMP_DIR, "test_write_videofile_with_provided_audio.mp4")
clip.write_videofile(location, audio="media/crunching.mp3")
d=ffmpeg_parse_infos(location)
assert d['video_found']
assert d['audio_found']


def test_write_videofile_with_silent_video():
source = "media/clip1024.flv"
clip = VideoFileClip(source)
d=ffmpeg_parse_infos(source)
assert not d['audio_found']
location = os.path.join(TMP_DIR, "test_write_videofile_with_silent_video.mp4")
clip.write_videofile(location)
d=ffmpeg_parse_infos(location)
assert d['video_found']
assert not d['audio_found']


def test_write_videofile_adds_audio_to_silent_video():
source = "media/clip1024.flv"
clip = VideoFileClip(source)
d=ffmpeg_parse_infos(source)
assert not d['audio_found']
location = os.path.join(TMP_DIR, "test_write_videofile_adds_audio_to_silent_video.mp4")
clip.write_videofile(location, audio="media/crunching.mp3")
d=ffmpeg_parse_infos(location)
assert d['video_found']
assert d['audio_found']


if __name__ == "__main__":
pytest.main()