Signbank / Global-signbank

An online sign dictionary and sign database management system for research purposes. Developed originally by Steve Cassidy/ This repo is a fork for the Dutch version, previously called 'NGT-Signbank'.
http://signbank.cls.ru.nl
BSD 3-Clause "New" or "Revised" License
19 stars 12 forks source link

Uploading video doesn't work - high priority #1102

Closed uklomp closed 3 months ago

uklomp commented 11 months ago

Two of my colleagues experience problems with recording a video to add with new signs (within the Oefenproject dataset). One of them tried to record a video (so: add a new sign to the dataset, and then record a video on the laptop with the integrated camera) and the image appeared but froze. Then they tried again, and recording and seeing it again works, but with uploading, the screen remains black. The other colleague experienced this as well.

susanodd commented 11 months ago

What is the operating system, browser?

susanodd commented 11 months ago

@uklomp did you check if the videos have been uploaded behind the scenes?

We had some issues in the past with large videos, that an error appears but that the video was in fact uploaded. (The uploading of a large video, the transaction finishes before the saving of the video has taken place. But the video turned out to have been uploaded, just not immediately visible.)

uklomp commented 11 months ago

I will ask them about OS and browser. As for uploaded behind the scenes: Hmm, I don't know how to check that, can you tell me where to see this? It must be noted that it worked fine before, so it would be weird if these videos are all of a sudden larger or different from earlier recorded videos...

(could it have to do anything with the fact that SignBank was down this morning?)

susanodd commented 11 months ago

Signbank was moved to a different computer.

I also deployed twice to solve bugs with morphemes that I fixed on master.

The deployment script has bugs in it due to the CNGT_scripts (some packages need new versions), so the deployment script didn't finish (but that didn't matter since it's only checking that packages are installed). I restarted it twice. It's possible that you were attempting to upload at the same time when it was being deployed.

You can look in the Admin at the GlossVideo section to see if the files are there. They should be near the top.

If indeed the files were visible before and then not visible, we'll have the system people check whether all the folders were copied. (Some paths to files may be different on the new computer and need to be set in the settings. The ones for the live server are not the same ones as visible on GitHub in the files.)

Jetske commented 11 months ago

I just tried and it worked for me. However, these problems are usually related to OS and browser. I use Windows + Chrome and know that Firefox and macOS often give trouble, so if possible prevent using those for now. To be honest I'm not sure how we can fix this at the moment as none of us use macOS so we can't really test it. It would really help to know the browser and OS that the problem occurs on.

If you tried uploading many times without luck, it can help to keep deleting videos on the gloss detail page until no backup video is found for the gloss and then upload/record it again. However, if there was a good backup video before, there is a risk to this button that it would throw away the backup file for good! @susanodd if it's a new gloss this would be ok, right?

I'll also make a pull request for #1065 as the video that it is trying to show is not always the latest video if there is still a video in the browser's cache so that can help to at least show the right video instead of an old (broken) version.

susanodd commented 11 months ago

I'm not entirely sure about how the delete works. I use Firefox on Ubuntu at the uni, and MacOS at home. I know if you upload quicktime videos they are not converted properly, so not visible on other browsers.

uklomp commented 11 months ago

It apparently works again. At least one of them uses MacOS indeed, the other colleague I don't know. I'll close it for now and if it happens again, I'll ask for more details.

uklomp commented 9 months ago

Hi, one of my colleagues can't record videos at the moment. She's using MacOS and Safari. She tries to use Chrome but there the inlog fails (other issue). She's recording a video with a new sign within the NGT dataset. The system counts down 3, 2, 1, but then the video freezes and she can't record.

susanodd commented 9 months ago

I can successfully upload recorded videos on MacOS / Safari.

I don't think recording inside of Signbank works. Can she make a video using the apple camera software and then upload this?

During uploading there is an alert about a non-trusted video app and it asks if you want to put it in the trash. So just dismiss it and don't do anything. The video is uploaded in spite of this. (There is also an error message in the runime log. We think this is something to do with the CNGT-scripts that grab the still image from the video. @vanlummelhuizen )

susanodd commented 9 months ago

From the development log:

Video file: /var/www/writable/glossvideo/NGT/BR/BROOD-B-1157.mp4 Error resizing video: /var/www/writable/glossvideo/NGT/BR/BROOD-B-1157.mp4 [Errno 2] No such file or directory: 'avprobe' Video file: /var/www/writable/glossvideo/NGT/BR/BROOD-B-1157.mp4 avconv -v quiet -i /var/www/writable/glossvideo/NGT/BR/BROOD-B-1157.mp4 -filter:v scale='iwmax(1,sar)':'ihmax(1,1/sar)' /var/www/writable/tmp/signbank-ExtractMiddleFrame/BROOD-B-1157.mp4-frames/all/frame-%5d.png IOError: [Errno 2] No such file or directory: 'avconv'

But I found this while looking for a avconv package to install:

avconv is obsolete and the libav-tools package is not found in any modern/supported version of Ubuntu. Use ffmpeg. (You should look at the date on guides you try to follow. The page you linked to is 10 years old..)

susanodd commented 9 months ago

That didn't entirely fix the bug.

On the "bread keyword" video, an error is generated by (video/models.py, class GlossVideo method)

