惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
雷峰网
雷峰网
Recent Announcements
Recent Announcements
月光博客
月光博客
G
Google Developers Blog
腾讯CDC
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
T
Tenable Blog
云风的 BLOG
云风的 BLOG
W
WeLiveSecurity
博客园 - 【当耐特】
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 聂微东
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
P
Privacy International News Feed
MyScale Blog
MyScale Blog
K
Kaspersky official blog
T
The Blog of Author Tim Ferriss
Attack and Defense Labs
Attack and Defense Labs
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
aimingoo的专栏
aimingoo的专栏
I
Intezer
Vercel News
Vercel News
小众软件
小众软件
Simon Willison's Weblog
Simon Willison's Weblog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
Latest news
Latest news
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tor Project blog
S
Security Affairs
P
Proofpoint News Feed
博客园 - 三生石上(FineUI控件)
博客园 - Franky
C
Cyber Attacks, Cyber Crime and Cyber Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
美团技术团队
Recent Commits to openclaw:main
Recent Commits to openclaw:main
S
Security @ Cisco Blogs
L
LINUX DO - 热门话题
Know Your Adversary
Know Your Adversary
Project Zero
Project Zero
D
Docker
L
Lohrmann on Cybersecurity
F
Full Disclosure

yyhhyyyyyy

Surge for Mac 配置教程:自用配置详解与 iOS 版差异 Surge for iOS 配置教程:自用配置文件逐段详解(General / 策略组 / 规则) Mac小企鹅输入法+雾凇拼音配置指南:从安装到同步 Winodws 双网卡实现内外网分流 VSCode 配置Ruff Cursor修改垂直布局 Clash Party/Clash Verge Rev/Sparkle 覆写与扩展脚本指南 解决 WSL2 与 Tunnel 模式网络冲突:MTU 设置妙招 Mihomo 配置教程:从零写一份完整配置文件(DNS / TUN / 分流规则详解) TUN 模式详解:System / gVisor / Mixed 三种堆栈的区别与选择 Tailscale+Headscale+自建Derp踩坑记录 解决Moviepy剪辑视频画面卡帧,但有声的问题 Surge Or Mihomo通过WireGuard回家 重装系统 -- Windows11 Win10/11配置fnm:解决PowerShell脚本运行受限问题 Ai 原画系统 基于社交媒体大数据的智慧政务系统 Miniconda安装教程 Doker-compose 网络互通 建立菲律宾台风损害模型
解决MoviePy保存视频时的视频质量降低问题
yyhhyyyyyy · 2024-08-14 · via yyhhyyyyyy

1. 起源

最近在折腾自动化剪辑视频的时候,发现我原视频视频质量看起来还ok,至少肉眼看过去还好,但是经过moviepy处理后保存下来的视频却质量降低了很多,会有很多噪点的产生。其实最直观的就是,传进去的视频大小是100MB,出来的视频就只有不到10MB,很明显就是被压缩了。

2. 解决方案

moviepy导出时的编码需要指定,且文件后缀也有一定要求。

先简单阐述下:

不同的编码器支持不同的容器格式(也称为封装格式)。以下是一些常见的编码器及其通常支持的容器格式:

  1. H.264 无损模式 :通常使用 .mp4.mkv 容器。
  2. H.265/HEVC 无损模式 :通常使用 .mp4.mkv 容器。
  3. ProRes:通常使用 .mov 容器。
  4. DNxHD/DNxHR:通常使用 .mov 容器。

代码附上:

H.264 无损模式(.mp4 容器)

video_clip.write_videofile(
    output_file + ".mp4",
    audio_codec="aac",
    temp_audiofile_path=output_dir,
    threads=params.n_threads or 2,
    logger=None,
    codec="libx264",
    ffmpeg_params=["-qp", "0"],  # 无损模式
    fps=video_clip.fps
)

H.264 无损模式(.mkv 容器)

video_clip.write_videofile(
    output_file + ".mkv",
    audio_codec="aac",
    temp_audiofile_path=output_dir,
    threads=params.n_threads or 2,
    logger=None,
    codec="libx264",
    ffmpeg_params=["-qp", "0"],  # 无损模式
    fps=video_clip.fps
)

H.265/HEVC 无损模式(.mp4 容器)

video_clip.write_videofile(
    output_file + ".mp4",
    audio_codec="aac",
    temp_audiofile_path=output_dir,
    threads=params.n_threads or 2,
    logger=None,
    codec="libx265",
    ffmpeg_params=["-qp", "0"],  # 无损模式
    fps=video_clip.fps
)

H.265/HEVC 无损模式(.mkv 容器)

video_clip.write_videofile(
    output_file + ".mkv",
    audio_codec="aac",
    temp_audiofile_path=output_dir,
    threads=params.n_threads or 2,
    logger=None,
    codec="libx265",
    ffmpeg_params=["-qp", "0"],  # 无损模式
    fps=video_clip.fps
)

ProRes(.mov 容器)

video_clip.write_videofile(
    output_file + ".mov",
    audio_codec="aac",
    temp_audiofile_path=output_dir,
    threads=params.n_threads or 2,
    logger=None,
    codec="prores",
    fps=video_clip.fps
)

请根据自己的需求选择合适的编码器和容器格式。当然也可以考虑使用 .mp4 容器,因为它是常见的格式,并且大多数编码器都支持。(不过偶尔mp4不太好用,moviepy没法直接保存