简体   繁体   English

如何在Windows 3上运行Python 3中的子进程来转换视频?

[英]How run subprocess in Python 3 on windows for convert video?

I have a little problem, I have trying for a lot time converted a video with FFMPEG in python 3 like this: 我有一点问题,我已经尝试了很多时间在python 3中使用FFMPEG转换视频,如下所示:

The model, 该模型,

class Video(models.Model):
   name = models.CharField(max_length=200, null=False)
   state = models.CharField(max_length=30, null=False)
   user_email = models.CharField(max_length=30, null=False)
   uploadDate = models.DateTimeField(null=False)
   message = models.CharField(max_length=200, null=False)
   original_video = models.FileField(upload_to='video', null=True)
   converted = models.BooleanField(default=False)

And the code of converted. 和转换的代码。

video = Video.objects.filter(id=param_id).get()
pathConverted = 'C:\\Users\\diego\\Documents\\GitHub\\convertido.mp4'
cmd = ['ffmpeg', '-i ', video.original_video.path, ' -b 1500k -vcodec ibx264 -g 30', pathConverted]
print('Ejecutando... ', ' '.join(cmd))
try:
    proc = subprocess.run(cmd, shell=True, check=True)
    proc.subprocess.wait()
except subprocess.CalledProcessError as e:
    raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))

The error is this. 错误就是这个。

 raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output)) RuntimeError: command '['ffmpeg', '-i ', 'C:\\Users\\diego\\Documents\\GitHub\\video1.avi', ' -b 1500k -vcodec libx264 -g 30', 'C:\\Users\\diego\\Documents\\GitHub\\convertido.mp4']' return with error (code 1): None

And also I have tried this: 我也试过这个:

video = Video.objects.filter(id=1).get()
pathConverted = 'C:\\Users\\diego\\Documents\\GitHub\\convertido.mp4'
cmd = ['ffmpeg', '-i ', video.original_video.path, ' -b 1500k -vcodec libx264 -g 30', pathConverted]
print('Ejecutando... ', ' '.join(cmd))
proc = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
proc.subprocess.wait()

In this case the error is: 在这种情况下,错误是:

FileNotFoundError: [WinError 2] No such file or directory

But when I copy the path and paste this in CMD on windows for try this converted the video. 但是当我复制路径并将其粘贴到Windows上的CMD中以尝试此转换视频时。 It works fine. 它工作正常。

Then, I am confused, I don't understand what is the error. 然后,我很困惑,我不明白是什么错误。

Somebody can help me please? 有人可以帮帮我吗?

The file not found is file "ffmpeg". 找不到的文件是文件“ffmpeg”。 Try to enter file with path and extension : c:\\Program Files\\ffmpeg\\ffmpeg.exe 尝试输入带路径和扩展名的文件:c:\\ Program Files \\ ffmpeg \\ ffmpeg.exe

Best Regard Emmanuel 最好的问候Emmanuel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM