在 mlt XML 和 C 接口以及 'hold' 生产者和 avformat 消费者中呈现不一致

Inconsistant rendering in mlt XML and C interface and 'hold' producer and avformat consumer

我正在尝试制作只有一张图片的短视频。 (我知道这有点傻,但这是对更大事物的考验)。

我用来渲染它的代码是:

#include <framework/mlt.h>
#include <stdlib.h>
#include <unistd.h>

int main() {
  if(mlt_factory_init(NULL)) {
    mlt_profile p = mlt_profile_init(NULL);
    mlt_consumer target = mlt_factory_consumer(p, "avformat", 
    mlt_producer source = mlt_factory_producer(p, "hold", "/Users/leif/logo.png");
    mlt_producer_set_in_and_out(source, 0, 10);
    mlt_consumer_connect(target, mlt_producer_service(source));
    mlt_consumer_start(target);

    sleep(5);
    mlt_consumer_stop(target);

    mlt_consumer_close(target);
    mlt_producer_close(source);
    mlt_factory_close();
  } else {
    printf("No\n");
  }

  return 0;
}

其中 logo.pngthis file

当我运行这个代码并播放output.mp4时,图片出来都是乱码。中间有一条绿线,logo自己叠加了很多

另一方面,如果我将消费者更改为 SDL,则图像可以正常播放。

最后,如果我将消费者更改为 XML,然后使用 melt 命令行应用程序渲染它:

melt -consumer avformat:xmlout.mp4 output.xml

播放视频,也很好。

我应该设置的 avformat 消费者中缺少什么吗?或者我在这里缺少的其他内容?

编辑:作为参考,输出的 xml 文件:output.xml 是:

<?xml version="1.0" encoding="utf-8"?>
<mlt LC_NUMERIC="en_US.UTF-8" version="6.2.0" root="/Users/leif/src/video/private" title="Anonymous Submission" parent="producer0" in="0" out="10">
      <profile description="DV/DVD PAL" width="720" height="576" progressive="0" sample_aspect_num="16" sample_aspect_den="15" display_aspect_num="4" display_aspect_den="3" frame_rate_num="25" frame_rate_den="1" colorspace="601"/>
  <producer id="producer0" title="Anonymous Submission" in="0" out="10">
    <property name="length">15000</property>
    <property name="eof">pause</property>
    <property name="resource">/Users/leif/logo.png</property>
    <property name="aspect_ratio">1.06667</property>
    <property name="frame">0</property>
    <property name="method">onefield</property>
    <property name="mlt_service">hold</property>
    <property name="global_feed">1</property>
  </producer>
</mlt>

来自相关bug report:

mlt_factory_profile() 实际上有点棘手和不清楚,因为框架本身并不强制生产者和消费者之间的协议。有一个名为 "loader" 的 MLT 超级生产者,它添加了一堆规范化过滤器以促进协议。当您将服务参数指定为 mlt_factory_producer() 时,您将绕过此生产者。您在上面的链接代码中看到对 MLT_PRODUCER 的引用,它具有在该文件前面定义的默认值 "loader"。

所以,真的,要让事情顺利进行,你应该说 mlt_factory_producer(p, NULL, "hold:/Users/leif/logo.png");

至于 XML,看看 producer_xml.c 是如何做到的。