Open AmirhBrt opened 1 week ago
I finally came up with this solution, but it still can not be run due to empty characters as file names. Anyone has any idea how to fix it properly without using subprocess library commands?
ffmpeg_input = ffmpeg.input(source_file_path)
video_splits = ffmpeg_input.video.split()
audio_splits = ffmpeg_input.audio.asplit()
ffmpeg_outputs = []
for i, quality in enumerate(HLS_QUALITIES):
ffmpeg_outputs.append(
ffmpeg.output(
video_splits[i].filter_(
"scale",
w=quality.width,
h=quality.height,
force_original_aspect_ratio="increase",
),
# Attach the corresponding audio stream
audio_splits[i],
filename="",
**{
# Set the video bitrate
f"b:v:{i}": f"{quality.video_bitrate}k",
# Set the maximum video bitrate
f"maxrate:v:{i}": f"{quality.video_max_rate}k",
# Set the buffer size for video
f"bufsize:v:{i}": f"{quality.buffer_size}k",
# Set the audio bitrate
f"b:a:{i}": f"{quality.audio_bitrate}k",
},
)
)
var_stream_map = " ".join([f"v:{i},a:{i},name:{quality.height}" for i, quality in enumerate(HLS_QUALITIES)])
stream = ffmpeg.merge_outputs(
*ffmpeg_outputs,
ffmpeg_input.output(
f"{destination_file_path}_%v.m3u8",
f="hls",
master_pl_name=f"{output_file_prefix}.m3u8",
ar=48000,
vprofile="main",
crf=20,
sc_threshold=0,
g=48,
keyint_min=48,
hls_time=2,
hls_playlist_type="vod",
hls_flags="independent_segments",
hls_segment_filename=f"{destination_file_path}_%v_%03d.ts",
var_stream_map=f"{var_stream_map}"
),
).overwrite_output()
I want to convert a mp4 file and I am using this command to convert my file to multiple qualities:
How can I convert it to ffmpeg-python?