mencoder生成空的.avi文件

1 投票
1 回答
1590 浏览
提问于 2025-04-17 04:32

我在一个Python脚本里调用mencoder,想把几个.png文件合成一部电影:

import sys, os
command =   ''.join([
            'mplayer\mencoder.exe ',
            'mf://frames/out_*.png ',
            '-mf type=png:w=800:h=600:fps=10 -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o out.avi '
            ])
print "executing", command
os.system(command)

但是mencoder给我生成了一个4KB的out.avi文件,输出内容是:

    C:\Windows\system32\cmd.exe /c python make_video.py
    executing mplayer\mencoder.exe mf://frames/out_*.png -mf type=png:w=800:h=600:fps=10 -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o out.avi
    MEncoder Sherpya-SVN-r34118-4.2.5 (C) 2000-2011 MPlayer Team
    success: format: 16  data: 0x0 - 0x0
    MF file format detected.
    [mf] search expr: frames/out_*.png
    [mf] number of files: 129 (516)
    VIDEO:  [MPNG]  800x600  24bpp  10.000 fps    0.0 kbps ( 0.0 kbyte/s)
    [V] filefmt:16  fourcc:0x474E504D  size:800x600  fps:10.000  ftime:=0.1000
    Opening video filter: [expand osd=1]
    Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
    ==========================================================================
    Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
    Selected video codec: [ffpng] vfm: ffmpeg (FFmpeg PNG)
    ==========================================================================

    Flushing video frames.
    Filters have not been configured! Empty file?
    Writing index...
    Writing header...
    ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.

    Video stream:      nan kbit/s  (-2147483648 B/s)  size: 0 bytes  0.000 secs  0 frames

请帮帮我。

1 个回答

4

我想这可能是个老话题,但我也遇到了同样的问题,所以想分享我的解决办法,以防有人也碰到这个问题。

其实这个错误是因为你在源文件夹之外运行mencoder命令导致的。要解决这个问题,只需进入存放源图片的文件夹,然后在那儿运行命令就可以了。

或者,你也可以修改你的Python脚本,在运行mencoder之前加一行代码,把当前路径改成你的源图片路径。可以这样写: os.chdir(sourcefolder) # 这里的sourcefolder是你源图片的存放位置

祝好! -Kevin

撰写回答