justburner 64e039
#include <memory></memory>
justburner 64e039
justburner 64e039
#include "tmachine.h"
justburner 64e039
#include "tsio_ffmpeg.h"
justburner 64e039
#include "tsystem.h"
justburner 64e039
#include "tfilepath_io.h"
justburner 64e039
#include "tsound_t.h"
justburner 64e039
#include "toonz/preferences.h"
justburner 64e039
#include "toonz/toonzfolders.h"
justburner 64e039
#include "thirdparty.h"
justburner 64e039
justburner 64e039
#include <qdir></qdir>
justburner 64e039
#include <qprocess></qprocess>
justburner 64e039
justburner 64e039
//==============================================================================
justburner 64e039
justburner 64e039
TSoundTrackReaderFFmpeg::TSoundTrackReaderFFmpeg(const TFilePath &fp)
justburner 64e039
    : TSoundTrackReader(fp) {}
justburner 64e039
justburner 64e039
//------------------------------------------------------------------------------
justburner 64e039
justburner 64e039
TSoundTrackP TSoundTrackReaderFFmpeg::load() {
justburner 64e039
  QProcess ffmpeg;
justburner 64e039
  QByteArray rawAudio;
justburner 64e039
justburner 64e039
  // Pipe the audio through ffmpeg
justburner 64e039
  ThirdParty::runFFmpegAudio(ffmpeg, m_path.getQString(), "-");
justburner 64e039
  if (!ThirdParty::readFFmpegAudio(ffmpeg, rawAudio)) return nullptr;
justburner 64e039
justburner 64e039
  long sampleCount = rawAudio.size() / 4;
justburner 64e039
justburner 64e039
  TSoundTrack *track = new TSoundTrackStereo16(44100, 2, sampleCount);
justburner 64e039
  memcpy((char *)track->getRawData(), rawAudio.constData(), sampleCount * 4);
justburner 64e039
  return track;
justburner 64e039
}