【问题标题】:Movie from PNGs using FFmpeg and Python - rgb24 vs yuv420p使用 FFmpeg 和 Python 从 PNG 制作电影 - rgb24 vs yuv420p
【发布时间】:2016-05-17 02:01:30
【问题描述】:

我编写了一个小 Python 程序来抓取一堆 PNG,并使用 FFmpeg 命令行将它们渲染成电影。将 PNG 读入 [X*Y*3] numpy 数组(忽略 alpha 通道),通过插值添加新帧,并将数据作为管道输入 FFmpeg 并保存为 mp4。

这些文件在 Windows 上的 VLC 中可以正常播放,但在 Mac 上的 iMovie 中无法正常播放。我认为这可能与大多数希望 H264 视频在 YUV420P 色彩空间中的程序有关,而我的电影不是。我尝试将 ffmpeg 命令 -pix_fmtrgb24 更改为 yuv420p,但不行。

下面附上相关的Python代码。

def init_vars(args):
    global log_file, file_names, command, num_int_frames, num_files, silent

    file_names = glob('./*.png')
    num_files = len(file_names)

    if args.log:
        log_file = 'bmmp.log'
    else:
        log_file = os.devnull

    silent = args.silent

    frames_per_second = args.fps
    wanted_movie_length = args.length
    movie_file_name = args.name + '.mp4'

    num_int_frames = round((frames_per_second * wanted_movie_length - 1) / (num_files - 1) - 1)

    if sys.platform == 'win32':
        ffmpeg_bin = 'ffmpeg.exe'
    else:
        ffmpeg_bin = 'ffmpeg'

    command = [ffmpeg_bin,
               '-y', # (optional) overwrite output file if it exists
               '-f', 'rawvideo',
               '-vcodec','rawvideo',
               '-s', '1280x720', # size of one frame
               '-pix_fmt', 'rgb24',
               '-r', str(frames_per_second), # frames per second
               '-i', '-', # The input comes from a pipe
               '-an', # Tells FFMPEG not to expect any audio
               movie_file_name]

干杯, 埃拉姆

【问题讨论】:

  • 这几乎不是一个 python 问题,更多的是ffmpeg 问题。尽管如此,视频不使用 YUV 色彩空间的原因是什么,毕竟这是 H.264 的调整目标
  • 这就是我最初尝试的方法,但根据下面 Mulvya 的回答,我做错了。

标签: python video ffmpeg h.264


【解决方案1】:

假设Python中参数的顺序代表构造命令的顺序,那么'-i', '-', # The input comes from a pipe后面应该插入一个'-pix_fmt', 'yuv420p',。不要删除或更改之前的 pix_fmt,因为它指定了输入属性。

【讨论】:

    猜你喜欢
    • 2017-03-12
    • 1970-01-01
    • 1970-01-01
    • 2019-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-19
    相关资源
    最近更新 更多