Combining an audio file with video file in python
Combining an audio file with video file in python - Stack Overflow https://stackoverflow.com/questions/28219049/combining-an-audio-file-with-video-file-in-python
import os os_sep = os.sep
this_file_abspath = os.path.abspath(__file__)
this_file_dirname, this_file_name = os.path.dirname(this_file_abspath), os.path.abspath(__file__).split(os_sep)[
-1] f_mp3 = '{}{}{}'.format(this_file_dirname, os_sep, 'auido.mp3')
from playsound import playsound import time
import math this_time = time.time() # playsound(f_mp3) # t_spend = time.time() - this_time
t_spend = 58.777058839797974
# 音频的秒数
t_spend = math.ceil(t_spend)
import cv2
import glob # 每秒传输帧数(Frames Per Second)
fps = 100 # 保存视频的FPS,可以适当调整 FPS是图像领域中的定义,是指画面每秒传输帧数,通俗来讲就是指动画或视频的画面数。FPS是测量用于保存、显示动态视频的信息数量。每秒钟帧数愈多,所显示的动作就会愈流畅。通常,要避免动作不流畅的最低是30。某些计算机视频格式,每秒只能提供15帧。
fps = 15
fps = 5 fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G') # opencv3.0 f_v = '{}{}'.format(int(time.time()), 'saveVideo.avi')
f_img_d = '{}{}{}{}{}'.format(this_file_dirname, os_sep, 'mypng', os_sep, '*.jpg')
imgs = glob.glob(f_img_d) img = cv2.imread(imgs[0])
img_size = (img.shape[1], img.shape[0])
videoWriter = cv2.VideoWriter(f_v, fourcc, fps, img_size)
#
frame_min = cv2.imread(imgs[-1]) """
用图片总数均分音频时间
"""
os_delay_factor=0.14
os_delay_factor=0.05
myinterval = t_spend / len(imgs)*os_delay_factor for imgname in imgs:
this_time = time.time()
frame = cv2.imread(imgname)
videoWriter.write(frame)
while time.time() - this_time < myinterval:
print(imgname)
videoWriter.write(frame)
#cv2.waitKey(10 * 1000)
#time.sleep(0.5)
##单位时间,写入帧数越大,视频空间越大,
# time.sleep(0.5)
# for i in range(fps):
# print(imgname)
# videoWriter.write(frame) videoWriter.release()
音频视频 合成
import time import os
import os, os.path, sys
import win32process, win32event '''
ffmpeg 命令 - wangkangluo1 - 博客园 http://www.cnblogs.com/wangkangluo1/archive/2012/07/10/2585095.html ''' d='C:\\Users\\sas\\PycharmProjects\\mypygame\\ffmpeg-20180331-be502ec-win64-static\\bin\\ffmpeg.exe -i son.wav -i video_origine.avi video_finale.mpg'
d='C:\\Users\\sas\\PycharmProjects\\mypygame\\ffmpeg-20180331-be502ec-win64-static\\bin\\ffmpeg.exe -i auido.mp3 -i 1523174854saveVideo.avi video_finale.mp4' os.system(d)
C:\Users\sas\PycharmProjects\mypygame\ffmpeg-20180331-be502ec-win64-static\bin>ffmpeg.exe -i auido.mp3 -i 1523174854saveVideo.avi video_finale.mp4
ffmpeg version N-90553-gbe502ec6cd Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
libavutil 56. 12.100 / 56. 12.100
libavcodec 58. 16.100 / 58. 16.100
libavformat 58. 10.100 / 58. 10.100
libavdevice 58. 2.100 / 58. 2.100
libavfilter 7. 13.100 / 7. 13.100
libswscale 5. 0.102 / 5. 0.102
libswresample 3. 0.101 / 3. 0.101
libpostproc 55. 0.100 / 55. 0.100
[mp3 @ 000001be707ea140] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'auido.mp3':
Duration: 00:00:58.64, start: 0.000000, bitrate: 16 kb/s
Stream #0:0: Audio: mp3, 16000 Hz, mono, s16p, 16 kb/s
Input #1, avi, from '1523174854saveVideo.avi':
Duration: 00:01:05.80, start: 0.000000, bitrate: 5720 kb/s
Stream #1:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj420p(pc, bt470bg/unknown/unknown), 1080x1920 [SAR 1:1 DAR 9:16], 5736 kb/s, 5 fps, 5 tbr, 5 tbn, 5 tbc
Stream mapping:
Stream #1:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Stream #0:0 -> #0:1 (mp3 (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 000001be7080d7c0] using SAR=1/1
[libx264 @ 000001be7080d7c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000001be7080d7c0] profile High, level 4.0
[libx264 @ 000001be7080d7c0] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=5 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'video_finale.mp4':
Metadata:
encoder : Lavf58.10.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuvj420p(pc, progressive), 1080x1920 [SAR 1:1 DAR 9:16], q=-1--1, 5 fps, 10240 tbn, 5 tbc
Metadata:
encoder : Lavc58.16.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 69 kb/s
Metadata:
encoder : Lavc58.16.100 aac
frame= 329 fps= 87 q=-1.0 Lsize= 1068kB time=00:01:05.20 bitrate= 134.2kbits/s speed=17.3x
video:492kB audio:564kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.136881%
[libx264 @ 000001be7080d7c0] frame I:4 Avg QP: 4.35 size:118982
[libx264 @ 000001be7080d7c0] frame P:83 Avg QP:10.52 size: 119
[libx264 @ 000001be7080d7c0] frame B:242 Avg QP: 7.67 size: 71
[libx264 @ 000001be7080d7c0] consecutive B-frames: 1.8% 0.0% 0.9% 97.3%
[libx264 @ 000001be7080d7c0] mb I I16..4: 67.7% 26.8% 5.6%
[libx264 @ 000001be7080d7c0] mb P I16..4: 0.5% 0.0% 0.0% P16..4: 0.1% 0.0% 0.0% 0.0% 0.0% skip:99.3%
[libx264 @ 000001be7080d7c0] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.0% 0.0% 0.0% direct: 0.0% skip:100.0% L0:94.7% L1: 5.3% BI: 0.0%
[libx264 @ 000001be7080d7c0] 8x8 transform intra:24.1% inter:90.7%
[libx264 @ 000001be7080d7c0] coded y,uvDC,uvAC intra: 20.5% 23.5% 20.4% inter: 0.0% 0.0% 0.0%
[libx264 @ 000001be7080d7c0] i16 v,h,dc,p: 92% 6% 2% 0%
[libx264 @ 000001be7080d7c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 17% 22% 4% 4% 4% 5% 7% 4%
[libx264 @ 000001be7080d7c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 41% 25% 10% 3% 5% 5% 5% 4% 3%
[libx264 @ 000001be7080d7c0] i8c dc,h,v,p: 73% 11% 13% 3%
[libx264 @ 000001be7080d7c0] Weighted P-Frames: Y:1.2% UV:1.2%
[libx264 @ 000001be7080d7c0] ref P L0: 98.3% 0.0% 1.1% 0.6%
[libx264 @ 000001be7080d7c0] ref B L0: 94.5% 5.5%
[libx264 @ 000001be7080d7c0] kb/s:61.15
[aac @ 000001be7080f3c0] Qavg: 32863.445 C:\Users\sas\PycharmProjects\mypygame\ffmpeg-20180331-be502ec-win64-static\bin>
Combining an audio file with video file in python的更多相关文章
- moviepy音视频剪辑:使用fl_time报错OSError: MoviePy error: failed to read the first frame of video file
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt+moviepy音视频剪辑实战 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 在m ...
- libGraphicsMagickWand.so: cannot open shared object file: No such file or directory stack traceback:
参考博文:http://www.linuxidc.com/Linux/2016-07/133213.htm ==>> Check Passed, the num of bbox and f ...
- python3: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory
安装python3遇到报错: wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz ./configure --prefix=/u ...
- 安卓开发error opening trace file: No such file or directory (2)报错原因
error opening trace file: No such file or directory (2) 这个问题的出现是因为运行的测试机android系统版本和项目api不一致导致. 改成一样 ...
- error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
zabbix3.2启动有如下报错: # service zabbix_server startStarting zabbix_server: /home/zabbix-server/sbin/zab ...
- 错误解决:error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory
执行以下代码,生成唯一的UID $fp = popen("/xxx/bin/tools/uuidgen system", "r");// $uid = frea ...
- 【转】error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
错误信息: /usr/local/memcacheq/bin/memcacheq: error while loading shared libraries: libevent-2.0.so.5: c ...
- 解决openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory错误
问题 在Centos7上编译安装openssl后,运行openssl version出现如下错误: openssl: error while loading shared libraries: lib ...
- NopCommerce 发布时 Could not load file or assembly 'file:///...\Autofac.3.5.2\lib\net40\Autofac.dll' or one of its dependencies
本文转自:http://www.nopcommerce.com/boards/t/33637/4-errors.aspx 问题: The 3.5 solution compiles fine, and ...
随机推荐
- 梦想Android版CAD控件2018.7.26更新
下载地址: http://www.mxdraw.com/ndetail_109.html 1. 增加所有接口CHM帮助文档 2. 增加得到当前打开文件函数 3. 读写CAD扩展记录接口 4. 读写属性 ...
- JavaScipt30(第二个案例)
承接上篇https://www.cnblogs.com/wangxi01/p/10641115.html,这是第二个案例 附上项目链接: https://github.com/wesbos/JavaS ...
- js读写txt文件
view plain<script language="javascript" type="text/javascript"> //读文件funct ...
- ThinkPHP---thinkphp框架介绍
目录: (1)简述: (2)下载: (3)文件结构: (4)部署: (5)细节问题: 主体: (1)简述 ThinkPHP诞生于2006年初,最初叫FSC.于2007年元旦更名为PHP,同时官网上线. ...
- C++ Primer(第4版)-学习笔记-第3部分:类和数据抽象
第12章 类 每个类可以没有成员,也可以定义多个成员,成员可以是数据.函数或类型别名. 成员函数必须在类内部声明,可以在类内部定义,也可以在类外部定义.如果在类内部定义,就默认是内联函数. ...
- 『 Luogu P3205 』 HNOI2010 合唱队
解题思路 设置两个二维数组 $f$ 和 $g$,含义如下. $f[l][r]$ 表示在期望得到的队形中 $l\rightarrow r$ 这段区间初始队形排列的方案数,并且最后一个加入进去的是第 $l ...
- QQ浏览器占用资源真的大
Edge 和 QQ浏览器 对比 正常情况下: QQ浏览器 看1个直播频道 ,CPU就几乎是在90% usage 范围 ,看2 个 就非常卡 下面就是对比图 Edge 我个人觉得 Edge 比 QQ好用 ...
- 搭建一台功能简单的FTP服务器
#vi /etc/sysconfig/network-scripts/ifcfg-eno33554952 #revice network restart #ping www.baidu.com #ip ...
- buf.readInt8()
buf.readInt8(offset[, noAssert]) offset {Number} 0 noAssert {Boolean} 默认:false 返回:{Number} 从该 Buffer ...
- LINUX-SWAP文件系统
mkswap /dev/hda3 创建一个swap文件系统 swapon /dev/hda3 启用一个新的swap文件系统 swapon /dev/hda2 /dev/hdb3 启用两个swap分区