- Mlt::Profile prof((char*) KdenliveSettings::current_profile().toUtf8().data());
- Mlt::Producer producer(prof, m_url.path().toUtf8().data());
- if (!producer.is_valid()) {
- kDebug() << "++++++++ INVALID CLIP: " << m_url.path();
- return;
- }
- if (!m_audioThumbFile.open(QIODevice::WriteOnly)) {
- kDebug() << "++++++++ ERROR WRITING TO FILE: " << m_audioThumbFile.fileName();
- kDebug() << "++++++++ DISABLING AUDIO THUMBS";
- KdenliveSettings::setAudiothumbnails(false);
- return;
- }
-
- if (KdenliveSettings::normaliseaudiothumbs()) {
- Mlt::Filter m_convert(prof, "volume");
- m_convert.set("gain", "normalise");
- producer.attach(m_convert);
- }
-
- int last_val = 0;
- int val = 0;
- //kDebug() << "for " << m_frame << " " << m_frameLength << " " << m_producer.is_valid();
- for (int z = (int) m_frame; z < (int)(m_frame + m_frameLength) && producer.is_valid(); z++) {
- if (m_stopAudioThumbs) break;
- val = (int)((z - m_frame) / (m_frame + m_frameLength) * 100.0);
- if (last_val != val && val > 1) {
- m_clipManager->setThumbsProgress(i18n("Creating thumbnail for %1", m_url.fileName()), val);
- last_val = val;
- }
- producer.seek(z);
- Mlt::Frame *mlt_frame = producer.get_frame();
- if (mlt_frame && mlt_frame->is_valid()) {
- double m_framesPerSecond = mlt_producer_get_fps(producer.get_producer());
- int m_samples = mlt_sample_calculator(m_framesPerSecond, m_frequency, mlt_frame_get_position(mlt_frame->get_frame()));
- mlt_audio_format m_audioFormat = mlt_audio_pcm;
- qint16* m_pcm = static_cast<qint16*>(mlt_frame->get_audio(m_audioFormat, m_frequency, m_channels, m_samples));
-
- for (int c = 0; c < m_channels; c++) {
- QByteArray m_array;
- m_array.resize(m_arrayWidth);
- for (int i = 0; i < m_array.size(); i++) {
- m_array[i] = ((*(m_pcm + c + i * m_samples / m_array.size())) >> 9) + 127 / 2 ;
- }
- m_audioThumbFile.write(m_array);
-
- }
- } else {
- m_audioThumbFile.write(QByteArray(m_arrayWidth, '\x00'));
- }
- delete mlt_frame;
- }
- m_audioThumbFile.close();
- if (m_stopAudioThumbs) {
- m_audioThumbFile.remove();
- } else {
- slotAudioThumbOver();
- }
-}
-
-void KThumb::slotAudioThumbOver()
-{
- m_clipManager->setThumbsProgress(i18n("Creating thumbnail for %1", m_url.fileName()), -1);
- m_clipManager->endAudioThumbsGeneration(m_id);
-}
-
-void KThumb::askForAudioThumbs(const QString &id)
-{
- m_clipManager->askForAudioThumb(id);