diff --git a/api/routes/photos.go b/api/routes/photos.go
index b14a9a7..b1b91e1 100644
--- a/api/routes/photos.go
+++ b/api/routes/photos.go
@@ -45,21 +45,16 @@ func RegisterPhotoRoutes(db *gorm.DB, router *mux.Router) {
 		}
 
 		if _, err := os.Stat(cachedPath); os.IsNotExist((err)) {
-			err := db.Transaction(func(tx *gorm.DB) error {
-				if err = scanner.ProcessSingleMedia(tx, media); err != nil {
-					log.Printf("ERROR: processing image not found in cache (%s): %s\n", cachedPath, err)
-					return err
-				}
+			// err := db.Transaction(func(tx *gorm.DB) error {
+			if err = scanner.ProcessSingleMedia(db, media); err != nil {
+				log.Printf("ERROR: processing image not found in cache (%s): %s\n", cachedPath, err)
+				w.WriteHeader(http.StatusInternalServerError)
+				w.Write([]byte("internal server error"))
+				return
+			}
 
-				if _, err = os.Stat(cachedPath); err != nil {
-					log.Printf("ERROR: after reprocessing image not found in cache (%s): %s\n", cachedPath, err)
-					return err
-				}
-
-				return nil
-			})
-
-			if err != nil {
+			if _, err = os.Stat(cachedPath); err != nil {
+				log.Printf("ERROR: after reprocessing image not found in cache (%s): %s\n", cachedPath, err)
 				w.WriteHeader(http.StatusInternalServerError)
 				w.Write([]byte("internal server error"))
 				return
diff --git a/api/routes/videos.go b/api/routes/videos.go
index dd1d502..2717eee 100644
--- a/api/routes/videos.go
+++ b/api/routes/videos.go
@@ -51,22 +51,15 @@ func RegisterVideoRoutes(db *gorm.DB, router *mux.Router) {
 
 		if _, err := os.Stat(cachedPath); err != nil {
 			if os.IsNotExist(err) {
-				err := db.Transaction(func(tx *gorm.DB) error {
-					if err := scanner.ProcessSingleMedia(tx, media); err != nil {
-						log.Printf("ERROR: processing video not found in cache: %s\n", err)
-						return err
-					}
+				if err := scanner.ProcessSingleMedia(db, media); err != nil {
+					log.Printf("ERROR: processing video not found in cache: %s\n", err)
+					w.WriteHeader(http.StatusInternalServerError)
+					w.Write([]byte("internal server error"))
+					return
+				}
 
-					if _, err := os.Stat(cachedPath); err != nil {
-						log.Printf("ERROR: after reprocessing video not found in cache: %s\n", err)
-						return err
-					}
-
-					return nil
-				})
-
-				if err != nil {
-					log.Printf("ERROR: %s\n", err)
+				if _, err := os.Stat(cachedPath); err != nil {
+					log.Printf("ERROR: after reprocessing video not found in cache: %s\n", err)
 					w.WriteHeader(http.StatusInternalServerError)
 					w.Write([]byte("internal server error"))
 					return
diff --git a/api/scanner/media_scan.go b/api/scanner/media_scan.go
new file mode 100644
index 0000000..2fccb62
--- /dev/null
+++ b/api/scanner/media_scan.go
@@ -0,0 +1,40 @@
+package scanner
+
+import (
+	"github.com/photoview/photoview/api/graphql/models"
+	"github.com/photoview/photoview/api/scanner/media_encoding"
+	"github.com/photoview/photoview/api/scanner/scanner_task"
+	"github.com/photoview/photoview/api/scanner/scanner_tasks"
+	"github.com/pkg/errors"
+)
+
+func scanMedia(ctx scanner_task.TaskContext, media *models.Media, mediaData *media_encoding.EncodeMediaData, mediaIndex int, mediaTotal int) error {
+	newCtx, err := scanner_tasks.Tasks.BeforeProcessMedia(ctx, mediaData)
+	if err != nil {
+		return errors.Wrapf(err, "before process media (%s)", media.Path)
+	}
+
+	mediaCachePath, err := media.CachePath()
+	if err != nil {
+		return errors.Wrapf(err, "cache directory error (%s)", media.Path)
+	}
+
+	transactionError := newCtx.DatabaseTransaction(func(ctx scanner_task.TaskContext) error {
+		updatedURLs, err := scanner_tasks.Tasks.ProcessMedia(newCtx, mediaData, mediaCachePath)
+		if err != nil {
+			return errors.Wrapf(err, "process media (%s)", media.Path)
+		}
+
+		if err = scanner_tasks.Tasks.AfterProcessMedia(newCtx, mediaData, updatedURLs, mediaIndex, mediaTotal); err != nil {
+			return errors.Wrap(err, "after process media")
+		}
+
+		return nil
+	})
+
+	if transactionError != nil {
+		return errors.Wrap(transactionError, "process media database transaction")
+	}
+
+	return nil
+}
diff --git a/api/scanner/scanner_album.go b/api/scanner/scanner_album.go
index f6abc42..53aec9b 100644
--- a/api/scanner/scanner_album.go
+++ b/api/scanner/scanner_album.go
@@ -86,7 +86,6 @@ func ValidRootPath(rootPath string) bool {
 }
 
 func ScanAlbum(ctx scanner_task.TaskContext) error {
-
 	newCtx, err := scanner_tasks.Tasks.BeforeScanAlbum(ctx)
 	if err != nil {
 		return errors.Wrapf(err, "before scan album (%s)", ctx.GetAlbum().Path)
@@ -101,35 +100,10 @@ func ScanAlbum(ctx scanner_task.TaskContext) error {
 
 	changedMedia := make([]*models.Media, 0)
 	for i, media := range albumMedia {
-		updatedURLs := []*models.MediaURL{}
-
 		mediaData := media_encoding.NewEncodeMediaData(media)
 
-		// define new ctx for scope of for-loop
-		ctx, err := scanner_tasks.Tasks.BeforeProcessMedia(ctx, &mediaData)
-		if err != nil {
-			return err
-		}
-
-		transactionError := ctx.DatabaseTransaction(func(ctx scanner_task.TaskContext) error {
-			updatedURLs, err = processMedia(ctx, &mediaData)
-			if err != nil {
-				return errors.Wrapf(err, "process media (%s)", media.Path)
-			}
-
-			if len(updatedURLs) > 0 {
-				changedMedia = append(changedMedia, media)
-			}
-
-			return nil
-		})
-
-		if transactionError != nil {
-			return errors.Wrap(err, "process media database transaction")
-		}
-
-		if err = scanner_tasks.Tasks.AfterProcessMedia(ctx, &mediaData, updatedURLs, i, len(albumMedia)); err != nil {
-			return errors.Wrap(err, "after process media")
+		if err := scanMedia(ctx, media, &mediaData, i, len(albumMedia)); err != nil {
+			return errors.Wrap(err, "album scan")
 		}
 	}
 
diff --git a/api/scanner/scanner_media.go b/api/scanner/scanner_media.go
index eaefb02..5abb45c 100644
--- a/api/scanner/scanner_media.go
+++ b/api/scanner/scanner_media.go
@@ -10,7 +10,6 @@ import (
 	"github.com/photoview/photoview/api/scanner/media_encoding"
 	"github.com/photoview/photoview/api/scanner/scanner_cache"
 	"github.com/photoview/photoview/api/scanner/scanner_task"
-	"github.com/photoview/photoview/api/scanner/scanner_tasks"
 	"github.com/pkg/errors"
 	"gorm.io/gorm"
 )
@@ -82,24 +81,8 @@ func ProcessSingleMedia(db *gorm.DB, media *models.Media) error {
 	media_data := media_encoding.NewEncodeMediaData(media)
 
 	task_context := scanner_task.NewTaskContext(context.Background(), db, &album, album_cache)
-	new_ctx, err := scanner_tasks.Tasks.BeforeProcessMedia(task_context, &media_data)
-	if err != nil {
-		return err
-	}
-
-	mediaCachePath, err := media.CachePath()
-	if err != nil {
-		return err
-	}
-
-	updated_urls, err := scanner_tasks.Tasks.ProcessMedia(new_ctx, &media_data, mediaCachePath)
-	if err != nil {
-		return err
-	}
-
-	err = scanner_tasks.Tasks.AfterProcessMedia(new_ctx, &media_data, updated_urls, 0, 1)
-	if err != nil {
-		return err
+	if err := scanMedia(task_context, media, &media_data, 0, 1); err != nil {
+		return errors.Wrap(err, "single media scan")
 	}
 
 	return nil
