Skip to content

Commit

Permalink
Add resolution settings to video conversion and modal
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenAnpu committed Dec 16, 2024
1 parent ae199f4 commit 0c83419
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
5 changes: 4 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"main_script": "src/main.py",
"modal_template": "src/modal.html",
"modal_template_state": {
"targetFps": 25
"targetFps": 25,
"targetResolutionWidth": 1024,
"targetResolutionHeight": 768,
"changeResolution": false
},
"modal_template_data": {
"resultProjectName": {
Expand Down
6 changes: 5 additions & 1 deletion src/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import supervisely as sly

import ffmpeg
import globals as g


class FpsVideoInfo:
Expand Down Expand Up @@ -33,14 +34,17 @@ def get_name(stream_type):
return video_codec_name, audio_codec_name, bitrate


def convert_video(target_fps, in_fpath, out_fpath):
def convert_video(target_fps, in_fpath, out_fpath, target_resolution=None):
video_codec, audio_codec, bitrate = get_encoding_info(in_fpath)
sly.logger.debug(f'Source codecs: Video={video_codec!r}, Audio={audio_codec!r} Source bitrate: {bitrate} bps')

ffmpeg_verbosity = {'hide_banner': None, 'loglevel': 'error'}
in_video = ffmpeg.input(in_fpath, **ffmpeg_verbosity)
video_stream = in_video.video.filter("fps", target_fps)

if g.CHANGE_RESOLUTION:
video_stream = video_stream.filter('scale', target_resolution[0], target_resolution[1]) # width, height

stream_list = [video_stream]
kwargs = {'vcodec': video_codec, 'video_bitrate': bitrate,
'x265-params': 'log-level=error'} # x265 lib bug with loglevel
Expand Down
4 changes: 4 additions & 0 deletions src/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
WORKSPACE_ID = int(os.environ['context.workspaceId'])
PROJECT_ID = int(os.environ['modal.state.slyProjectId'])
DATASET_ID = int(os.environ['modal.state.slyDatasetId'])
CHANGE_RESOLUTION = os.environ['modal.state.changeResolution']
TARGET_HEIGHT = int(os.environ['modal.state.targetResolutionHeight'])
TARGET_WIDTH = int(os.environ['modal.state.targetResolutionWidth'])
target_resolution = (TARGET_WIDTH, TARGET_HEIGHT)

TARGET_FPS = float(os.environ['modal.state.targetFps'])
RES_PROJECT_NAME = os.getenv('modal.state.resultProjectName', None)
14 changes: 12 additions & 2 deletions src/modal.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
<sly-field>
<sly-field title="Target FPS">
<el-input-number v-model="state.targetFps" :min="0.1" max=200></el-input-number>
<el-input-number v-model="state.targetFps" :min="0.1" :max=200></el-input-number>
</sly-field>
<sly-field title="New project name" :description="data.resultProjectName.description">
<sly-field title="New Project Name" :description="data.resultProjectName.description">
<el-input v-model="state.resultProjectName"></el-input>
</sly-field>
<sly-field title="Change Resolution Settings">
<el-switch v-model="state.changeResolution"></el-switch>
</sly-field>
<sly-field v-if="state.changeResolution" title="Resolution Width x Height">
<div style="display: flex; align-items: center;">
<el-input-number v-model="state.targetResolutionWidth" :min=24 :max=5000></el-input-number>
<span style="margin: 0 10px;">x</span>
<el-input-number v-model="state.targetResolutionHeight" :min=24 :max=5000></el-input-number>
</div>
</sly-field>
</sly-field>

0 comments on commit 0c83419

Please sign in to comment.