Code Monkey home page Code Monkey logo

dane-video-segmentation-worker's Introduction

main branch

dane-video-segmentation-worker

Running Scenedetect to detect shots and select keyframes. Including code for extracting keyframes, extracting audio, and generating spectrograms.

Installation

Use Poetry to install this project into a virtualenv.

poetry install

Installing python-opencv in a virtualenv, and thus not as a system package, could cause certain shared-objects to be missing. So far it seems libgl1 might be missing this way. Install it using:

apt-get install libgl1

To make sure the unit-test work as well

apt-get install ffmpeg

Run in local Python virtualenv

For local testing, make sure to put a config.yml in the root of this repo:

cp ./config/config.yml config.yml

Then make sure to activate your virtual environment:

poetry shell

Then run ./scripts/check-project.sh to:

  • linting (Using flake8)
  • type checking (Using mypy)
  • unit testing (Using pytest)

Run test file in local Docker Engine

This form of testing/running avoids connecting to DANE:

  • No connection to DANE RabbitMQ is made
  • No connection to DANE ElasticSearch is made

This is ideal for testing:

  • main_data_processor.py, which uses VISXP_PREP.TEST_INPUT_FILE (see config.yml) to produce this worker's output
  • I/O steps taken after the output is generated, i.e. deletion of input/output and transfer of output to S3
docker build -t dane-video-segmentation-worker .

Check out the docker-compose.yml to learn about how the main process is started. As you can see there are two volumes mounted and an environment file is loaded:

version: '3'
services:
  web:
    image: dane-video-segmentation-worker:latest  # your locally built docker image
    volumes:
      - ./data:/data  # put input files in ./data and update VISXP_PREP.TEST_INPUT_FILE in ./config/config.yml
      - ./config:/root/.DANE  # ./config/config.yml is mounted to configure the main process
    container_name: visxp
    command: --run-test-file  # NOTE: comment this line to spin up th worker
    env_file:
      - s3-creds.env  # create this file with AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to allow boto3 to connect to your AWS S3 bucket (see OUTPUT.S3_* variables in config.yml)
    logging:
      options:
        max-size: 20m
    restart: unless-stopped

There is no need to update the docker-compose.yml, but make sure to:

  • adapt ./config/config.yml (see next sub-section for details)
  • create s3-creds.env to allow the worker to upload output to your AWS S3 bucket

Config

The following parts are relevant for local testing (without connecting to DANE). All defaults are fine for testing, except:

  • VISXP_PREP.TEST_INPUT_FILE: make sure to supply your own mp4 file in ./data
  • S3_ENDPOINT_URL: ask your DANE admin for the endpoint URL
  • S3_BUCKET: ask your DANE admin for the bucket name
FILE_SYSTEM:
    BASE_MOUNT: /data
    INPUT_DIR: input-files
    OUTPUT_DIR: output-files/visxp_prep
PATHS:
    TEMP_FOLDER: /data/input-files
    OUT_FOLDER: /data/output-files
VISXP_PREP:
    RUN_KEYFRAME_EXTRACTION: true
    RUN_AUDIO_EXTRACTION: false
    SPECTROGRAM_WINDOW_SIZE_MS: 1000
    SPECTROGRAM_SAMPLERATE_HZ:
        - 24000
    TEST_INPUT_FILE: /data/testob-take-2.mp4
INPUT:
    DELETE_ON_COMPLETION: False  # NOTE: set to True in production environment
OUTPUT:
    DELETE_ON_COMPLETION: True
    TRANSFER_ON_COMPLETION: True
    S3_ENDPOINT_URL: https://your-s3-host/
    S3_BUCKET: your-s3-bucket  # bucket reserved for 1 type of output
    S3_FOLDER_IN_BUCKET: assets  # folder within the bucket

Relevant links

Also see: https://stackoverflow.com/questions/64664094/i-cannot-use-opencv2-and-received-importerror-libgl-so-1-cannot-open-shared-obj

https://docs.opencv.org/4.x/d2/de6/tutorial_py_setup_in_ubuntu.html

dane-video-segmentation-worker's People

Contributors

dependabot[bot] avatar gb-beng avatar jblom avatar martijnbng avatar mwigham avatar veldhoen avatar wmelder avatar

Watchers

 avatar  avatar  avatar  avatar

dane-video-segmentation-worker's Issues

Run hecate

Have worker use hecate to apply shot detection

Use timestamps in video-url to determine which shots to filter out

Output:

  • shot boundaries (timestamps)
  • keyframe time codes
  • keyframes (optional, based on config. Either png or jpg)
  • Thumbnails (optional, based on config)

Manage edge-cases for spectograms (out of scope)

When a keyframe is very close to the beginning or end of a video, a (symmetrical) one second window of audio cannot be creared. Moreover, when a keyframe is close to a shot boundary, a one second window may be inappropriate. However, the feature extraction model requires homogeneous, one second-based spectograms.

We discussed several solutions:

  • shift the keyframe timestamp away from the boundary (and extract both spectogram and keyframe at that moment in time)
  • pad the extracted audio with repeated frames. This can be mirrorred padding (playing the edge frames again in reverse) or circular padding (repeat the last frames in he beginning, or the first frames at the end). The last approach is expected to be least harmful to the spectogram.
  • discard all keyframes that are close to the edges alltogether

The second approach (apply padding, in a circular fashion) is deemed most appropriate.
However, due to time constraints we stick with the last approach (discarding edge frames) at least for the video boundaries, as a minimum effort solution.

NB: the same holds for the annotations a researcher uses as query for similarity search!

Determine appropriate way to include hecate

Hecate is C++ code. I can think of several options to include it in a worker:

  • Install everything in one docker. Use Python subprocess to call Hecate executionable from Python (this is roughly the approach (minus containerization) taken in https://github.com/beeldengeluid/dane-shot-detection-worker
  • Install Hecate in a separate docker, and use docker-py (or some other approach) to call it from Python
  • Use C bindings to run Hecate directly from Python

What is the most elegant way to tackle this problem? @jblom @MartijnBNG @gb-beng any thoughts on this? Did you encounter this before, and how was it solved?

Tweak scenedetect

Shot length, prevent almost duplicate keyframes, enough keyframes per time interval

Containerize

Create dockerfile (& image) to include both installation of hecate and dependencies for audio processing

Improve documentation

it is not so clear from the README how to run the local test
there are 2 config.yml files, this is confusing

Drop audio processing

Make audio processing a configurable option (and set to false for current processing)

Restore to a runnable state

Currently, I get all kinds of errors trying to run the code either locally or in a container. Need to fix those before I can do anything relevant.

Also, do some cleanup:
Local installation via poetry and in Dockerfile through pip/requirements.txt obscures the process unnecessarily
Also, there are lots of references to Hecate, both in the code and the readme.

Replace! Hecate

Shots seem overly strict, keyframes quite generous.

ffmpeg can also do scene detection
Philo & A-team have looked into tools for keyframes & scenes > find report
DAAN also stores keyframes (low res) - use timestamps?

Coverage keyframes

Make sure there are enough keyframes per time interval

(First: check whether it actually happens that coverage is low)

Audio spectogram

Create and output audio spectogram from video based on 1 second window around given timestamp

Generate snippets

Decide whether to generate audio and video snippets (whether to support this in the frontend)

VisXP provenance plan

Document suggesting how to deal with it (store in S3)
Discuss that on September 4

Added this as an issue for the dane-video-segmentation-worker, although it also holds for the next worker(s)

Enforce spectogram quality

Assert that every spectogram that is outputted has the proper dimensionality (e.g. the time window was correct, etc.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.