通過Python將視頻添加圖片

from PIL import Image
from moviepy.editor import *from configs.settings import PROJECT_PATHdef movie_add_image(video_config, type, video_path, out_path):# 加載視頻文件video = VideoFileClip(video_path)all_time = 0for config in video_config:image = config.get('top_image')time = config.get('time')if image:# 打開圖片img = Image.open(f'{PROJECT_PATH}/src/{type}/{image}')new_img = img.resize((200, 300))new_img.save(f'{PROJECT_PATH}/src/{type}/tmp_{image}')# 添加圖片image_clip = ImageClip(f'{PROJECT_PATH}/src/{type}/tmp_{image}')image_clip = image_clip.set_position("center").set_start(all_time).set_duration(time)# 將文字和音樂添加到視頻中video = CompositeVideoClip([video, image_clip])all_time += time# 導出視頻video.write_videofile(out_path, codec='mpeg4', audio_codec='aac')
[{'subtitle': '盼望著,盼望著,東風來了,春天的腳步近了。', 'image': '1.png', 'time': 3}, {'subtitle': '一切都像剛睡醒的樣子,欣欣然張開了眼。', 'image': '1.png', 'time': 3}, {'subtitle': '山朗潤起來了,水漲起來了,太陽的臉紅起來了。', 'image': '1.png', 'time': 3}, {'subtitle': '不好意思打斷下,先來介紹下最新的顯卡排名。', 'image': '1.png', 'top_image': '9.png', 'time': 4}, {'subtitle': 'xxxxxxx第一名。', 'image': '1.png', 'top_image': '9.png', 'time': 2}, {'subtitle': 'xxxxxxx第2名。', 'image': '2.png', 'top_image': '9.png', 'time': 3}, {'subtitle': 'xxxxxxx第3名。', 'image': '2.png', 'top_image': '9.png', 'time': 3}, {'subtitle': 'xxxxxxx第4名。', 'image': '2.png', 'top_image': '9.png', 'time': 2}, {'subtitle': 'xxxxxxx第5名。', 'image': '2.png', 'top_image': '9.png', 'time': 3}, {'subtitle': '園子里,田野里,瞧去,一大片一大片滿是的。', 'image': '2.png', 'time': 3}, {'subtitle': '坐著,躺著,打兩個滾,踢幾腳球,', 'image': '2.png', 'time': 3}, {'subtitle': '賽幾趟跑,捉幾回迷藏。風輕悄悄的,草軟綿綿的。', 'image': '2.png', 'time': 4}, {'subtitle': '桃樹、杏樹、梨樹,你不讓我,我不讓你,都開滿了花趕趟兒。', 'image': '3.png', 'time': 5}, {'subtitle': '紅的像火,粉的像霞,白的像雪。', 'image': '3.png', 'time': 2}, {'subtitle': '花里帶著甜味兒,閉了眼,樹上仿佛已經滿是桃兒、杏兒、梨兒。', 'image': '3.png', 'time': 5}, {'subtitle': '花下成千成百的蜜蜂嗡嗡地鬧著,大小的蝴蝶飛來飛去。', 'image': '3.png', 'time': 4}, {'subtitle': '野花遍地是:雜樣兒,有名字的,沒名字的,', 'image': '3.png', 'time': 3}, {'subtitle': '散在花叢里,像眼睛,像星星,還眨呀眨的。', 'image': '3.png', 'time': 3}, {'subtitle': '“吹面不寒楊柳風”,不錯的,像母親的手撫摸著你。', 'image': '4.png', 'time': 4}, {'subtitle': '風里帶來些新翻的泥土的氣息,混著青草味兒,', 'image': '4.png', 'time': 3}, {'subtitle': '還有各種花的香,都在微微潤濕的空氣里醞釀。', 'image': '4.png', 'time': 3}, {'subtitle': '鳥兒將巢安在繁花嫩葉當中,高興起來了,', 'image': '4.png', 'time': 3}, {'subtitle': '呼朋引伴地賣弄清脆的喉嚨,唱出宛轉的曲子,', 'image': '4.png', 'time': 3}, {'subtitle': '跟輕風流水應和著。牛背上牧童的短笛,', 'image': '4.png', 'time': 3}, {'subtitle': '這時候也成天在嘹亮地響著。', 'image': '4.png', 'time': 2}, {'subtitle': '雨是最尋常的,一下就是三兩天。可別惱。', 'image': '5.png', 'time': 4}, {'subtitle': '看,像牛毛,像花針,像細絲,密密地斜織著,', 'image': '5.png', 'time': 3}, {'subtitle': '人家屋頂上全籠著一層薄煙。樹葉兒卻綠得發亮,', 'image': '5.png', 'time': 4}, {'subtitle': '小草也青得逼你的眼。傍晚時候,上燈了,', 'image': '5.png', 'time': 3}, {'subtitle': '一點點黃暈的光,烘托出一片這安靜而和平的夜。', 'image': '5.png', 'time': 4}, {'subtitle': '在鄉下,小路上,石橋邊,有撐起傘慢慢走著的人;', 'image': '6.png', 'time': 4}, {'subtitle': '還有地里工作的農民,披著蓑戴著笠。他們的草屋,', 'image': '6.png', 'time': 3}, {'subtitle': '稀稀疏疏的,在雨里靜默著。', 'image': '6.png', 'time': 2}, {'subtitle': '天上風箏漸漸多了,地上孩子也多了。', 'image': '7.png', 'time': 3}, {'subtitle': '城里鄉下,家家戶戶,老老小小,', 'image': '7.png', 'time': 2}, {'subtitle': '也趕趟兒似的,一個個都出來了。', 'image': '7.png', 'time': 3}, {'subtitle': '舒活舒活筋骨,抖擻抖擻精神,', 'image': '7.png', 'time': 2}, {'subtitle': '各做各的一份兒事去,“一年之計在于春”;', 'image': '7.png', 'time': 3}, {'subtitle': '剛起頭兒,有的是工夫,有的是希望。', 'image': '7.png', 'time': 2}, {'subtitle': '春天像剛落地的娃娃,從頭到腳都是新的,它生長著。', 'image': '8.png', 'time': 4}, {'subtitle': '春天像小姑娘,花枝招展的,笑著,走著。', 'image': '8.png', 'time': 3}, {'subtitle': '春天像健壯的青年,有鐵一般的胳膊和腰腳,他領著我們上前去。', 'image': '8.png', 'time': 5}]

