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 ...
随机推荐
- blender_(uv应用)................http://digitalman.blog.163.com/blog/static/23874605620174172058299/
轻松学习Blender基础入门之九:UV-1 2017-06-21 14:24:49| 分类: Blender |举报 |字号 订阅 下载LOFTER 我的照片书 | [前言] ...
- bazel和TensorFlow安装
bazel安装:https://docs.bazel.build/versions/master/install-ubuntu.html#install-with-installer-ubuntu 安 ...
- contab的使用方法
linux 系统则是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非常多的计划性工作,因此这个系统服务是默认启动的.另 外, 由于使用者自己也可以设置计划任务,所以, ...
- TWaver推智能手表挑战华为苹果
2015年的春节刚过,苹果.华为.三星就紧锣密鼓的发布了各自新产品.华为.苹果的智能手表最吸引眼球.TWaver也不甘示弱,立刻连夜推出了更像传统奢侈豪华手表的TWaver Watch,予以反击.看来 ...
- 利用CMD 創建新文件的機種方法
用 CMD 創建新文件 説明一下: 是在Windows的 CMD命令行模式下,或者在PowerShell命令行模式下創建新文件的機種方法. 創建空文件 cd.>a.txt cd.表示改变当前目录 ...
- 【Codeforces 682C】Alyona and the Tree
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 设dis[v]表示v以上的点到达这个点的最大权值(肯定是它的祖先中的某个点到这个点) 类似于最大连续累加和 当往下走(x,y)这条边的时候,设 ...
- IDEA建立一个可运行的struts2项目
参考博客:https://blog.csdn.net/shuai_wy/article/details/79027573 直接使用IDEA创建struts2项目,配置好tomcat后是跑不起来的 需要 ...
- ansible roles例子
#理解 changed_when failed_when become become_user ansible_become ansible_become_user static #检查group_v ...
- 通过混合编程分析的方法和机器学习预测Web应用程序的漏洞
通过混合编程分析的方法和机器学习预测Web应用程序的漏洞 由于时间和资源的限制,web软件工程师需要支持识别出有漏洞的代码.一个实用的方法用来预测漏洞代码可以提高他们安全审计的工作效率.在这篇文章中, ...
- 食物链 2001年NOI全国竞赛
时间限制: 3 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond 题目描述 Description 动物王国中有三类动物 A,B,C,这三类动物的食物链构成了有趣的环形.A吃B ...