public function finalize($filename, $caption)
	{
		$canEditFile = false;
		$filePath = $this->path . DIRECTORY_SEPARATOR . $filename;
		$file = null;

		if ($this->mp4EditingEnabled && strtolower(pathinfo($filename, PATHINFO_EXTENSION)) == 'mp4') {
			$file = new Mp4($filePath);
			$canEditFile = true;

			if (strtolower($this->captionFormat) == 'sub')
				$this->defaultFPS = $file->getFPS();
		}

		if ($caption !== false && count($this->videoInfo->captions))
			$this->downloadCaption($this->videoInfo->captions, $caption, $filename);

		if ($canEditFile) {
			try {
				$response = $this->webClient->get($this->videoInfo->image['medium_quality']);
				if ($response->getStatusCode() == 200)
					$file->setCover($response->getBody());
			} catch (\Exception $e) {}

			$file->setTrackName($this->videoInfo->title);
			$file->setArtist($this->videoInfo->author);

			$videosCount = $this->isPlaylist ? count($this->playlistInfo->video) : 1;
			if ($videosCount > 1)
				$file->setTrackNumber($this->currentDownloadingVideoIndex, $videosCount);

			$file->setSoftwareInformation('Downloaded by YoutubeDownloader https://is.gd/Youtubedownloader');
			$file->setMediaType(MediaTypes::Movie);

			$tempFilePath = $filePath . time();
			copy($filePath, $tempFilePath); // Make backup of video in case something goes wrong

			try {
				$file->save();
				unlink($tempFilePath);
			} catch (\Zend_Media_Iso14496_Exception $e) {
				$file = null;
				rename($tempFilePath, $filePath); // Restore backup file in case of error
			}

			if ($file && $this->autoCloseEditedMp4Files) {
				$file->__destruct();
				$file = null;
			}
		}

		$videosCount = $this->isPlaylist ? count($this->playlistInfo->video) : 1;

		$onFinalized = $this->onFinalized;
		$onFinalized($filePath, filesize($filePath), $this->currentDownloadingVideoIndex, $videosCount);
	}