执行使用Python执行ffmpeg命令来定位*.png文件失败。

huangapple go评论74阅读模式
英文:

Excuting ffmpeg commands using Python to locate *.png failed

问题

以下是翻译的部分:

  1. 当您在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
    
  2. 但是,如果您尝试在Python中使用os.system()运行它时,您会遇到Unknown encoder 'libx264'错误。

  3. 如果移除命令中的引号,如下所示:

    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错误。

  4. 使用subprocess.run(command, shell=True) 时,结果与上述情况相同。

  5. 如果您尝试在没有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
    
  6. 同样,去掉图片目录中的引号会导致Unknown encoder 'libx264'错误。

  7. 当您在图片目录周围使用引号运行命令时,也会遇到'/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png': No such file or directory错误。

  8. 后来发现您有两个版本的ffmpeg,一个是4.3,另一个是4.4.2。使用引号运行子进程会调用4.4.2版本,而不使用引号会调用4.3版本。

  9. 从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版本不固定。换句话说,如果我不在命令中引用目录(对于subprocessos.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.

huangapple
  • 本文由 发表于 2023年5月18日 04:40:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76276053.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定