英文:
Excuting ffmpeg commands using Python to locate *.png failed
问题
以下是翻译的部分:
-
当您在Bash终端中运行以下命令时,它可以正常工作:
ffmpeg -framerate 25 -pattern_type glob -i 'data/*.png' -i data/download_youtube/_-91nXXjrVo_cut.wav -c:v libx264 -pix_fmt yuv420p data/download_youtube/_-91nXXjrVo_out.mp4
-
但是,如果您尝试在Python中使用
os.system()
运行它时,您会遇到Unknown encoder 'libx264'
错误。 -
如果移除命令中的引号,如下所示:
os.system(r"ffmpeg -framerate 25 -pattern_type glob -i /data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png -i /data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav -c:v libx264 -pix_fmt yuv420p /data/share/VFHQ/data/download_youtube/out.mp4")
您会遇到
Option pattern_type not found
错误。 -
使用
subprocess.run(command, shell=True)
时,结果与上述情况相同。 -
如果您尝试在没有Shell的情况下运行
subprocess.run()
,会得到以下错误:[image2 @ 0x56001a8fee00] Could find no file with path '/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png' and index in the range 0-4 /data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png: No such file or directory
-
同样,去掉图片目录中的引号会导致
Unknown encoder 'libx264'
错误。 -
当您在图片目录周围使用引号运行命令时,也会遇到
'/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png': No such file or directory
错误。 -
后来发现您有两个版本的ffmpeg,一个是4.3,另一个是4.4.2。使用引号运行子进程会调用4.4.2版本,而不使用引号会调用4.3版本。
-
从4.3版本的日志中可以看到
Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'libx264'
,但最终会出现Unknown encoder 'libx264'
错误。
这些是您提供的信息的翻译摘要,如果您需要更多帮助,请告诉我。
英文:
The following command works well if I run it in the Bash terminal.
ffmpeg -framerate 25 -pattern_type glob -i 'data/*.png' -i data/download_youtube/_-91nXXjrVo_cut.wav -c:v libx264 -pix_fmt yuv420p data/download_youtube/_-91nXXjrVo_out.mp4
However, If i run it using os.system()
using Python.
os.system(r"ffmpeg -framerate 25 -pattern_type glob -i '/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png' -i /data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav -c:v libx264 -pix_fmt yuv420p /data/share/VFHQ/data/download_youtube/out.mp4")
I get Unknown encoder 'libx264'
If I remove the quotation mark inside the commands
os.system(r"ffmpeg -framerate 25 -pattern_type glob -i /data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png -i /data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav -c:v libx264 -pix_fmt yuv420p /data/share/VFHQ/data/download_youtube/out.mp4")
I get Option pattern_type not found.
So I tried subprocess.run(command,shell=True)
, I get same results as shown above.
Running 'subprocess.run()' without Shell will result in the following"
subprocess.run(['ffmpeg', '-framerate', '25','-pattern_type', 'glob', '-i','/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png',
'-i','/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav','-c:v','libx264','-pix_fmt','yuv420p','/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_out.mp4'])
[image2 @ 0x56001a8fee00] Could find no file with path '/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png' and index in the range 0-4
/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png: No such file or directory
With out the quotation marks on the picture directory:
CompletedProcess(args=['ffmpeg', '-framerate', '25', '-pattern_type', 'glob', '-i', '/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png', '-i', '/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav', '-c:v', 'libx264', '-pix_fmt', 'yuv420p', '/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_out.mp4'], returncode=1)
Unknown encoder 'libx264'
with quotation marks around the picture directory (also the correct way to run in the terminal):
subprocess.run(['ffmpeg', '-framerate', '25','-pattern_type', 'glob', '-i',"'/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png'",
'-i','/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav','-c:v','libx264','-pix_fmt','yuv420p','/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_out.mp4'])
'/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png': No such file or directory
It was later found out that I have 2versions of ffmpeg. One is 4.3 the other is 4.4.2
The thing is running a subprocess with quotation marks (I know it is incorrect as it has been explained) will call v4.4.2. Running it without quotation marks will call the v4.3 ffmpeg.
Also from V4.3 log, it suggests Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'libx264'.
but in the end
[wav @ 0x55eaef48b240] After avformat_find_stream_info() pos: 204878 bytes read:294990 seeks:1 frames:50
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, wav, from '/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav':
Metadata:
encoder : Lavf58.45.100
Duration: 00:00:11.44, bitrate: 1536 kb/s
Stream #1:0, 50, 1/48000: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
Successfully opened the file.
Parsing a group of options: output url /data/share/VFHQ/data/download_youtube/_-91nXXjrVo_out.mp4.
Applying option c:v (codec name) with argument libx264.
Applying option pix_fmt (set pixel format) with argument yuv420p.
Successfully parsed a group of options.
Opening an output file: /data/share/VFHQ/data/download_youtube/_-91nXXjrVo_out.mp4.
Unknown encoder 'libx264'
[AVIOContext @ 0x55eaef487fc0] Statistics: 294990 bytes read, 1 seeks
答案1
得分: 1
subprocess.run(['ffmpeg', '-framerate', '25', '-pattern_type', 'glob',
'-i','/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png',
'-i','/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav','-c:v','libx264','-pix_fmt','yuv420p',
'/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_out.mp4'])
英文:
You don't have to add another level of quotes around the pathname, since it's not being processed by the shell.
subprocess.run(['ffmpeg', '-framerate', '25','-pattern_type', 'glob',
'-i','/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png',
'-i','/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav','-c:v','libx264','-pix_fmt','yuv420p',
'/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_out.mp4'])
答案2
得分: 0
感谢每个人的贡献。
为了找到问题,我们在ffmpeg
参数中加入了-report
以获取详细日志。这样做可以让我发现我的系统中有2个版本的ffmpeg
。
为了解决问题,在运行时,请运行whereis ffmpeg
来定位这2个版本的ffmpeg
,然后在运行时添加ffmpeg
的绝对目录。例如:/usr/bin/ffmpeg -i xxxxxx
有一个现象,即在Python中调用的ffmpeg
版本不固定。换句话说,如果我不在命令中引用目录(对于subprocess
或os.system()
也不需要),则调用v3.2
,如果我使用引号,则调用v4.4.2
。这个问题尚不清楚。
英文:
Thanks for everyone's contribution.
To locate the problem, we place -report
in the ffmpeg
argument for a detailed log. Doing this allows me to find out that there are 2 versions of ffmpeg
in my system.
To solve the problem, run whereis ffmpeg
to locate the 2 versions of ffmpeg
then add the absolute directory of the ffmpeg
when running it. For instance /usr/bin/ffmpeg -i xxxxxx
There is a phenomenon where the version of ffmpeg
called in Python is not fixed. In other words, the v3.2
is called if I do not quote the directory in the command (which is also not needed for subprocess
or os.system()
) and 'v4.4.2` will be called if I place quotation marks. This problem is unknown.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论