diff --git a/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp b/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp
index 9ed05df..5efecea 100644
--- a/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp
+++ b/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp
@@ -101,9 +101,11 @@ void Ffmpeg::setPath(TFilePath path) { m_path = path; }
 
 void Ffmpeg::createIntermediateImage(const TImageP &img, int frameIndex) {
   m_frameCount++;
+  if (m_frameNumberOffset == -1) m_frameNumberOffset = frameIndex - 1;
   QString tempPath = getFfmpegCache().getQString() + "//" +
                      QString::fromStdString(m_path.getName()) + "tempOut" +
-                     QString::number(m_frameCount) + "." + m_intermediateFormat;
+                     QString::number(frameIndex - m_frameNumberOffset) + "." +
+                     m_intermediateFormat;
   std::string saveStatus = "";
   TRasterImageP tempImage(img);
   TRasterImage *image = (TRasterImage *)tempImage->cloneImage();
diff --git a/toonz/sources/image/ffmpeg/tiio_ffmpeg.h b/toonz/sources/image/ffmpeg/tiio_ffmpeg.h
index 1ab3986..88747db 100644
--- a/toonz/sources/image/ffmpeg/tiio_ffmpeg.h
+++ b/toonz/sources/image/ffmpeg/tiio_ffmpeg.h
@@ -46,7 +46,7 @@ public:
 private:
   QString m_intermediateFormat, m_ffmpegPath, m_audioPath, m_audioFormat;
   int m_frameCount    = 0, m_lx, m_ly, m_bpp, m_bitsPerSample, m_channelCount,
-      m_ffmpegTimeout = 30000;
+      m_ffmpegTimeout = 30000, m_frameNumberOffset = -1;
   double m_frameRate  = 24.0;
   bool m_ffmpegExists = false, m_ffprobeExists = false, m_hasSoundTrack = false;
   TFilePath m_path;
diff --git a/toonz/sources/image/sprite/tiio_sprite.cpp b/toonz/sources/image/sprite/tiio_sprite.cpp
index f1b6d22..c52dfe6 100644
--- a/toonz/sources/image/sprite/tiio_sprite.cpp
+++ b/toonz/sources/image/sprite/tiio_sprite.cpp
@@ -194,6 +194,8 @@ void TLevelWriterSprite::saveSoundTrack(TSoundTrack *st) {}
 //-----------------------------------------------------------
 
 void TLevelWriterSprite::save(const TImageP &img, int frameIndex) {
+  m_frameIndexOrder.push_back(frameIndex);
+  std::sort(m_frameIndexOrder.begin(), m_frameIndexOrder.end());
   TRasterImageP tempImage(img);
   TRasterImage *image = (TRasterImage *)tempImage->cloneImage();
 
@@ -261,7 +263,14 @@ void TLevelWriterSprite::save(const TImageP &img, int frameIndex) {
   newQi->fill(qRgba(0, 0, 0, 0));
   QPainter painter(newQi);
   painter.drawImage(QPoint(0, 0), *qi);
-  m_images.push_back(newQi);
+
+  // Make sure to order the images according to their frame index
+  // Not just what comes out first
+  std::vector<int>::iterator it;
+  it = find(m_frameIndexOrder.begin(), m_frameIndexOrder.end(), frameIndex);
+  int pos = std::distance(m_frameIndexOrder.begin(), it);
+
+  m_images.insert(m_images.begin() + pos, newQi);
   delete image;
   delete qi;
   free(buffer);
diff --git a/toonz/sources/image/sprite/tiio_sprite.h b/toonz/sources/image/sprite/tiio_sprite.h
index 5bbd838..cd58063 100644
--- a/toonz/sources/image/sprite/tiio_sprite.h
+++ b/toonz/sources/image/sprite/tiio_sprite.h
@@ -37,6 +37,7 @@ private:
   int m_left = 0, m_right = 0, m_top = 0, m_bottom = 0;
   std::vector<QImage *> m_images;
   std::vector<QImage> m_imagesResized;
+  std::vector<int> m_frameIndexOrder;
   bool m_firstPass = true;
   bool m_trim      = true;
   QString m_format;