我正在评估使用MLT框架处理和连接一些视频。我需要将它与一个32位C#应用程序集成,并将一些动态的定制覆盖应用于基于C#数据结构的数据,因此我计划通过P/Invoke构建C并在C#中使用它。
我用SDL、libavcodec和dlfcn 32构建了一个简约的库配置,所有其他模块都在https://www.mltframework.org/docs/windowsbuild/之后禁用。但是,我的32位构建在使用C或C++ API时不能正常工作。在使用SDL时,我会得到分段错误、创建虚拟输出视频或挂起。创建的melt.exe和示例项目play.cpp也有相同的问题。
这让我觉得32位构建可能有问题,所以我也尝试了64位构建,也有类似的结果。之后,我尝试了以下配置和编译器:
最后一个没有起作用的事实令我惊讶,让我觉得我的环境一定有问题,或者我正在做的事情。我按照那些指示写了信。此外,构建的Shotcut.exe在启动时也会崩溃。在所有这些情况下,构建都成功了,但是构建的二进制文件没有像预期的那样工作。
有没有人得到MLT的C API来正确地工作在Windows 32位上的视频编码?
这是我的小测试项目,改编自https://www.mltframework.org/docs/framework/。
(我编辑了这个代码示例,以反映Sergey的回答中的一些关注,但最终结果没有改变)。
#include <windows.h>
#include <stdio.h>
#include "include/mlt/framework/mlt.h"
int main()
{
mlt_repository repo = mlt_factory_init(NULL);
fprintf(stderr, "start\n");
if (repo != NULL)
{
mlt_consumer consumer = mlt_factory_consumer(NULL, "sdl", NULL);
fprintf(stderr, "Creating consumer %p\n", consumer);
if (consumer == NULL)
{
fprintf(stderr, "Consumer NULL. Aborting");
return 1;
}
mlt_producer producer = mlt_factory_producer(NULL, "color", "red");
fprintf(stderr, "Creating producer %p\n", producer);
if (producer == NULL)
{
fprintf(stderr, "Producer NULL. Aborting");
return 1;
}
fprintf(stderr, "Connecting %p to %p\n", producer, consumer);
mlt_consumer_connect(consumer, mlt_producer_service(producer));
fprintf(stderr, "Starting consumer %p\n", consumer);
mlt_consumer_start(consumer);
fprintf(stderr, "Wait for consumer\n");
while (!mlt_consumer_is_stopped(consumer))
{
Sleep(1000);
fprintf(stderr, "Wait more for consumer...\n");
}
fprintf(stderr, "Close consumer\n");
// Close the consumer
mlt_consumer_close(consumer);
fprintf(stderr, "Close producer\n");
// Close the producer
mlt_producer_close(producer);
fprintf(stderr, "Close factory\n");
// Close the factory
mlt_factory_close();
}
else
{
// Report an error during initialisation
fprintf(stderr, "Unable to locate factory modules\n");
}
return 0;
}发布于 2017-07-28 08:22:36
我已经解决了这个问题。有一个错误,在Windows上,当没有传入时,不会创建默认的mlt_profile。
因此,显式地创建一个并将其传递给工厂调用:
mlt_profile profile = mlt_profile_init(NULL);
这解决了我在Windows上使用C API的问题。不,SDL由于某种原因仍然不起作用。但这没那么重要。
发布于 2017-07-21 17:17:29
来自MLT文件:
mlt_consumer mlt_factory_consumer (mlt_profile,const char *,const mlt_factory_consumer *) 从存储库中获取使用者
您没有检查mlt_factory_consumer返回的值,而是NULL。
mlt_consumer hello = mlt_factory_consumer(NULL, "color", "red");
printf("Created consumer %p\n", hello);
mlt_producer world = mlt_factory_producer(NULL, NULL, NULL);
printf("Created producer %p\n", world);
mlt_service service = mlt_producer_service (world);
printf("Created service %p\n", service);> gcc test.c -lmlt -g && ./a.outCreated consumer (nil)
Created producer (nil)
Created service (nil)
Segmentation fault (core dumped)然而,当给定默认参数时,它返回一个有效指针:
mlt_consumer hello = mlt_factory_consumer(NULL, NULL, NULL);
printf("Created consumer %p\n", hello);
printf("Loop over parent %p\n", hello -> parent . child);
. . .> gcc test.c -lmlt -g && ./a.outCreated consumer 0x561978461cf0
Loop over parent 0x561978461cf0
Created producer (nil)
Created service (nil)
Connected 0
Starting consumer 0
Wait for consumer
Wait more for consumer...
Wait more for consumer...
CTRL-C
Close consumer
Close producer
Close factory

从您提供的链接中:
默认的使用者是
sdl。还请注意,您可以按以下方式覆盖默认值:MLT_CONSUMER=xml ./hello file.avi将在stdout上创建一个XML文档。MLT_CONSUMER=xml MLT_PRODUCER=avformat ./hello file.avi将直接使用avformat生产者播放视频,因此它将绕过规范化功能。 如果幸运的话,MLT_CONSUMER=libdv ./hello file.avi > /dev/dv1394可能会实时地将file.avi转换成DV,并将其广播到DV设备上。
很明显,您必须为mlt_factory_consumer提供一个有效的参数或NULL (如果愿意,可以重写默认的使用者):
mlt_consumer hello = mlt_factory_consumer(NULL, "xml", NULL);
printf("Created consumer %p\n", hello);
. . .> gcc test.c -lmlt -g && ./a.outCreated consumer 0x55ab3ceb7660
Loop over parent 0x55ab3ceb7660
Created producer (nil)
Created service (nil)
Connected 0
Starting consumer 0
Wait for consumer
Close consumer
Close producer
Close factoryhttps://stackoverflow.com/questions/45241525
复制相似问题