Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview generation for video files might fail for files greater 5MB #28694

Closed
juliushaertl opened this issue Sep 2, 2021 · 4 comments · Fixed by #28889
Closed

Preview generation for video files might fail for files greater 5MB #28694

juliushaertl opened this issue Sep 2, 2021 · 4 comments · Fixed by #28889
Labels

Comments

@juliushaertl
Copy link
Member

Starting with Nextcloud 20 the preview generation for video files is only using the first 5MB to process the thumbnails when using any non-local storage, e.g. as encountered with primary object storage.

This might work depending on the video file if the moov atom is located early enough in the original video file that it will be contained in the first chunk as well, however if the moov is outside of that chunk there is no chance that ffmpeg can parse it and generate a preview from it.

Basically we cannot be sure that the first 5MB will be enough to generate a preview.

Before 20:

$useFileDirectly = (!$fileInfo->isEncrypted() && !$fileInfo->isMounted());

Nextcloud 20+:
$useTempFile = $file->isEncrypted() || !$file->getStorage()->isLocal();

It worked before Nextcloud 20 as it just used the full file there also for non-local storages, however i would assume that is has always been an issue for external storages.

The only possible way to solve this would be to try the first 5mb part and if that fails to generate a preview we will need to fall back to use the full file, but I'm open for other ideas.

@ocrete
Copy link

ocrete commented Sep 9, 2021

Yes, you're right, for MP4 files, part of the header may be in the end.. You could even need something from a random spot in the middle in theory.

In practice, instead of downloading a 5MB chunk of the file and then running ffmpeg on it locally, you should just give the http URI to ffmpeg and have it do the http requests for you, it should do the proper byte-range requests to get the appropriate part. I guess you're using ffmpeg as a binary instead of the library? You should be able to give ffmpeg the cookies, extra header or whatever else is needed to make it connect.

@ocrete
Copy link

ocrete commented Sep 9, 2021

I'm seeing some stuff about encryption, you may need to write your own AVIO that calls into your code (but that means writing it in native code, not PHP)

@PVince81
Copy link
Member

passing an HTTP URI is not an option because Nextcloud has many storage types that are not accessible through HTTP, like SMB or SFTP

Another idea would be to pipe the stream from the storage into ffmpeg, having ffmpeg read from stdin. Here the hope is that ffmpeg already quits as soon as it has enough data to process the frame in question. If the latter works, then we don't need to pipe the whole file and rely on ffmpeg to abort early enough.

@PVince81
Copy link
Member

PR here that uses a fallback approach: #28889

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants