-
This is a Django video processing app that uses the
FFMPEG
library at the backend to extract audio and watermark to the uploaded video. -
The application also implements custom watermark overlay feature where the user can either supply exact
x,y
coordinates or use predefined places to put watermark on. -
The application also stores the details of the Videos and the Processed videos and the user who uploaded them in the PostgreSQL db.
-
Uses User model of django and JWT token authentication to for user signup and login before using the API
-
The app follows a modular structure, with clear and concise code.
-
The application uses the
APIView
class from the django-rest-framework to have a better control over the backend api endpoints and responses. -
Makefile introduced for efficient local setup and development.
-
Audio Extraction:
- Upload a video file.
- Extract the audio from the video.
- Download the extracted audio file in mp3 format.
-
Video Watermarking:
- Upload a video and a watermark image.
- Overlay the watermark on the video at a customizable position.
- User can provide exact
x,y
coordinates (starting from top left of the video) - User can use predefined positions supported by API which are:
top-left
top-right
bottom-right
bottom-left
center
- User can provide exact
- Store information about the processed video and watermarking parameters along with the path of files and time of edit.
- Download the video with watermark!
-
Containerized Application:
- Dockerized for easy deployment and scalability.
- The DB persistence is maintained through docker volumes where docker attaches a local volume to the DB service so as to have backup data in case the container is closed say through
docker compose down
. - Backend data (stored videos and audio files and images) are also persisted.
- Instructions for containerizing the application included in the README.
-
Running Directly From Repository
-
Clone the repository and cd into it.
-
run the command
make setup
to install dependencies and create .env file from .env.example. -
Start the virtual environment by using the command
source src/.venv/bin/activate
. -
open .env file and add the appropriate values below
# FOR DJANGO APP
comment for the database settings (there are some place holder settings for docker use, replace them) -
Now to run the backend server, simply type
make runserver
to initiate the server at http://127.0.0.1:8000/
-
-
Using Docker Compose
-
Clone the repository and cd into it.
-
Run the command
cp .env.example .env
to generate a .env file. Change the values if you wish to, although I have already populated the fields with Test values. -
Now we can start creating images and running up the containers. Use the commands in root directory itself.
-
Write these commands to start using the app:
sudo docker compose build
docker-compose build
builds the images for the listed services in thedocker-compose.yml
file, here they will be backend and db.
docker compose up
-
docker compose up
creates the respective containers from the images of the services and composes them together also creating a local network for them in order for the services to communicate. -
A backend server would have started at http://127.0.0.1:8000/.
-
To stop the containers:
docker compose down
docker compose down
command will stop running containers, but it also removes the stopped containers as well as any networks that were created.
-
-
Go to http://127.0.0.1:8000/accounts/api/signup/ and register a user
- You need to send
username
andpassword
fields. - Request should be
POST
- You need to send
-
Go to http://127.0.0.1:8000/accounts/api/login/ and login with credentials of a signed up user
- You need to send
username
andpassword
fields. - Request should be
POST
- Copy the token value from
access
field in the body of the response
- You need to send
-
- Go to http://127.0.0.1:8000/video/api/extract-audio/
- Add the
Authorization
Header key to the request. The value will beBearer {token}
Example Authorization : Bearer {paste token copied above, without braces}
- In the body, send
video_file
field with a video. - You will get a response with the mp3 file which can be downloaded.
-
-
Add the
Authorization
Header key to the request. The value will beBearer {token}
Example Authorization : Bearer {paste token copied above, without braces}
-
In the body, send
video_file
field with a video, sendimage_file
field with a an image/logo. -
[OPTIONAL] SEND
scale
field to scale the watermark respective to height of video.- Default value is
0.2
- Value should be less than
1
and should have at most 3 decimals
- Default value is
-
If you wish to use custom coordinates for the position of the watermark
- Send
custom_coordinate_X
field with the X position AND - Send
custom_coordinate_Y
field with the Y position - Both fields are important for this to work
- (0,0) is the top-left pixel in the video.
- Coordinates should be under the value of the resolution of the video.
- Send
-
You can also use the predefined positions in the API
-
Send
lazy_position
field with any of the following values: -top-left
-top-right
-bottom-right
-bottom-left
-center
-
If both coordinates and lazy_position is supplied, then the coordinates are given priority.
-
Download the video with the watermark
- Fields:
user
: ForeignKey to the Django built-inUser
model, representing the user who uploaded the video.video_file
: FileField storing the video file with specified upload location and file extension validation.upload_timestamp
: DateTimeField set to auto_now_add, representing the timestamp of when the video was uploaded.
- Fields:
video
: ForeignKey to theVideo
model, creating a relationship with the original video.audio_file
: CharField storing the path to the audio file related to the processed video.extraction_timestamp
: DateTimeField set to auto_now_add, representing the timestamp of when the audio was extracted.
- Methods:
get_audio_file_object()
: An API method allowing file handling, yielding the binary file content.
- Fields:
video
: ForeignKey to theVideo
model, creating a relationship with the original video.watermark_image
: ImageField storing the watermark image file with specified upload location and file extension validation.watermarked_video_path
: CharField storing the path to the watermarked video file.overlay_timestamp
: DateTimeField set to auto_now_add, representing the timestamp of when the video was watermarked.lazy_position
: CharField with a maximum length of 20, allowing specification of a lazy position (nullable).custom_coordinate_X
: IntegerField representing the custom X-coordinate for the watermark (nullable).custom_coordinate_Y
: IntegerField representing the custom Y-coordinate for the watermark (nullable).scale
: DecimalField representing the scale of the watermark with a default value of 0.2.