Skip to content

Commit

Permalink
Added: ability to make first audio you send as primary
Browse files Browse the repository at this point in the history
  • Loading branch information
yashoswalyo authored Sep 5, 2022
1 parent 34aa73c commit f6efbda
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions helpers/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async def MergeSub(filePath: str, subPath: str, user_id):
subTrack += 1
LOGGER.info("Sub muxing")
subprocess.call(
f"ffmpeg -hide_banner {input_files}-map 0:v:0 -map 0:a -map 0:s? {maps}{metadata}-c:v copy -c:a copy -c:s srt './downloads/{str(user_id)}/[@yashoswalyo]_softmuxed_video.mkv' ",
f"ffmpeg -hide_banner {input_files}-map 0:v:0 -map 0:a:? -map 0:s:? {maps}{metadata}-c:v copy -c:a copy -c:s srt './downloads/{str(user_id)}/[@yashoswalyo]_softmuxed_video.mkv' ",
shell=True,
)
orgFilePath = shutil.move(
Expand Down Expand Up @@ -126,7 +126,7 @@ def MergeSubNew(filePath: str, subPath: str, user_id, file_list):
subTrack += 1
LOGGER.info("Sub muxing")
subprocess.call(
f"ffmpeg -hide_banner {input_files}-map 0:v:0 -map 0:a -map 0:s? {maps}{metadata}-c:v copy -c:a copy -c:s srt './downloads/{str(user_id)}/[@yashoswalyo]_softmuxed_video.mkv'",
f"ffmpeg -hide_banner {input_files}-map 0:v:0 -map 0:a:? -map 0:s:? {maps}{metadata}-c:v copy -c:a copy -c:s srt './downloads/{str(user_id)}/[@yashoswalyo]_softmuxed_video.mkv'",
shell=True,
)
return f"./downloads/{str(user_id)}/[@yashoswalyo]_softmuxed_video.mkv"
Expand All @@ -137,19 +137,21 @@ def MergeAudio(videoPath:str,files_list:list,user_id):
inputfiles = ""
maps = ""
metadata = ""
rmDispositions = ""
videoData = ffmpeg.probe(filename=videoPath)
videoStreamsData = videoData.get("streams")
audioTracks = 0
for i in range(len(videoStreamsData)):
if videoStreamsData[i]["codec_type"] == "audio":
rmDispositions += f"-disposition:a:{audioTracks} 0 "
audioTracks+=1
for i in files_list:
inputfiles += f"-i '{i}' "
for j in range(1,len(files_list)):
maps += f"-map {j}:a "
LOGGER.info("Merging files now")
subprocess.call(
f"ffmpeg -hide_banner {inputfiles}-map 0:v:0 -map 0:a:? {maps}-map 0:s:? -c:v copy -c:a copy -c:s copy './downloads/{str(user_id)}/[@yashoswalyo]_export.mkv'",
f"ffmpeg -hide_banner {inputfiles}-map 0:v:0 -map 0:a:? {maps}-map 0:s:? -c:v copy -c:a copy -c:s copy {rmDispositions}-disposition:a:{audioTracks} default './downloads/{str(user_id)}/[@yashoswalyo]_export.mkv'",
shell=True
)
return f"./downloads/{str(user_id)}/[@yashoswalyo]_export.mkv"
Expand Down

0 comments on commit f6efbda

Please sign in to comment.