+void Render::getFileProperties(const QDomElement &xml, int clipId) {
+ int height = 50;
+ int width = (int)(height * m_mltProfile->dar());
+ QMap < QString, QString > filePropertyMap;
+ QMap < QString, QString > metadataPropertyMap;
+
+ QDomDocument doc;
+ QDomElement westley = doc.createElement("westley");
+ QDomElement play = doc.createElement("playlist");
+ doc.appendChild(westley);
+ westley.appendChild(play);
+ play.appendChild(doc.importNode(xml, true));
+ char *tmp = decodedString(doc.toString());
+ Mlt::Producer producer(*m_mltProfile, "westley-xml", tmp);
+ delete[] tmp;
+
+ if (producer.is_blank()) {
+ return;
+ }
+
+ int frameNumber = xml.attribute("frame_thumbnail", "0").toInt();
+ if (frameNumber != 0) producer.seek(frameNumber);
+ mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer.get_producer());
+
+ KUrl url = xml.attribute("resource", QString::null);
+ filePropertyMap["filename"] = url.path();
+ filePropertyMap["duration"] = QString::number(producer.get_playtime());
+ //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
+
+ Mlt::Frame * frame = producer.get_frame();
+ filePropertyMap["fps"] = producer.get("source_fps");
+
+ if (frame && frame->is_valid()) {
+ filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + "x" + QString::number(frame->get_int("height"));
+ filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
+ filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
+ filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
+
+ if (frame->get_int("test_image") == 0) {
+ if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
+ filePropertyMap["type"] = "playlist";
+ metadataPropertyMap["comment"] = QString::fromUtf8(mlt_properties_get(MLT_SERVICE_PROPERTIES(producer.get_service()), "title"));
+ } else if (frame->get_int("test_audio") == 0)
+ filePropertyMap["type"] = "av";
+ else
+ filePropertyMap["type"] = "video";
+
+ mlt_image_format format = mlt_image_yuv422;
+ int frame_width = 0;
+ int frame_height = 0;
+ //frame->set("rescale.interp", "hyper");
+ frame->set("normalised_height", height);
+ frame->set("normalised_width", width);
+ QPixmap pix(width, height);
+
+ uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
+ uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
+ mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
+ QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
+
+ if (!image.isNull()) {
+ pix = pix.fromImage(image.rgbSwapped());
+ } else
+ pix.fill(Qt::black);
+
+ mlt_pool_release(new_image);
+ emit replyGetImage(clipId, 0, pix, width, height);
+
+ } else if (frame->get_int("test_audio") == 0) {
+ QPixmap pixmap(KStandardDirs::locate("appdata", "graphics/music.png"));
+ emit replyGetImage(clipId, 0, pixmap, width, height);
+ filePropertyMap["type"] = "audio";
+ }
+ }
+
+ // Retrieve audio / video codec name
+
+ // Fetch the video_context
+#if 1
+ AVFormatContext *context = (AVFormatContext *) mlt_properties_get_data(properties, "video_context", NULL);
+ if (context != NULL) {
+ // Get the video_index
+ int index = mlt_properties_get_int(properties, "video_index");
+
+#if ENABLE_FFMPEG_CODEC_DESCRIPTION
+ if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name)
+ filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->long_name;
+ else
+#endif
+ if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name)
+ filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->name;
+ }
+ context = (AVFormatContext *) mlt_properties_get_data(properties, "audio_context", NULL);
+ if (context != NULL) {
+ // Get the video_index
+ int index = mlt_properties_get_int(properties, "audio_index");
+
+#if ENABLE_FFMPEG_CODEC_DESCRIPTION
+ if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name)
+ filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->long_name;
+ else
+#endif
+ if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name)
+ filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->name;
+ }
+#endif
+ // metadata
+
+ mlt_properties metadata = mlt_properties_new();
+ mlt_properties_pass(metadata, properties, "meta.attr.");
+ int count = mlt_properties_count(metadata);
+ for (int i = 0; i < count; i ++) {
+ QString name = mlt_properties_get_name(metadata, i);
+ QString value = QString::fromUtf8(mlt_properties_get_value(metadata, i));
+ if (name.endsWith("markup") && !value.isEmpty())
+ metadataPropertyMap[ name.section(".", 0, -2)] = value;
+ }
+
+ emit replyGetFileProperties(clipId, filePropertyMap, metadataPropertyMap);
+ kDebug() << "REquested fuile info for: " << url.path();
+ if (frame) delete frame;