Мне удалось написать следующий код для объединения нескольких изображений в один файл mp4. Однако файл, созданный таким образом, «поврежден». Есть ли у кого-нибудь идеи, что может произойти?
def create_video_from_images(self, video_name='output_video.mp4'):
"""
Creates a video from images in a specified
"""
# Get sorted list of image files from the folder
image_files = sorted(
[os.path.join(self.images_dir, f) for f in os.listdir(self.images_dir) if f.endswith(('.png', '.jpg', '.jpeg'))]
)
# Read the first image to determine video dimensions
first_image = cv2.imread(image_files[0])
height, width, _ = first_image.shape
# Calculate frames per image
total_frames = int(30 * self.length) # Assuming 30 frames per second
frames_per_image = int(total_frames // len(image_files))
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for .mp4 files
output_file = os.path.join(self.video_dir, video_name)
video_writer = cv2.VideoWriter(output_file, fourcc, 30, (width, height))
for image_file in image_files:
img = cv2.imread(image_file)
if img.shape[:2] != (height, width):
img = cv2.resize(img, (width, height)) # Resize if dimensions differ
for _ in range(frames_per_image):
video_writer.write(img)
video_writer.release()
Подробнее здесь: https://stackoverflow.com/questions/792 ... ges-python
Создание видео из изображений (python) ⇐ Python
Программы на Python
1733062066
Anonymous
Мне удалось написать следующий код для объединения нескольких изображений в один файл mp4. Однако файл, созданный таким образом, «поврежден». Есть ли у кого-нибудь идеи, что может произойти?
def create_video_from_images(self, video_name='output_video.mp4'):
"""
Creates a video from images in a specified
"""
# Get sorted list of image files from the folder
image_files = sorted(
[os.path.join(self.images_dir, f) for f in os.listdir(self.images_dir) if f.endswith(('.png', '.jpg', '.jpeg'))]
)
# Read the first image to determine video dimensions
first_image = cv2.imread(image_files[0])
height, width, _ = first_image.shape
# Calculate frames per image
total_frames = int(30 * self.length) # Assuming 30 frames per second
frames_per_image = int(total_frames // len(image_files))
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for .mp4 files
output_file = os.path.join(self.video_dir, video_name)
video_writer = cv2.VideoWriter(output_file, fourcc, 30, (width, height))
for image_file in image_files:
img = cv2.imread(image_file)
if img.shape[:2] != (height, width):
img = cv2.resize(img, (width, height)) # Resize if dimensions differ
for _ in range(frames_per_image):
video_writer.write(img)
video_writer.release()
Подробнее здесь: [url]https://stackoverflow.com/questions/79241736/create-video-from-images-python[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия