使用 python 或命令行进行视频编辑

发布于 2024-10-14 20:31:56 字数 789 浏览 7 评论 0原文

我需要在我的 python+django 项目中执行以下操作:

  • 加入具有相同大小和比特率的视频
  • 加入视频和图像(对于图像操作,我将使用 PIL:将文本写入现有图像)
  • 淡入视频之间的过渡

我已经知道一些Python视频编辑库:MLT框架(对于我的需要),pygamepymedia(不包含我想要的所有功能)、gstreamer 绑定(糟糕的文档)。

我还可以使用 ffmpeg 从命令行完成所有工作,mencoder转码

在 Linux 机器上执行此类操作的最佳方法是什么?

编辑:最终我选择使用melt(mlt的命令行)

I need to perform the following operations in my python+django project:

  • joining videos with same size and bitrate
  • joining videos and images (for the image manipulation I'll use PIL: writing text to an existing image)
  • fading in the transitions between videos

I already know of some video editing libraries for python: MLT framework (too complex for my needs), pygame and pymedia (don't include all the features I want), gstreamer bindings (terrible documentation).

I could also do all the work from command line, using ffmpeg, mencoder or transcode.

What's the best approach to do such a thing on a Linux machine.

EDIT: eventually I've chosen to work with melt (mlt's command line)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

脸赞 2024-10-21 20:31:56

http://avisynth.org/mediawiki/Main_Page 是一种视频脚本语言。

http://avisynth.org/mediawiki/Main_Page is a scripting language for video.

断爱 2024-10-21 20:31:56

因为 ffmpeg 在 GNU/Linux 上可用,所以我喜欢将它与 pexpectsubprocess 是最好的解决方案......

Because ffmpeg is available on GNU/Linux, i thing using it with modules such as pexpect or subprocess is the best solution....

橘虞初梦 2024-10-21 20:31:56

您可以使用 OpenCV 来连接视频和图像。请参阅文档,特别是图像/视频 I/O 函数

但是,我不确定该库是否具有可以为您进行淡入淡出的功能。

You can use OpenCV for joining videos and images. See the documentation, in particular the image/video I/O functions.

However, I'm not sure if the library has functions that will do the fading for you.

半寸时光 2024-10-21 20:31:56

您使用什么编解码器?

视频压缩有两种方法:有损和无损。很容易区分它们。根据其长度,有损视频文件在兆字节范围内,无损(包括未压缩)视频文件在千兆字节范围内。

这是一个过于简单化的情况。编辑视频文件与编辑胶片有很大不同,您只需将胶片粘合在一起即可。这不仅仅是比特率、帧率和分辨率的问题。大多数有损视频编解码器(MPEG 1-4、Ogg Theora、H.26x、VC-1 等)从全帧开始,然后仅记录运动变化。当您观看视频时,您实际看到的是一个静态场景,上面粘贴了一层又一层的变化。看起来您看到的是一个又一个的全帧,但如果您查看文件中的数据,您看到的将是黑色背景和混乱的视频块。

如果它是未压缩的或使用无损编解码器(HuffYUV、Lagarith、FFV1 等),那么您可以像电影一样编辑视频文件。您仍然需要重新编码视频,但这不会影响视频质量,您可以随意剪切、复制和粘贴,只要分辨率和帧速率相同即可。如果您的视频有损,则必须重新编码,但视频质量会有所损失,就像一遍又一遍地以 JPEG 格式保存相同的图像一样。

另一种选择可能是将多段视频放入 MKV 等容器中,并使用章节使其从一段视频跳转到另一段视频。我似乎记得有人告诉我这是可能的,但我从未尝试过,所以也许不是。

What codec are you using?

There are two ways to compress video: lossy and lossless. It's easy to tell them apart. Depending on their length, lossy video files are in the megabyte range, lossless (including uncompressed) are in the gigabyte range.

Here's an oversimplification. Editing video files is a lot different from editing film, where you just glue the pieces of film together. It's not just about bitrate, frame rate and resolution. Most lossy video codecs (MPEG 1-4, Ogg Theora, H.26x, VC-1, etc.) start out with a full frame then record only the changes in movement. When you watch the video what you're actually seeing is a static scene with layer after layer of changes pasted on top of it. It looks like you're seeing full frame after full frame, but if you looked at the data in the file all you'd see would be a black background and scrambled blocks of video.

If it's uncompressed or uses a lossless codec (HuffYUV, Lagarith, FFV1, etc.) then you can edit your video file just like film. You still have to re-encode the video but it won't effect video quality and you can cut, copy and paste however you like as long as the resolution and frame rate are the same. If you're video is lossy you have to re-encode it with some loss of video quality, just like saving the same image in JPEG, over and over.

Another option might be to put several pieces of video into a container like MKV and use chapters to have it jump from piece to piece. I seem to remember being told this is possible but I've never tried it so maybe it isn't.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文