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

Encoding Multiple Videos using Batch File #710

Closed
ARTUR551 opened this issue Apr 19, 2022 · 6 comments
Closed

Encoding Multiple Videos using Batch File #710

ARTUR551 opened this issue Apr 19, 2022 · 6 comments
Assignees
Labels
documentation This issue exists because the documentation is outdated. duplicate This issue or pull request already exists

Comments

@ARTUR551
Copy link

ARTUR551 commented Apr 19, 2022

Hi,

Thank you for developing SLEAP!

I have been running into the same error over and over.
After the GUI finishes training and tries to start the inference an error occurs:

KeyError: "Unable to load frame 7679 from MediaVideo(filename='D:/SLEAP/TEST_001.mp4', grayscale=False, bgr=True, dataset='', input_format='channels_last')."
'open_in_gui': False,
'peak_threshold': 0.2,
'tracking.tracker': None,
'tracking.target_instance_count': None,
'tracking.pre_cull_to_target': None,
'tracking.pre_cull_iou_threshold': None,
'tracking.post_connect_single_breaks': None,
'tracking.clean_instance_count': None,
'tracking.clean_iou_threshold': None,
Process return code: 1

I already tried with several single videos and pairs of them. I also tried to cut the last frames (even seconds) of several videos and I always get the same error. It is always with the last couple of frames of any video.
It also occurs when I try to run directly the inference process.

Is it a bug or I'm using wrong videos?

Thanks again!

Artur

@roomrys
Copy link
Collaborator

roomrys commented Apr 19, 2022

Hi @ARTUR551,

Glad you are enjoying SLEAP! We have seen a few problems like this occur when the video is not reliably seekable. Try reencoding your video and let us know how that works.

Thanks,
Liezl

P.S. Also linking similar problems here for reference (namely Unable to load frame #366 and KeyError when trying to run inference #630).

@ARTUR551
Copy link
Author

ARTUR551 commented Apr 20, 2022

Hi roomrys,

Thank you for your timely response.
The reencoding solution worked.

Is there a way to batch (or folder) reencode? (I'm not an expert in programming, I already looked all over and I did not find a way) I have hundreds of videos to analyze.
Or the reencoding is just needed for the training and inference?

Thanks again,

Artur

@roomrys
Copy link
Collaborator

roomrys commented Apr 20, 2022

Hi @ARTUR551,

Great that it worked!

To do any computer vision-based processing (as needed in training and inference), we require the video to be reliably seekable. That being said if you have many videos within a folder that are not reliably seekable and would like to perform training and/or inference on them, then we can create a batch file within the folder that will run the re-encode command on all the files (of a specific extension). Since we are running a command on an entire folder, I recommend having backup of the videos just to be safe.

To run the re-encode on an entire directory of videos (on Windows - if you are on another system, I can create instructions for a similar process):

  1. Navigate to the directory containing all the videos
  2. Create a new text file named "script.txt"
  3. Inside "script.txt", paste the following command:
for %%V in ("*.mp4") do ffmpeg -y -i "%%V" -c:v libx264 -pix_fmt yuv420p -preset superfast -crf 23 "output\%%~nV.mp4"

Note: with the above command, we only search for files ending with the .mp4 extension. If you would like to search for a different extension, change the *.mp4 to *.<another extension>

  1. Save "script.txt" and head back to the directory containing all the videos
  2. Change the extension of "script.txt" to "script.bat" - this will change the text file to a batch file which we can execute from the command line
  3. Create a new directory called "output" - this is where we will store all the re-encoded videos instead of overwriting the originals
  4. Open a terminal in the directory containing all the videos
  5. Run script.bat from within the terminal

Re-encoding does take a bit of time, so we recommend only doing it on videos you will use with SLEAP (which are not reliably seekable). Let me know if this works for you.

Thanks,
Liezl

@roomrys
Copy link
Collaborator

roomrys commented May 5, 2022

We should add documentation on this.

@roomrys roomrys added documentation This issue exists because the documentation is outdated. duplicate This issue or pull request already exists and removed waiting for user input labels May 5, 2022
@roomrys roomrys changed the title Consistent error after training Encoding Multiple Videos using Batch File May 5, 2022
@ARTUR551
Copy link
Author

It worked nicely!

Yes, documentation about this would be helpful.

Thanks!

@talmo
Copy link
Collaborator

talmo commented May 12, 2022

Closing as a duplicate of the objectives of #581.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This issue exists because the documentation is outdated. duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants