大二python+ffpmeg处理视频实验

很简单没啥好说的
1:

import subprocess
import os
VideoPath = "ffv.mp4"
#获取视频时长
cmd =' ffprobe -i %s -show_entries format=duration -of csv="p=0" -v quiet' % VideoPath
duration = os.popen(cmd,'r')
duration = duration.read()

#获取视频的帧率
cmd=' ffprobe -count_frames -i %s -select_streams v:0 -show_entries stream=avg_frame_rate -of csv="p=0" -v quiet'% VideoPath
rate= os.popen(cmd,'r')
rate = rate.read()

#获取视频帧数
cmd=' ffprobe -count_frames -i %s -select_streams v:0 -show_entries stream=nb_read_frames -of csv="p=0" -v quiet' % VideoPath
frames = os.popen(cmd,'r')
frames = frames.read()

#获取视频帧的长度和宽度
cmd1=' ffprobe -count_frames -i %s -select_streams v:0 -show_entries stream=height -of csv="p=0" -v quiet' % VideoPath
cmd2=' ffprobe -count_frames -i %s -select_streams v:0 -show_entries stream=width -of csv="p=0" -v quiet' % VideoPath
height = os.popen(cmd1,'r')
width = os.popen(cmd2,'r')
height = height.read()
width= width.read()
print ('Number of Frames = ', frames[:-1])
print ('Frame Rate = ', rate[:-1], 'fps')
print ('Duration = ', duration[:-1], 'sec')
print ('Height= ',height[:-1], 'px')
print ('Width = ',width[:-1], 'px')

在这里插入图片描述
2:

import subprocess
import os
#每秒提取一帧视频帧
VideoPath = "ffv.mp4"
OutputPath =  "KRYFRAMES"
cmd = "ffmpeg -i "+VideoPath+" -r 1 -f image2 "+OutputPath + "/%06d.jpg"
subprocess.call(cmd, shell=True)
#提取 I 帧
OutputPath = "I_FRAMES"
cmd = 'ffmpeg -i '+VideoPath+' -vf "select=eq(pict_type\,I)" -vsync vfr '+OutputPath + '/%06d.jpg'
subprocess.call(cmd, shell=True)
#提取 B 帧
OutputPath = "B_FRAMES"
cmd = 'ffmpeg -i '+VideoPath+' -vf "select=eq(pict_type\,B)" -vsync vfr '+OutputPath +'/%06d.jpg'
subprocess.call(cmd, shell=True)
#提取 P 帧
OutputPath ="P_FRAMES"
cmd = 'ffmpeg -i '+VideoPath+' -vf "select=eq(pict_type\,P)" -vsync vfr '+OutputPath +'/%06d.jpg'
subprocess.call(cmd, shell=True)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
3:

import subprocess
import os
VideoPath = "ffv.mp4"
#OutputPath =  "F://大二下//数媒基础//191002720//"
#boxblur 滤镜,模糊处理
cmd = "ffmpeg -i "+VideoPath+" -vf boxblur=4:1 v1.mp4"
subprocess.call(cmd, shell=True)
#添加红色偏色的阴影
cmd = "ffmpeg -i "+VideoPath+" -vf colorbalance=rs=0.5 red.mp4"
subprocess.call(cmd, shell=True)
#混合滤镜,给视频添加 logo
cmd = "ffmpeg -i "+VideoPath+" -i mark.jpg -filter_complex overlay v3.mp4"
subprocess.call(cmd, shell=True)

运行结果部分截图:
在这里插入图片描述
在这里插入图片描述

处理后变模糊的视频v1:
在这里插入图片描述
要为视频添加红色的滤镜,视频在处理后不知为何无法打开,但在Pr中的播放是正常的
在这里插入图片描述
我要添加的标志:
在这里插入图片描述
添加后的视频v3:
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值