def make_small_video(self):
    from CNGT_scripts.python.resizeVideos import VideoResizer

    video_file_full_path = os.path.join(WRITABLE_FOLDER, str(self.videofile))
    try:
        resizer = VideoResizer([video_file_full_path], FFMPEG_PROGRAM, 180, 0, 0)
        resizer.run()
    except Exception as e:
        print(e)

The error is: 'duration'

susanodd commented 9 months ago

@Jetske from the documentation of ffmpeg, it looks like you need to leave the original ".mkv" extension on the file, rather than rename it to ".mp4". And let ffmpeg convert it.

It looks like the ffmpeg software applies its own "logic" when converting because the ".mkv" files may have subtitles, so three streams. So the ffmpeg (examples in the documentation) show extracting only whichever stream is needed to obtain the desired output.

(The recorded Matroska video does not work on Firefox nor on Safari. I suspect it's because it's merely renamed. The convert video software is merely renaming .mkv and .mov files since the conversion has been broken. it looks like the ffmpeg command -- done inside the CNGT scripts -- needs to be changed, different parameters for different file types.)

susanodd commented 9 months ago

[UPLOADING A RECORDED VIDEO FROM WEBCAM]

@Jetske I've been experimenting with a matroska file (from last year, recorded by you). It only works to upload it on Firefox with the "renamed" mp4 extension. (The browser will not allow the webm, mkv extensions to be selected, no matter what I do to the form and validation.)

So the file is being uploaded, but it does not display.

So I'm using the convert_to_mp4 method you wrote a long time ago, that has been commented out in the code.

There is a problem with the conversion, but it's not what you think. The ffmpeg command does not like it if you overwrite the source file. That is what is broken.

I changed it to the following.

def convert_to_mp4(self):
    print(self.videofile.path)
    name, _ = os.path.splitext(self.videofile.path)
    out_name = name + "2.mp4"
    import ffmpeg
    ffmpeg.input(self.videofile.path).output(out_name).run(quiet=False)
    print("Finished converting {}".format(self.videofile.path))

By adding a "2" before the .mp4 filename. (This is wrong because it's adding it after the gloss ID.) It finishes and prints "Finished...."

The actual file is not displayed in the browser (it obviously has the wrong filename and can't be found.) But the file stored on disk can be played. (The original file could not be played.)

So if that ffmpeg command can be modified to save a copy during conversion and then copy it back, it should work.

susanodd commented 9 months ago

I think we should get rid of the versions (saving the old videos before uploading a new). This is totally messed up if something goes wrong with upload. As soon as you try to upload again (because it does not display properly), it generates yet another video in the file system. In order to stop this, you literally need to keep deleting the "video" (even if you can't see it), until it goes back to the no video screen. This is extremely annoying, and there end up numerous video mishaps filling up the space because nothing is deleted.

susanodd commented 9 months ago

This is a pull request now. I only changed the gloss video method, not the sentence video method. @Jetske hopefully you can check this, since you can create the Matroska videos with the webcam. I only changed the method that's called by adding videos in Gloss Edit.

susanodd commented 9 months ago

Some of the very old videos are interlaced.

susanodd commented 9 months ago

Also works to convert quicktime to mp4.

susanodd commented 9 months ago

Does not work on older formats like mpeg2 or interlaced videos. (The command works but the interlacing is visible and weird inverse colours.)

susanodd commented 9 months ago

@Jetske I'm trying to debug the video upload for uploading a video I made on my macbook using the camera, since I can't record in the browser. The camera makes videos in .mov format.

Since I'm testing stuff trying to figure out how to get small videos to work (they end up with horizontal lines in them), I looked in the admin to see what GlossVideo entries there are. I noticed there are quite a few ".bak.bak" videos for Oefen. It looks like videos were uploaded again if it didn't work. But this ends up creating an entry in GlossVideo even if it was unsuccessful to upload. Then these are causing new uploads to mess up because "reversion" on a non-existent file doesn't work.

(It's something like failed uploads, and paths to non-existent files stored in the database. Because even if there was no file -- a failed upload -- it still makes a ".bak" entry in the GlossVideo table.)

susanodd commented 9 months ago

From the pull request, what has been done so far:

I have the code working for quicktime videos now. I think what was going wrong before the repairs was that

  1. quicktime is already in h264 format - to fix this the convert_video routine ffmpeg, if the source video is quicktime, it now uses codec "copy" to remove the container from the video and save it as mp4
  2. the frames per second is 15, not 30. This was causing the make small video to not work. Instead - new python function - first small png files for the frames are generated, then these are put into a new .mov file using rawvideo format. Then this is converted to mp4.
susanodd commented 9 months ago

I still need to work on the matroska format, if somebody ends up with one of these from their camera. These don't display on Firefox nor on Safari / (anything) Apple. The same workflow hopefully applies.

susanodd commented 7 months ago

Is this solved?

uklomp commented 6 months ago

who do you ask? :)

susanodd commented 6 months ago

Anybody? Has anybody had problems with videos recently? (Sometimes bugs get reported and we fix things but it's hard to duplicate what caused the bug initially, so it's not always possible to confirm that a bug has been fixed.) I guess if nobody has had problems with this then it can be closed.