rosyvs commited on
Commit
500e98d
·
1 Parent(s): d971130

generate a different FFMPEG command for webm to wav specifically , to fix white noise output issue. Stil ldont know why this was happening.

Browse files
Files changed (2) hide show
  1. app.py +5 -5
  2. utils.py +27 -34
app.py CHANGED
@@ -60,9 +60,9 @@ def trim_video_helper(input_file, output_file, start_time, end_time):
60
 
61
  def convert_video_helper(input_file, output_file, output_format):
62
  # convert video
63
- print("start converting")
64
  output_file = convert_and_trim_video(input_file.name, output_file)
65
- print("finished converting")
66
  return output_file
67
 
68
  def convert_transcript_helper(input_transcript, output_transcript):
@@ -174,10 +174,10 @@ def convert_video(input_file, output_format):
174
  output_folder = f"{os.getcwd()}/results_vc/"
175
  output_file = set_output_file(input_file, output_format, output_folder, \
176
  insert_string = 'converted')
177
- print("Begin converting to output format: ", output_format)
178
  # Convert video
179
  output_file = convert_video_helper(input_file, output_file, output_format)
180
- print("created output file: ", output_file)
181
  # remove file after 10 minutes for security
182
  print("Done converting. start deleting files")
183
  path_to_delete = [input_file.name, output_file]
@@ -199,7 +199,7 @@ interface = gr.Interface(fn=trim_video, inputs=[input_file, output_format, start
199
 
200
  # gr components for video converter
201
  input_file_c = gr.File(label="Select video file")
202
- output_format_c = gr.Dropdown(choices=["mkv", "MOV", "mp4", "wav"], label="Select output format", value="mp4",)
203
  output_file_c = gr.File(label="Download converted file")
204
 
205
  interface_c = gr.Interface(fn=convert_video, inputs=[input_file_c, output_format_c], outputs=output_file_c, title="Video Converter", allow_flagging="never",
 
60
 
61
  def convert_video_helper(input_file, output_file, output_format):
62
  # convert video
63
+ print(f"convert_video_helper: converting {input_file} to {output_format}")
64
  output_file = convert_and_trim_video(input_file.name, output_file)
65
+ print("convert_video_helper: finished converting")
66
  return output_file
67
 
68
  def convert_transcript_helper(input_transcript, output_transcript):
 
174
  output_folder = f"{os.getcwd()}/results_vc/"
175
  output_file = set_output_file(input_file, output_format, output_folder, \
176
  insert_string = 'converted')
177
+ print(f"Begin converting to output format: {output_format}" )
178
  # Convert video
179
  output_file = convert_video_helper(input_file, output_file, output_format)
180
+ print(f"created output file: {output_file}")
181
  # remove file after 10 minutes for security
182
  print("Done converting. start deleting files")
183
  path_to_delete = [input_file.name, output_file]
 
199
 
200
  # gr components for video converter
201
  input_file_c = gr.File(label="Select video file")
202
+ output_format_c = gr.Dropdown(choices=["mkv", "MOV", "mp4", "wav"], label="Select output format", value="wav",)
203
  output_file_c = gr.File(label="Download converted file")
204
 
205
  interface_c = gr.Interface(fn=convert_video, inputs=[input_file_c, output_format_c], outputs=output_file_c, title="Video Converter", allow_flagging="never",
utils.py CHANGED
@@ -214,26 +214,24 @@ def convert_and_trim_video(media_in, media_out, start=None, end=None):
214
  logging.info(f'...Using ffmpeg to convert {in_ext} to {out_ext}...')
215
 
216
  if out_ext == '.wav':
217
- # convert to wav with standard format for audio models
218
- command = [
219
- 'ffmpeg',
220
- "-f", "s16le",
221
- '-y',
222
- '-i', media_in,
223
- *trim_command,
224
- '-vn',
225
- '-acodec', 'pcm_s16le',
226
- '-ac', str(WAV_CHANNELS),
227
- '-ar', str(WAV_SAMPLE_RATE),
228
- media_out,
229
- '-hide_banner', '-loglevel', 'warning']
230
- logging.info(f"FFMPEG command: {' '.join(command)}")
231
- process = subprocess.run(command, capture_output=True, text=True)
232
- if process.returncode != 0:
233
- logging.info(f"FFMPEG error: {process.stderr}")
234
- else:
235
- logging.info(process.stdout)
236
- return media_out
237
 
238
  else: # convert using copy codec
239
  if in_ext == '.webm':
@@ -245,13 +243,6 @@ def convert_and_trim_video(media_in, media_out, start=None, end=None):
245
  '-acodec', 'aac',
246
  media_out,
247
  '-hide_banner', '-loglevel', 'warning']
248
- logging.info(f"FFMPEG command: {' '.join(command)}")
249
- process = subprocess.run(command, capture_output=True, text=True)
250
- if process.returncode != 0:
251
- logging.info(f"FFMPEG error: {process.stderr}")
252
- else:
253
- logging.info(process.stdout)
254
- return media_out
255
  else: # not webm
256
  command = ['ffmpeg',
257
  '-y',
@@ -260,13 +251,15 @@ def convert_and_trim_video(media_in, media_out, start=None, end=None):
260
  '-c','copy',
261
  media_out,
262
  '-hide_banner', '-loglevel', 'warning']
263
- logging.info(f"FFMPEG command: {' '.join(command)}")
264
- process = subprocess.run(command, check=True)
265
- if process.returncode != 0:
266
- logging.info(f"FFMPEG error: {process.stderr}")
267
- else:
268
- logging.info(process.stdout)
269
- return media_out
 
 
270
 
271
  except Exception as e:
272
  logging.error(f"Error converting video format: {e}")
 
214
  logging.info(f'...Using ffmpeg to convert {in_ext} to {out_ext}...')
215
 
216
  if out_ext == '.wav':
217
+ if in_ext == '.webm':
218
+ command = ['ffmpeg', '-i', media_in, *trim_command, media_out,
219
+ '-hide_banner', '-loglevel', 'warning']
220
+
221
+ else:
222
+ # convert to wav with standard format for audio models
223
+ command = [
224
+ 'ffmpeg',
225
+ "-f", "s16le",
226
+ '-y',
227
+ '-i', media_in,
228
+ *trim_command,
229
+ '-vn',
230
+ '-acodec', 'pcm_s16le',
231
+ '-ac', str(WAV_CHANNELS),
232
+ '-ar', str(WAV_SAMPLE_RATE),
233
+ media_out,
234
+ '-hide_banner', '-loglevel', 'warning']
 
 
235
 
236
  else: # convert using copy codec
237
  if in_ext == '.webm':
 
243
  '-acodec', 'aac',
244
  media_out,
245
  '-hide_banner', '-loglevel', 'warning']
 
 
 
 
 
 
 
246
  else: # not webm
247
  command = ['ffmpeg',
248
  '-y',
 
251
  '-c','copy',
252
  media_out,
253
  '-hide_banner', '-loglevel', 'warning']
254
+
255
+ # run the ffmpeg command
256
+ logging.info(f"FFMPEG command: {' '.join(command)}")
257
+ process = subprocess.run(command, capture_output=True, text=True)
258
+ if process.returncode != 0:
259
+ logging.info(f"FFMPEG error: {process.stderr}")
260
+ else:
261
+ logging.info(process.stdout)
262
+ return media_out
263
 
264
  except Exception as e:
265
  logging.error(f"Error converting video format: {e}")