Spaces:
Sleeping
Sleeping
edited vc to support webm input
Browse files- Dockerfile +3 -0
- app.py +3 -2
- utlis.py +74 -22
Dockerfile
CHANGED
|
@@ -25,6 +25,9 @@ RUN chmod -R 777 /app/results_st
|
|
| 25 |
RUN mkdir /app/results_vtr
|
| 26 |
RUN chmod -R 777 /app/results_vtr
|
| 27 |
|
|
|
|
|
|
|
|
|
|
| 28 |
COPY . .
|
| 29 |
|
| 30 |
CMD ["python", "app.py"]
|
|
|
|
| 25 |
RUN mkdir /app/results_vtr
|
| 26 |
RUN chmod -R 777 /app/results_vtr
|
| 27 |
|
| 28 |
+
RUN mkdir /app/logs
|
| 29 |
+
RUN chmod -R 777 /app/logs
|
| 30 |
+
|
| 31 |
COPY . .
|
| 32 |
|
| 33 |
CMD ["python", "app.py"]
|
app.py
CHANGED
|
@@ -38,7 +38,7 @@ def classify_input_format(input_string):
|
|
| 38 |
pass
|
| 39 |
|
| 40 |
# if the input format is neither seconds nor HH:MM:SS, return None
|
| 41 |
-
|
| 42 |
|
| 43 |
def set_output_file(input_file, output_format, folder, insert_string = 'trimmed'):
|
| 44 |
# Set output file name and extension
|
|
@@ -183,7 +183,8 @@ def convert_video(input_file, output_format):
|
|
| 183 |
try:
|
| 184 |
# Set output file
|
| 185 |
output_folder = f"{os.getcwd()}/results_vc/"
|
| 186 |
-
output_file = set_output_file(input_file, output_format, output_folder
|
|
|
|
| 187 |
|
| 188 |
# Convert video
|
| 189 |
output_file = convert_video_helper(input_file, output_file, output_format)
|
|
|
|
| 38 |
pass
|
| 39 |
|
| 40 |
# if the input format is neither seconds nor HH:MM:SS, return None
|
| 41 |
+
gr.Error("Input format not supported. Please enter a valid time in the format HH:MM:SS or seconds.")
|
| 42 |
|
| 43 |
def set_output_file(input_file, output_format, folder, insert_string = 'trimmed'):
|
| 44 |
# Set output file name and extension
|
|
|
|
| 183 |
try:
|
| 184 |
# Set output file
|
| 185 |
output_folder = f"{os.getcwd()}/results_vc/"
|
| 186 |
+
output_file = set_output_file(input_file, output_format, output_folder, \
|
| 187 |
+
insert_string = 'converted')
|
| 188 |
|
| 189 |
# Convert video
|
| 190 |
output_file = convert_video_helper(input_file, output_file, output_format)
|
utlis.py
CHANGED
|
@@ -7,6 +7,11 @@ from pathlib import Path
|
|
| 7 |
import gradio as gr
|
| 8 |
import pandas as pd
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def sort_transcript(file_path, save_path):
|
| 12 |
"""
|
|
@@ -55,41 +60,88 @@ def sort_transcript(file_path, save_path):
|
|
| 55 |
|
| 56 |
|
| 57 |
def convert_video_format(media_in, media_out):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
try:
|
| 59 |
WAV_CHANNELS = 1
|
| 60 |
WAV_SAMPLE_RATE = 16000
|
| 61 |
-
|
| 62 |
if not isinstance(media_in, (str, Path)):
|
| 63 |
raise TypeError("media_in must be a string or a PathLike object")
|
| 64 |
-
|
| 65 |
if not isinstance(media_out, (str, Path)):
|
| 66 |
raise TypeError("media_out must be a string or a PathLike object")
|
| 67 |
-
ext = Path(media_out).suffix
|
| 68 |
-
if ext == '.wav':
|
| 69 |
-
# convert to wav with standard format for audio models
|
| 70 |
-
print(f'...generating {media_out}...')
|
| 71 |
-
subprocess.run(f'ffmpeg -y -i "{media_in}" -acodec pcm_s16le -ac {WAV_CHANNELS} -ar {WAV_SAMPLE_RATE} "{media_out}" -hide_banner -loglevel warning', check=True, shell=True)
|
| 72 |
-
return media_out
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
return media_out
|
|
|
|
|
|
|
| 90 |
except Exception as e:
|
|
|
|
| 91 |
gr.Error(f"Error converting video format: {e}")
|
| 92 |
|
|
|
|
| 93 |
def trim_media(media_in, media_out, start, end):
|
| 94 |
try:
|
| 95 |
# options for writing out audio if converting
|
|
|
|
| 7 |
import gradio as gr
|
| 8 |
import pandas as pd
|
| 9 |
|
| 10 |
+
import logging
|
| 11 |
+
os.makedirs(f'{os.getcwd()}/logs', exist_ok=True)
|
| 12 |
+
logging.basicConfig(filename=f'{os.getcwd()}/logs/logfile.log', level=logging.INFO,
|
| 13 |
+
format='%(asctime)s - %(levelname)s - %(message)s')
|
| 14 |
+
logging.info('Starting the application...')
|
| 15 |
|
| 16 |
def sort_transcript(file_path, save_path):
|
| 17 |
"""
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
def convert_video_format(media_in, media_out):
|
| 63 |
+
"""
|
| 64 |
+
Function to convert video format using ffmpeg.
|
| 65 |
+
|
| 66 |
+
"""
|
| 67 |
+
logging.info(f'...Converting video format from {media_in} to {media_out}...')
|
| 68 |
+
|
| 69 |
try:
|
| 70 |
WAV_CHANNELS = 1
|
| 71 |
WAV_SAMPLE_RATE = 16000
|
| 72 |
+
|
| 73 |
if not isinstance(media_in, (str, Path)):
|
| 74 |
raise TypeError("media_in must be a string or a PathLike object")
|
| 75 |
+
|
| 76 |
if not isinstance(media_out, (str, Path)):
|
| 77 |
raise TypeError("media_out must be a string or a PathLike object")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
+
in_ext = Path(media_in).suffix
|
| 80 |
+
out_ext = Path(media_out).suffix
|
| 81 |
+
|
| 82 |
+
if in_ext !='.webm':
|
| 83 |
+
# input is not in webm format
|
| 84 |
+
if out_ext == '.wav':
|
| 85 |
+
# convert to wav with standard format for audio models
|
| 86 |
+
logging.info(f'...generating {media_out}...')
|
| 87 |
+
command = ['ffmpeg', '-y', '-i',
|
| 88 |
+
media_in, '-acodec', 'pcm_s16le',
|
| 89 |
+
'-ac', str(WAV_CHANNELS), '-ar',
|
| 90 |
+
str(WAV_SAMPLE_RATE), media_out,
|
| 91 |
+
'-hide_banner', '-loglevel', 'warning']
|
| 92 |
+
process = subprocess.run(command, capture_output=True, text=True)
|
| 93 |
+
if process.returncode != 0:
|
| 94 |
+
logging.info(f"Error: {process.stderr}")
|
| 95 |
+
else:
|
| 96 |
+
logging.info(process.stdout)
|
| 97 |
+
return media_out
|
| 98 |
+
|
| 99 |
+
else:
|
| 100 |
+
logging.info(f'...Using ffmpeg to convert {media_in} to {media_out}...')
|
| 101 |
+
logging.info(f'...generating {media_out}...')
|
| 102 |
+
command = ['ffmpeg',
|
| 103 |
+
'-y',
|
| 104 |
+
'-i',
|
| 105 |
+
media_in,
|
| 106 |
+
'-c',
|
| 107 |
+
'copy',
|
| 108 |
+
media_out,
|
| 109 |
+
'-hide_banner',
|
| 110 |
+
'-loglevel',
|
| 111 |
+
'warning'
|
| 112 |
+
]
|
| 113 |
+
process = subprocess.run(command, check=True)
|
| 114 |
+
if process.returncode != 0:
|
| 115 |
+
logging.info(f"Error: {process.stderr}")
|
| 116 |
+
else:
|
| 117 |
+
logging.info(process.stdout)
|
| 118 |
+
return media_out
|
| 119 |
|
| 120 |
+
if in_ext == '.webm':
|
| 121 |
+
if out_ext == '.wav':
|
| 122 |
+
command = ['ffmpeg', '-i', media_in, media_out]
|
| 123 |
+
process = subprocess.run(command, capture_output=True, text=True)
|
| 124 |
+
if process.returncode != 0:
|
| 125 |
+
logging.info(f"Error: {process.stderr}")
|
| 126 |
+
else:
|
| 127 |
+
logging.info(process.stdout)
|
| 128 |
+
return media_out
|
| 129 |
+
|
| 130 |
+
else:
|
| 131 |
+
command = ['ffmpeg', '-i', media_in, '-vcodec', 'h264', '-acodec', 'aac', media_out]
|
| 132 |
+
process = subprocess.run(command, capture_output=True, text=True)
|
| 133 |
+
if process.returncode != 0:
|
| 134 |
+
logging.info(f"Error: {process.stderr}")
|
| 135 |
+
else:
|
| 136 |
+
logging.info(process.stdout)
|
| 137 |
return media_out
|
| 138 |
+
|
| 139 |
+
|
| 140 |
except Exception as e:
|
| 141 |
+
logging.error(f"Error converting video format: {e}")
|
| 142 |
gr.Error(f"Error converting video format: {e}")
|
| 143 |
|
| 144 |
+
|
| 145 |
def trim_media(media_in, media_out, start, end):
|
| 146 |
try:
|
| 147 |
# options for writing out audio if converting
|