0

Normally my input has an audio. When I convert my input with following code, the output is muted.

ffmpeg.input("input.webm").filter("scale", force_original_aspect_ratio="decrease", force_divisible_by=2).output(("out.mp4"), vcodec="libx264", r=60, preset='fast').run()

.filter() function causes it and I don't know how to fix it. I want to use filter, but I want to keep the audio same also.

Thank you for your help.

muzak
  • 33
  • 4

2 Answers2

0

You need to inspect the composed ffmpeg command line, but I suspect filter() inserts -filter_complex and -map options which in turn excludes all other streams including audio. You need to add -map 0:a option to the command. I'm not familiar with ffmpeg-python but should be achievable by adding map keyword argument to the output() method. (pure speculation)

If you are OK with alternate package you can try my ffmpegio, which tries to keep its API close to the FFmpeg.

To install

pip install ffmpegio-core

FFmpeg executables must be in the system path (or in one of the prescribed locations, see documentation)

To run your command:

import ffmpegio

ffmpeg.transcode(
    "input.webm",
    "out.mp4",
    vf="scale=force_original_aspect_ratio=decrease:force_divisible_by=2",
    vcodec="libx264", r=60, preset='fast')
kesh
  • 4,515
  • 2
  • 12
  • 20
0

Apply the filter to video (only), and pass the filtered video and the original audio as arguments to output(...):

import ffmpeg

v = ffmpeg.input("input.webm").video.filter("scale", force_original_aspect_ratio="decrease", force_divisible_by=2)
a = ffmpeg.input("input.webm").audio
ffmpeg.output(v, a, "out.mp4", vcodec="libx264", r=60, preset='fast', acodec='aac').overwrite_output().run()

In case you want it in one line:
ffmpeg.output(ffmpeg.input("input.webm").video.filter("scale", force_original_aspect_ratio="decrease", force_divisible_by=2), ffmpeg.input("input.webm").audio, "out.mp4", vcodec="libx264", r=60, preset='fast', acodec='aac').overwrite_output().run()


For getting the equivalent command line, you may add -report global argument, and check the log file:

ffmpeg.output(ffmpeg.input("input.webm").video.filter("scale", force_original_aspect_ratio="decrease", force_divisible_by=2), ffmpeg.input("input.webm").audio, "out.mp4", vcodec="libx264", r=60, preset='fast', acodec='aac').global_args('-report').overwrite_output().run()

According to the log file, the equivalent command line is:

ffmpeg -i input.webm -filter_complex "[0:v]scale=force_divisible_by=2:force_original_aspect_ratio=decrease[s0]" -map "[s0]" -map 0:a -acodec aac -preset fast -r 60 -vcodec libx264 out.mp4 -report -y

As you can see, -filter_complex is used, the filtered video is mapped with -map "[s0]" and the audio is mapped with -map 0:a.

Rotem
  • 30,366
  • 4
  • 32
  • 65