1.通過VideoFileClip加載需要處理的視頻

2.通過Image類,來修改圖片的尺寸到指定大小

3.通過ImageClip來加載需要添加的圖片
可以設置圖片的顯示位置set_position
開始顯示時間set_start
停留時間set_duration

4.通過CompositeVideoClip類,來合并視頻和圖片

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/38999.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/38999.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/38999.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【NFS】【部署】NFS文件系統Server端部署,及客戶端掛載

服務器準備 主機名IPk8s04192.168.199.24k8s05192.168.199.25 配置husts文件 vi /etc/hosts #追加 192.168.199.24 k8s04 192.168.199.25 k8s05Server端部署 yum install -y nfs-utils創建NFS存儲目錄 mkdir /data配置NFS服務 vi /etc/exports #添加 /data 192.168.…

【React】上傳文章封面基礎實現

<Form.Item label"封面"><Form.Item name"type"><Radio.Group onChange{onTypeChange}><Radio value{1}>單圖</Radio><Radio value{3}>三圖</Radio><Radio value{0}>無圖</Radio></Radio.Group&…

react 自定義 年-月-日 組件,單獨選擇年、月、日,并且產生聯動

自定義 年-月-日 組件 code import { useState } from react function Year_Month_Date() {const [yearList, setYearList] useState([])const [monthList, setMonthList] useState([])const [dateList, setDateList] useState([])const [currentYear, setCurrentYear] u…

javaweb(四)——過濾器與監聽器

文章目錄 過濾器Filter基本概念濾波器的分類: 時域和頻域表示濾波器類型1. 低通濾波器(Low-Pass Filter)2. 高通濾波器(High-Pass Filter)3. 帶通濾波器(Band-Pass Filter)4. 帶阻濾波器(Band-Stop Filter) 濾波器參數1. 通帶頻率(Passband Frequency)2. 截止頻率(Cutoff Frequ…

【Kotlin】Kotlin 基礎語法指南

人不走空 &#x1f308;個人主頁&#xff1a;人不走空 &#x1f496;系列專欄&#xff1a;算法專題 ?詩詞歌賦&#xff1a;斯是陋室&#xff0c;惟吾德馨 目錄 &#x1f308;個人主頁&#xff1a;人不走空 &#x1f496;系列專欄&#xff1a;算法專題 ?詩詞歌…

dell g15機器awcc刪除后無法重新安裝

那是因為注冊表并沒有刪除干凈&#xff0c;需要手動刪除&#xff0c;但是普通小白又沒有時間進行手動刪除&#xff0c; 這個個時候就需要微軟的刪除工具的幫忙了. 微軟軟件刪除工具&#xff1a;修復阻止程序安裝或刪除的問題 - Microsoft 支持

Android的activity廣播無法接收,提示process gone or crashing原因有可能是那些?

當Android的Activity無法接收廣播&#xff0c;并且收到“process gone or crashing”的提示時&#xff0c;可能的原因有多種。以下是一些常見的原因和排查步驟&#xff1a; Activity生命周期問題&#xff1a; 如果Activity在廣播發送之前就已經被銷毀&#xff08;例如&#xf…

vue3 elementplus Springboot 課程購買系統案例源碼

系統演示 項目獲取地址 Springboot vue3 elementplus 課程購買系統案例源碼 附帶系統演示&#xff0c;環境搭建教程,開發工具 技術棧:SpringBoot Vue3 ElementPlus MybatisPlus 開發工具:idea 后端構建工具:Maven 前端構建工具:vite 運行環境:Windows Jdk版本:1.8 Nod…

《昇思25天學習打卡營第04天|數據集Dataset》

數據集 環境準備 # 實驗環境已經預裝了mindspore2.2.14&#xff0c;如需更換mindspore版本&#xff0c;可更改下面mindspore的版本號 !pip uninstall mindspore -y !pip install -i https://pypi.mirrors.ustc.edu.cn/simple mindspore2.2.14 import numpy as np from mindsp…

基于Tools體驗NLP編程的魅力

大模型能理解自然語言&#xff0c;從而能解決問題&#xff0c;但是就像人類大腦一樣&#xff0c;大腦只能發送指令&#xff0c;實際行動得靠四肢&#xff0c;所以LangChain4j提供的Tools機制就是大模型的四肢。 大模型的不足 大模型在解決問題時&#xff0c;是基于互聯網上很…

Tomcat部署與優化

Tomcat部署與優化 Tomcat簡述 server&#xff1a; 服務器&#xff0c;Tomcat運行的進程實例&#xff0c;一個Server中可以有多個service&#xff0c;但通常就一個 service&#xff1a;服務&#xff0c;用來組織Engine&#xff08;引擎&#xff09;和Connector&#xff08;連接…

gdb及其使用

gdb調試一&#xff1a; 首先進入gdb&#xff0c;確定好進程&#xff0c;輸入進程號 確定要調試哪個文件&#xff0c;然后輸入&#xff1a;&#xff08;b為打斷點&#xff09; (gdb) b serialization_protobuffer.h:write<ros::serialization::OStream>(ros::serializat…

MySQL的limit關鍵字和聚合函數講解

目錄 一、MySQL數據庫介紹二、MySQL聚合函數三、MySQL數據排序分組四、MySQL的limit關鍵字 一、MySQL數據庫介紹 MySQL是一種廣泛使用的開源關系型數據庫管理系統&#xff0c;由瑞典MySQL AB公司開發&#xff0c;后被Sun Microsystems收購&#xff0c;最終成為Oracle公司的一部…

RANSAC空間圓擬合實現

由初中的幾何知識我們可以知道&#xff0c;確定一個三角形至少需要三個不共線的點&#xff0c;因此確定一個三角形的外接圓至少可用三個點。我們不妨假設三個點坐標為P1(x1,y1,z1),P2(x2,y2,z2),P3(x3,y3,z3)。 圓方程的標準形式為&#xff1a; (xi-x)2(yi-y)2R2 &#xff08;1…

【Annotation】SpringBoot自定義注解

1. 自定義注釋是基于SpringAOP實現的 Spring AOP&#xff08;Aspect-Oriented Programming&#xff0c;面向切面編程&#xff09;是Spring框架中的一個強大功能模塊&#xff0c;它實現了AOP編程模型&#xff0c;允許開發者將橫切關注點&#xff08;如日志記錄、事務管理、安全…

新火種AI|蘋果要將蘋果智能做成AI時代的APP Store?

作者&#xff1a;一號 編輯&#xff1a;美美 蘋果還是想要自己做AI時代的“APP Store”。 自從去年開始落了隊&#xff0c;蘋果現在AI上開始高歌猛進。今年WWDC上展示的AI產品和與OpenAI的合作只是開始。有消息稱&#xff0c;蘋果正與Meta等AI巨頭展開深入合作&#xff0c;這…

隨想錄 Day 74 Floyd / A*

隨想錄 Day 74 Floyd / A* Bellman_ford 隊列優化 97. 小明逛公園 時間限制&#xff1a;1.000S 空間限制&#xff1a;256MB 題目描述 小明喜歡去公園散步&#xff0c;公園內布置了許多的景點&#xff0c;相互之間通過小路連接&#xff0c;小明希望在觀看景點的同時&#xff…

小和問題和逆序對問題

小和問題和逆序對問題 小和問題&#xff0c; 在一個數組中&#xff0c;每一個數左邊的數中比當前數小的數累加起來&#xff0c;叫做這個數組的小和&#xff0c;求一個數組的小和 直接遍歷&#xff1a; int littleSum1(int* arr, int L, int R) {int temp 0;for (int i L; …

Spring底層原理之bean的加載方式四 @import 注解

bean的加載方式四 import 第四種bean的導入方式 是import導入的方式 在配置類上面加上注解就行 package com.bigdata1421.config;import com.bigdata1421.bean.Dog; import org.springframework.context.annotation.Import;Import(Dog.class) public class SpringConfig4 {…

CesiumJS【Basic】- #041 繪制紋理線(Entity方式)- 需要自定義著色器

文章目錄 繪制紋理線(Entity方式)- 需要自定義著色器1 目標2 代碼2.1 main.ts3 資源文件繪制紋理線(Entity方式)- 需要自定義著色器 1 目標 使用Entity方式繪制紋理線 2 代碼 2.1 main.ts import * as Cesium from cesium;const viewer = new Cesium.Viewer