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. RabbitMQ - Publisher的消息确认机制

    queue和consumer之间的消息确认机制:通过设置ack.那么Publisher能不到知道他post的Message有没有到达queue,甚至更近一步,是否被某个Consumer处理呢?毕竟对于 ...

  2. swift 扩展 要素总结

    类: 协议: 泛型及元素类型:扩展约束:

  3. 【LeetCode】7、Reverse Integer(整数反转)

    题目等级:Easy 题目描述: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 O ...

  4. Getting start with dbus in systemd (03) - sd-bus.h 使用例子 (systemd version>=221)

    sd-bus.h 例子 注意: sd-dbus 是systemd提供的lib,但是这个lib,只有在systemd>v221版本后才可以使用,centos 219版本太低,所以不能使用. 参考: ...

  5. block: cfq 学习01

    CFQ,即Completely Fair Queueing绝对公平调度器,力图为竞争块设备使用权的所有进程分配一个等同的时间片,在调度器分配给进程的时间片内,进程可以将其读写请求发送给底层块设备,当进 ...

  6. POJ3616 Milking Time【dp】

    Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her producti ...

  7. Pycharm Anaconda 安装dlib

    由于采用python3.7安装会出现各种问题,两种解决方法. 1)安装Cmake boost等(不推荐,麻烦且不容易成功). 2)安装Anaconda,创建一个python3.6的环境. 这里使用第二 ...

  8. PAT 1141 PAT Ranking of Institutions

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  9. [ural1057][Amount of Degrees] (数位dp+进制模型)

    Discription Create a code to determine the amount of integers, lying in the set [X; Y] and being a s ...

  10. 关于 startup_stm32f10x_hd.s 这个文件的一些说明

    关于 startup_stm32f10x_hd.s 这个文件的一些说明 startup_stm32f10x_hd.s 是一个启动文件,里面是使用汇编语言写好的基本程序,当STM32 芯片上电启动的时候 ...