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的更多相关文章

  1. moviepy音视频剪辑:使用fl_time报错OSError: MoviePy error: failed to read the first frame of video file

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt+moviepy音视频剪辑实战 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 在m ...

  2. 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 ...

  3. 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 ...

  4. 安卓开发error opening trace file: No such file or directory (2)报错原因

    error opening trace file: No such file or directory (2) 这个问题的出现是因为运行的测试机android系统版本和项目api不一致导致. 改成一样 ...

  5. 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 ...

  6. 错误解决: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 ...

  7. 【转】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 ...

  8. 解决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 ...

  9. 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 ...

随机推荐

  1. java操作zip文件

    思路: 1).读取zip中的文件并将除了重名文件之外的文件转存到中转zip文件中. 2).往中转文件中插入txt文件. 3).删除原zip文件. 4).将中转zip文件重命名为原zip文件. 前提,t ...

  2. 【sqli-labs】 less65 GET -Challenge -Blind -130 queries allowed -Variation4 (GET型 挑战 盲注 只允许130次查询 变化4)

    双引号括号闭合 http://192.168.136.128/sqli-labs-master/Less-65/?id=1")%23

  3. RabbitMQ系列(三)--Java API

    基于java使用RabbitMQ 框架:SpringBoot1.5.14.RELEASE maven依赖: <dependency> <groupId>com.rabbitmq ...

  4. Java基础——工具类

    一Java 常用类 Object Object类是所有类.数组.枚举类的父类.位于Java.lang包.也就是说,Java允许把任意类型的对象赋给Object类型的变量. Object类的常用方法 1 ...

  5. UVA - 1608 Non-boring sequences(分治法)

    题目: 如果一个序列的任意连续的子序列中至少有一个只出现一次的元素,则称这个序列是不无聊的.输入一个n(n≤200000)个元素的序列A(各个元素均为109以内的非负整数),判断它是不是不无聊的. 思 ...

  6. LCS(HDU_5495 循环节)

    传送门:LCS 题意:给出两个序列an和bn,想在给出一个序列pn,问经过a[p1],,,,a[pn]和b[p1],,,b[pn]变换后序列a和序列b的最长公共子序列的长度是多少. 思路:对a[i]- ...

  7. 安装ubuntu系统空间分配问题

    以下是我安装linux系统(ubuntu)时的系统空间配置,以50G为例: 挂载点 大小 格式 分区类型 / 15G Ext4 主分区 /home 30G Ext4 逻辑分区 /boot 1G Ext ...

  8. xfce 设在分辨率1920 1080

    #自定义cvt 1920 1080 #查看系统显示器名称xrandr #设置分辨率xrandr --newmode "1920x1080_60.00" 173.00 1920 20 ...

  9. Python介绍以及Python 优缺点

    Python是先编译成字节码,然后在解释执行的一门语言,而不是单纯的解释型语言 Python应用场景: Web应用开发. 操作系统管理,服务器运维的自动化脚本, 网络爬虫 科学计算 桌面软件 游戏 服 ...

  10. [luoguP2890] [USACO07OPEN]便宜的回文Cheapest Palindrome(DP)

    传送门 f[i][j] 表示区间 i 到 j 变为回文串所需最小费用 1.s[i] == s[j] f[i][j] = f[i + 1][j - 1] 2.s[i] != s[j] f[i][j] = ...