-1

I am using Moviepy to generate a new video from Python code. The purpose is to create a video that combines two TextClip objects, each displaying a different piece of text. Once executed, the code indeed produces an mp4 file. However, I am encountering an issue where I am unable to play the resulting video. When I attempt to open the file with Windows 11 Media Player, it displays an error with the code "0xc00d5212". This error is preventing me from verifying if the output video is as expected.

Here is the code I used:

from moviepy.editor import TextClip, concatenate_videoclips, CompositeVideoClip

jp_text = "こんにちは"
en_text = "Hello"

jp_clip = TextClip(jp_text, fontsize=24, color='white').set_duration(3)
en_clip = TextClip(en_text, fontsize=24, color='white').set_duration(3)

final_clip = concatenate_videoclips([jp_clip, en_clip])

final_clip.set_duration(6).set_fps(30).write_videofile("output.mp4")

To resolve the error, I tried a different approach, where I attempted to generate a webm video file instead of an mp4. I was able to play the resulting video, confirming that the code works in general. However, the output did not match my expectations as the image was incorrect.

The following is the code I tried:

final_clip.set_duration(6).set_fps(30).write_videofile("output.webm")

This is the resulting image: result

My expectation is to produce an mp4 video file that can be played back normally, with the correct images corresponding to the jp_clip and en_clip TextClips.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • Sounds like a question for over on https://github.com/Zulko/moviepy/issues because if you have a simple, clear, reproducible test case and moviepy doesn't generate a valid mp4 file with that code, that's something the people who _make_ moviepy will want to know about so they can fix that for everyone. Having said that: where's the part where you tell moviepy which font to use for each of the textclips? I don't see a `font=` argument, and you definitely don't want the OS to just pick "any random font". – Mike 'Pomax' Kamermans Jul 16 '23 at 16:01
  • Thanks for your comment. Your comment prompted me to look up font designations. Then I came across this Japanese article. (https://qiita.com/masachaco/items/75ac0d59bafe11231a14) Here I found how to specify font. Apparently, you don't have to specify anything for English, but you need to specify an appropriate font to display Japanese. Thanks to you I was able to find this fact. Thank you very much. – Creeper Saviour Jul 16 '23 at 17:02
  • On the other hand, the problem was solved with the following code. `FONT = 'SourceHanSansJP-Medium.otf'` `SIZE = (1080, 1920)` `jp_clip = TextClip(jp_text, font=FONT, fontsize=24, color='white', size=SIZE).set_duration(3)` `en_clip = TextClip(en_text, font=FONT, fontsize=24, color='white', size=SIZE).set_duration(3)` I saw that StackOverFlow requires 15 reputations to answer my own question myself, so I'll post it here. Thank you all for your help. – Creeper Saviour Jul 16 '23 at 17:04
  • Don't put that in a comment, write an answer and then accept it as solving the problem tomorrow. – Mike 'Pomax' Kamermans Jul 16 '23 at 22:09
  • I see. I wrote it. – Creeper Saviour Jul 17 '23 at 06:47

1 Answers1

1

The problem was solved with the following code.

FONT = 'SourceHanSansJP-Medium.otf'
SIZE = (1080, 1920)

jp_clip = TextClip(jp_text, font=FONT, fontsize=24, color='white', size=SIZE).set_duration(3)
en_clip = TextClip(en_text, font=FONT, fontsize=24, color='white', size=SIZE).set_duration(3)
Rabbid76
  • 202,892
  • 27
  • 131
  • 174