I'm evaluating using the MLT framework to process and concatenate some videos. I would need to integrate it with a 32 bit C# application, and also apply some dynamic, custom overlay to the data based on C# data structures, so I was planning on building the C API and using it in C# through P/Invoke.
I have managed to build a minimalistic config of the library with SDL, libavcodec, and dlfcn-win32, all other modules disabled, following https://www.mltframework.org/docs/windowsbuild/. However, my 32 bit build is not working correctly when using the C API, or the C++ API. I get segfaults, dummy output videos created, or hangs when using SDL. The created melt.exe and example project play.cpp have the same problem too.
Now this made me think maybe there is a problem with 32 bit builds, so I have tried a 64 bit build as well, with similar results. After that, I have tried the following configurations and compilers:
The fact that the last one did not work is surprising, makes me think there must be something wrong with my environment or something I'm doing. I followed those instructions to the letter. Also the built Shotcut.exe crashes on startup. In all these cases, the build did succeed but the built binaries did not work as expected.
Has anyone gotten MLT's C API to work correctly for video encoding on Windows 32 bit?
Here's my small test project, adapted from https://www.mltframework.org/docs/framework/.
(I have edited this code sample to reflect some of the concerns from Sergey's answer, but no change in the final result).
#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;
}
I have solved the issue. There is a bug where on Windows a default mlt_profile is not created when none is passed in.
So create one explicitly and pass it in to the factory calls:
mlt_profile profile = mlt_profile_init(NULL);
This fixed my issues with the C API on Windows. And no, SDL for some reason still doesn't work. But it's not that important.