在vba中使用ffmpeg更改视频格式 [英] use ffmpeg in vba to change video format
问题描述
我想更改演示文稿中出现的嵌入式视频的视频格式.我可以使用以下代码将视频文件导出到另一个文件夹:
I want to change the video format of the embedded videos that appears in a presentation. I achieve to export the video file to another folder using the following code:
Dim Finame As Variant
Dim oApp As Object
Dim StoreFolder As Variant
Dim Videoname As Variant
Dim FileNameFolder As Variant
MkDir "C:\template\videoZip"
Set oApp = CreateObject("Shell.Application")
FileNameFolder = "C:\template\videoZip\"
Finame = ActivePresentation.Path & "\" & ActivePresentation.Name
StoreFolder = "C:\template\created_files\"
oApp.Namespace("C:\template\videoZip\").CopyHere Finame
Name "C:\template\videoZip\" & ActivePresentation.Name As "C:\template\videoZip\" & ActivePresentation.Name & ".zip"
oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace("C:\template\videoZip\" & ActivePresentation.Name & ".zip").items
Dim firstCount As Integer
Dim lastCount As Integer
For j = 1 To videoNum
firstCount = oApp.Namespace(StoreFolder).items.count
Videoname = "C:\template\videoZip\ppt\media\media" & j & ".mp4"
oApp.Namespace(StoreFolder).CopyHere Videoname
lastCount = oApp.Namespace(StoreFolder).items.count
If firstCount = lastCount Then
MsgBox "The video has problems loading and it will not be shown (Only mp4 supported)"
End If
Next j
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.deletefolder "C:\template\videoZip"
End If
正如我所说,有了这样的代码,我可以获取演示文稿中的所有视频.现在,我想更改它们的格式.我听说可以使用ffmpeg.也欢迎其他更改格式的解决方案.
As I said, with this peace of code I can get all the videos that are in the presentation. Now I want to change the format of them. I heard that it is possible using ffmpeg. Other solutions to change format are welcome too.
推荐答案
至少在Linux上,用于转换视频文件的语法为
At least on Linux the syntax for converting your video files would be
ffmpeg -i media1.mp4 media1.avi
然后,您可以使用许多选项来播放尺寸,编解码器,修剪等内容.请参见 ffmpeg文档为此.
Then you have numerous options to play with size, codecs, trimming etc. See the ffmpeg documentation for that.
关于执行shell的线程命令并等待它们返回.
There is a thread on SO about executing shell commands and waiting until they return.
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
Dim errorCode As Integer
wsh.Run("C:\pathto\ffmpeg.exe -i media1.mp4 media1.avi", windowStyle, waitOnReturn)
这篇关于在vba中使用ffmpeg更改视频格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!