1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
| #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include "mlt.h" #include "mlt_log.h"
int main(int argc, char *argv[]) { if (argc < 3) { fprintf(stderr, "Usage: %s input.mp4 output.mp4\n", argv[0]); return 1; } const char *input_path = argv[1]; const char *output_path = argv[2]; const char* plugin_dir = getenv("MLT_REPOSITORY"); if (!plugin_dir) { plugin_dir = "/home/cmder/mlttest/lib/mlt"; } if (!mlt_factory_init(plugin_dir)) { fprintf(stderr, "Failed to init MLT factory (tried: %s)\n", plugin_dir); return 1; } mlt_log_set_level(MLT_LOG_WARNING); printf("MLT factory initialized, plugin directory: %s\n", plugin_dir); mlt_profile profile = mlt_profile_init(NULL); if (!profile) { fprintf(stderr, "Failed to create profile\n"); mlt_factory_close(); return 1; } mlt_producer producer = mlt_factory_producer(profile, "avformat", input_path); if (!producer) { printf("Failed with 'avformat', trying auto-detect...\n"); producer = mlt_factory_producer(profile, NULL, input_path); } if (!producer) { fprintf(stderr, "Failed to create producer for %s\n", input_path); fprintf(stderr, "Please check:\n"); fprintf(stderr, " 1. File exists and is readable\n"); fprintf(stderr, " 2. MLT avformat plugin is loaded (libmltavformat.so)\n"); fprintf(stderr, " 3. File format is supported by FFmpeg\n"); mlt_profile_close(profile); mlt_factory_close(); return 1; } printf("Producer created successfully\n"); mlt_profile_from_producer(profile, producer);
mlt_filter brightness = mlt_factory_filter(profile, "brightness", NULL); if (!brightness) { fprintf(stderr, "Failed to create brightness filter\n"); mlt_producer_close(producer); mlt_profile_close(profile); mlt_factory_close(); return 1; } mlt_properties bprops = MLT_FILTER_PROPERTIES(brightness); mlt_properties_set_double(bprops, "level", 1.5); if (mlt_producer_attach(producer, brightness) != 0) { fprintf(stderr, "Failed to attach brightness filter\n"); mlt_filter_close(brightness); mlt_producer_close(producer); mlt_profile_close(profile); mlt_factory_close(); return 1; } mlt_consumer consumer = mlt_factory_consumer(profile, "avformat", output_path); if (!consumer) { fprintf(stderr, "Failed to create avformat consumer for %s\n", output_path); mlt_filter_close(brightness); mlt_producer_close(producer); mlt_profile_close(profile); mlt_factory_close(); return 1; } mlt_properties cprops = MLT_CONSUMER_PROPERTIES(consumer);
mlt_properties_set(cprops, "vcodec", "libx264"); mlt_properties_set_int(cprops, "bitrate", 4000000); char fps_str[64]; snprintf(fps_str, sizeof(fps_str), "%.3f", mlt_profile_fps(profile)); mlt_properties_set(cprops, "frame_rate", fps_str);
mlt_properties_set(cprops, "real_time", "0"); mlt_properties_set_int(cprops, "overwrite", 1); mlt_consumer_connect(consumer, MLT_PRODUCER_SERVICE(producer)); if (mlt_consumer_start(consumer) != 0) { fprintf(stderr, "Failed to start consumer\n"); mlt_consumer_close(consumer); mlt_filter_close(brightness); mlt_producer_close(producer); mlt_profile_close(profile); mlt_factory_close(); return 1; } while (!mlt_consumer_is_stopped(consumer)) { sleep(1); } mlt_consumer_close(consumer); mlt_producer_close(producer); mlt_profile_close(profile); mlt_factory_close(); printf("Done. Wrote output to %s\n", output_path); return 0; }
|