
Recherche avancée
Médias (16)
-
#7 Ambience
16 octobre 2011, par
Mis à jour : Juin 2015
Langue : English
Type : Audio
-
#6 Teaser Music
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#5 End Title
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#3 The Safest Place
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#4 Emo Creates
15 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#2 Typewriter Dance
15 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
Autres articles (20)
-
Publier sur MédiaSpip
13 juin 2013Puis-je poster des contenus à partir d’une tablette Ipad ?
Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir -
Librairies et logiciels spécifiques aux médias
10 décembre 2010, parPour un fonctionnement correct et optimal, plusieurs choses sont à prendre en considération.
Il est important, après avoir installé apache2, mysql et php5, d’installer d’autres logiciels nécessaires dont les installations sont décrites dans les liens afférants. Un ensemble de librairies multimedias (x264, libtheora, libvpx) utilisées pour l’encodage et le décodage des vidéos et sons afin de supporter le plus grand nombre de fichiers possibles. Cf. : ce tutoriel ; FFMpeg avec le maximum de décodeurs et (...) -
Pas question de marché, de cloud etc...
10 avril 2011Le vocabulaire utilisé sur ce site essaie d’éviter toute référence à la mode qui fleurit allègrement
sur le web 2.0 et dans les entreprises qui en vivent.
Vous êtes donc invité à bannir l’utilisation des termes "Brand", "Cloud", "Marché" etc...
Notre motivation est avant tout de créer un outil simple, accessible à pour tout le monde, favorisant
le partage de créations sur Internet et permettant aux auteurs de garder une autonomie optimale.
Aucun "contrat Gold ou Premium" n’est donc prévu, aucun (...)
Sur d’autres sites (5698)
-
How to use hardware acceleration for ffmpeg [closed]
11 mars 2024, par Kevin GilbertI am try to get hardware acceleration going on my Dell Inspiron AMD laptop. It appears that
vaapi
is installed but how to I use it inffmpeg
?

For testing, all I want is to accelerate


ffmpeg -i input.ts output.mp4



Currently, the unaccelerated command I am currently using is


ffmpeg -y -i input.ts -c:v libx264 -preset slower -tune film -filter_complex scale=1080:608 -sws_flags lanczos output.mp4



BTW : Environment is fully up-to-date Fedora 39 with stock
ffmpeg
.

-
Ffmpeg encoding too slow
8 mars 2024, par Marc CuadrasI'm using a Python script to encode mp4 videos in various qualities, in my case 360 +720 +1080.
Ffmpeg encoding videos very slow, 1 video taking 2 hours or more, I'm using good dedicated server from hetzner (ryzen 5 3600 + 64gm ram), any suggestion to improve speed will be really appreciated


import os
import glob
from datetime import datetime
import subprocess
from rich import print
import time
import sys
import pymysql as sql
import move

MYSQL_HOST = "127.0.0.1"
MYSQL_USER = ""
MYSQL_PASSWORD = ""
MYSQL_DB = ""

BASE_PATH = ''
UPLOAD_PATH = os.path.join(BASE_PATH, 'upload')
UPLOAD_PATH2 = os.path.join(BASE_PATH, 'upload2')
VIDEO_PATH = os.path.join(BASE_PATH, 'video')
LOGO_PATH = os.path.join(BASE_PATH, 'logo.png')
ERROR_PATH = os.path.join(BASE_PATH, 'error')
RCLONE_PATH = os.path.join(BASE_PATH, 'rclone')
WAIT = 60
VIDEO_LENGTH = 10
MOVE_CMD = "screen -dmS move python3 move.py --folder {}"

global current_video_id

db = sql.connect(
 host=MYSQL_HOST,
 user=MYSQL_USER,
 password=MYSQL_PASSWORD,
 database=MYSQL_DB
 )

def executedb(query):
 cursor = db.cursor()
 cursor.execute(query)
 db.commit()

def time_now():
 now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
 return now

def write_log(msg):
 log_msg = f"{time_now()}: {msg}"
 with open('log.txt','a') as f:
 f.write(log_msg)
 f.write('\n')

def change_extension(files):
 for file in files:
 os.rename(file, file.split('.')[0] + '.mkv')

def change_all_videos_extension():
 # changing all the vidoe's extension to mkv format
 MKV_files = glob.glob('*.MKV')
 AVI_files = glob.glob('*.AVI')
 avi_files = glob.glob('*.avi')
 MP4_files = glob.glob('*.MK4')
 mp4_files = glob.glob('*.mp4')
 webm_files = glob.glob('*.webm')
 ts_files = glob.glob('*.ts')

 if len(avi_files) > 0:
 print(f'[{time_now()}] Converting avi videos to mkv format')
 change_extension(avi_files)

 if len(MKV_files) > 0:
 print(f'[{time_now()}] Converting MKV videos to mkv format')
 change_extension(MKV_files)

 if len(AVI_files) > 0:
 print(f'[{time_now()}] Converting AVI videos to mkv format')
 change_extension(AVI_files)

 if len(MP4_files) > 0:
 print(f'[{time_now()}] Converting MP4 videos to mkv format')
 change_extension(MP4_files)

 if len(mp4_files) > 0:
 print(f'[{time_now()}] Converting mp4 videos to mkv format')
 change_extension(mp4_files)

 if len(webm_files) > 0:
 print(f'[{time_now()}] Converting webm videos to mkv format')
 change_extension(webm_files)

 if len(ts_files) > 0:
 print(f'[{time_now()}] Converting ts videos to mkv format')
 change_extension(ts_files)
 
def encode_480(filename):
 FILENAME_PATH = filename
 newname = filename.split('.')[0]
 newname_path = os.path.join(VIDEO_PATH, newname)

 poster_cmd = f'ffmpeg -y -ss 00:00:10 -i {FILENAME_PATH} -vframes 1 -q:v 2 poster.jpg'
 os.system(poster_cmd)
 
 if not os.path.exists(newname_path):
 os.mkdir(newname_path)

 os.replace('poster.jpg', os.path.join(newname_path, 'poster.jpg'))
 

 ffmpeg480_cmd = f'ffmpeg -hide_banner -y -i {FILENAME_PATH} -sn -c:a aac -ac 2 -c:v libx264 -crf 23 -preset fast -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -maxrate 1024k -bufsize 1536k -b:a 128k -pix_fmt yuv420p -hls_segment_filename 4835JRK9%03d.ts 480p.m3u8'
 os.system(ffmpeg480_cmd)
 
 # os.remove(FILENAME_PATH)
 
 ts_files = glob.glob('*.ts')
 for ts_file in ts_files:
 os.replace(ts_file, os.path.join(newname_path, ts_file))
 
 master_text = '''#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=1500000,RESOLUTION=854x480
480p.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=840000,RESOLUTION=640x360
360p.m3u8
'''
 with open('master.m3u8', 'w') as f:
 f.write(master_text)
 
 m3u8_files = glob.glob('*.m3u8')
 for m3u8_file in m3u8_files:
 os.replace(m3u8_file, os.path.join(newname_path, m3u8_file))


def encode_360(filename):
 FILENAME_PATH = filename
 newname = filename.split('.')[0]
 newname_path = os.path.join(VIDEO_PATH,newname)
 poster_cmd = f'ffmpeg -y -ss 00:00:10 -i {FILENAME_PATH} -vframes 1 -q:v 2 poster.jpg'
 os.system(poster_cmd)
 if not os.path.exists(newname_path):
 os.mkdir(newname_path)
 os.replace('poster.jpg',os.path.join(newname_path, 'poster.jpg'))

 
 ffmpeg360_cmd = f'ffmpeg -hide_banner -y -i {FILENAME_PATH} -sn -c:a aac -ac 2 -c:v libx264 -crf 23 -preset fast -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -maxrate 512k -bufsize 768k -b:a 128k -pix_fmt yuv420p -hls_segment_filename 365RL6TJ%03d.ts 360p.m3u8'
 os.system(ffmpeg360_cmd)
 # return
 
 
 ts_files = glob.glob('*.ts')
 for ts_file in ts_files:
 os.replace(ts_file, os.path.join(newname_path,ts_file))
 master_text = '''#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=840000,RESOLUTION=640x360
360p.m3u8
 '''
 with open('master.m3u8', 'w') as f:
 f.write(master_text)
 m3u8_files = glob.glob('*.m3u8')
 for m3u8_file in m3u8_files:
 os.replace(m3u8_file, os.path.join(newname_path, m3u8_file))


def encode_720(filename):
 FILENAME_PATH = filename
 newname = filename.split('.')[0]
 newname_path = os.path.join(VIDEO_PATH,newname)
 poster_cmd = f'ffmpeg -y -ss 00:00:10 -i {FILENAME_PATH} -vframes 1 -q:v 2 poster.jpg'
 os.system(poster_cmd)

 if not os.path.exists(newname_path):
 os.mkdir(newname_path)

 os.replace('poster.jpg',os.path.join(newname_path, 'poster.jpg'))

 ffmpeg720_cmd = f'ffmpeg -hide_banner -y -i {FILENAME_PATH} -sn -c:a aac -ac 2 -c:v libx264 -crf 23 -preset fast -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -maxrate 2048k -bufsize 3072k -b:a 160k -pix_fmt yuv420p -hls_segment_filename 7269TKL0%03d.ts 720p.m3u8'
 os.system(ffmpeg720_cmd)

 # os.remove(FILENAME_PATH)

 ts_files = glob.glob('*.ts')
 for ts_file in ts_files:
 os.replace(ts_file, os.path.join(newname_path,ts_file))
 
 m3u8_text = '''#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=2800000,RESOLUTION=1280x720
720p.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=840000,RESOLUTION=640x360
360p.m3u8 
 '''

 with open('master.m3u8','w') as f:
 f.write(m3u8_text)
 
 m3u8_files = glob.glob('*.m3u8')
 for m3u8_file in m3u8_files:
 os.replace(m3u8_file, os.path.join(newname_path,m3u8_file)) 


def encode_1080(filename):
 FILENAME_PATH = filename
 newname = filename.split('.')[0]
 newname_path = os.path.join(VIDEO_PATH, newname)
 poster_cmd = f'ffmpeg -y -ss 00:00:10 -i {FILENAME_PATH} -vframes 1 -q:v 2 poster.jpg'
 os.system(poster_cmd)

 if not os.path.exists(newname_path):
 os.mkdir(newname_path)

 os.replace('poster.jpg', os.path.join(newname_path, 'poster.jpg'))

 ffmpeg1080_cmd = f'ffmpeg -hide_banner -y -i {FILENAME_PATH} -sn -c:a aac -ac 2 -c:v libx264 -crf 23 -preset fast -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -maxrate 4000k -bufsize 6000k -b:a 192k -pix_fmt yuv420p -hls_segment_filename 108YUT8T%03d.ts 1080p.m3u8'
 os.system(ffmpeg1080_cmd)

 # os.remove(FILENAME_PATH)

 ts_files = glob.glob('*.ts')
 for ts_file in ts_files:
 os.replace(ts_file, os.path.join(newname_path, ts_file))

 m3u8_text = '''#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=4000000,RESOLUTION=1920x1080
1080p.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2800000,RESOLUTION=1280x720
720p.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=840000,RESOLUTION=640x360
360p.m3u8
'''

 with open('master.m3u8', 'w') as f:
 f.write(m3u8_text)

 m3u8_files = glob.glob('*.m3u8')
 for m3u8_file in m3u8_files:
 os.replace(m3u8_file, os.path.join(newname_path, m3u8_file))



def vod(filename, resolution):
 os.replace(filename,filename.replace(' ','_'))
 filename = filename.replace(' ','_')
 FILENAME_PATH = filename
 width_cmd = f'ffprobe -v error -select_streams v:0 -show_entries stream=width -of default=nw=1:nk=1 {FILENAME_PATH}'
 height_cmd= f'ffprobe -v error -select_streams v:0 -show_entries stream=height -of default=nw=1:nk=1 {FILENAME_PATH}'

 width_result = subprocess.run(width_cmd.split(), stdout=subprocess.PIPE)
 width = width_result.stdout.strip().decode('utf-8')

 height_result = subprocess.run(height_cmd.split(), stdout=subprocess.PIPE)
 height = height_result.stdout.strip().decode('utf-8')

 if not os.path.exists(VIDEO_PATH):
 os.mkdir(VIDEO_PATH)

 if resolution == 360: 
 write_log(f'Encoding {filename} in 360p') 
 encode_360(filename)

 if resolution == 720 :
 if int(height) >=400 :
 if int(height) <= 700:
 query = f"""UPDATE videos SET encoding_status = 'encoding480' WHERE file_uid LIKE '%{filename.replace(".mkv","")}'"""
 executedb(query)
 write_log(f'Encoding {filename} in 480p')
 encode_480(filename) 
 query = f"""UPDATE videos SET encoding_status = 'done480' WHERE file_uid LIKE '%{filename.replace(".mkv","")}'"""
 executedb(query)
 query = f"""UPDATE videos SET quality = 2 WHERE file_uid LIKE '%{filename.replace(".mkv","")}'"""
 executedb(query)
 else:
 if int(height) >= 800:
 query = f"""UPDATE videos SET encoding_status = 'encoding720' WHERE file_uid LIKE '%{filename.replace(".mkv","")}'"""
 executedb(query)
 write_log(f'Encoding {filename} in 720p')
 encode_720(filename) 
 query = f"""UPDATE videos SET encoding_status = 'done720' WHERE file_uid LIKE '%{filename.replace(".mkv","")}'"""
 executedb(query)
 query = f"""UPDATE videos SET quality = 3 WHERE file_uid LIKE '%{filename.replace(".mkv","")}'"""
 executedb(query)
 query = f"""UPDATE videos SET encoding_status = 'encoding1080' WHERE file_uid LIKE '%{filename.replace(".mkv","")}'"""
 executedb(query)
 write_log(f'Encoding {filename} in 720p')
 encode_1080(filename) 
 query = f"""UPDATE videos SET encoding_status = 'done1080' WHERE file_uid LIKE '%{filename.replace(".mkv","")}'"""
 executedb(query)
 query = f"""UPDATE videos SET quality = 4 WHERE file_uid LIKE '%{filename.replace(".mkv","")}'"""
 executedb(query)
 else:
 query = f"""UPDATE videos SET encoding_status = 'encoding720' WHERE file_uid LIKE '%{filename.replace(".mkv","")}'"""
 executedb(query)
 write_log(f'Encoding {filename} in 720p')
 encode_720(filename) 
 query = f"""UPDATE videos SET encoding_status = 'done720' WHERE file_uid LIKE '%{filename.replace(".mkv","")}'"""
 executedb(query)
 query = f"""UPDATE videos SET quality = 3 WHERE file_uid LIKE '%{filename.replace(".mkv","")}'"""
 executedb(query)
 
 
 
 os.remove(filename)


def move_to_rclone():
 if not os.path.exists(RCLONE_PATH):
 os.mkdir(RCLONE_PATH)
 folders = os.listdir(VIDEO_PATH)
 if len(folders) > 0:
 for folder in folders:
 folder_in_rclone = os.path.join(RCLONE_PATH, folder)
 if not os.path.exists(folder_in_rclone):
 os.mkdir(folder_in_rclone)
 files = os.listdir(os.path.join(VIDEO_PATH, folder))
 for file in files:
 os.replace(os.path.join(VIDEO_PATH, folder, file), os.path.join(folder_in_rclone, file))
 os.system(MOVE_CMD.format(folder_in_rclone))
 if len(os.listdir(os.path.join(VIDEO_PATH, folder))) == 0:
 os.rmdir(os.path.join(VIDEO_PATH, folder))
 # rclone_folders = os.listdir(RCLONE_PATH)
 # if len(rclone_folders)> 0:
 # for rclone_folder in rclone_folders:
 # os.system(MOVE_CMD.format(rclone_folder))

def get_length(input_video):
 result = subprocess.run(['ffprobe', '-v', 'error', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', input_video], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
 try:
 output = float(result.stdout)
 except:
 output = 0
 return output

def move_to_error(file):
 if not os.path.exists(ERROR_PATH):
 os.mkdir(ERROR_PATH)
 print(f'[red][-][/red] Moving {file} to the error folder')
 os.replace(file, os.path.join(ERROR_PATH, file.split('/')[-1]))

def main():
 db = sql.connect(
 host=MYSQL_HOST,
 user=MYSQL_USER,
 password=MYSQL_PASSWORD,
 database=MYSQL_DB
 )

 def get_video_data(file_uid):
 cursor = db.cursor()
 query = f"""SELECT id, post_title, file_uid, group_id FROM videos WHERE file_uid LIKE %s"""
 cursor.execute(query, (f'%{file_uid}%',))
 data = cursor.fetchone()
 return data if data else None
 
 if os.path.exists(UPLOAD_PATH):
 upload_files = os.listdir(UPLOAD_PATH)
 upload_files = [os.path.join(UPLOAD_PATH, x) for x in upload_files]
 upload_files.sort(key=lambda x: os.path.getmtime(x))
 else:
 upload_files = []

 if len(upload_files) > 0:
 for upload_file in upload_files:
 if get_length(upload_file) < VIDEO_LENGTH:
 move_to_error(upload_file)
 write_log(f'Length of {upload_file} is less than 60 sec. Moving to error folder')
 continue
 try:
 os.replace(upload_file, upload_file.split('/')[-1])
 query = f"""UPDATE videos SET encoding_status = 'uploaded' WHERE file_uid LIKE '%{upload_file.replace(".mkv","").replace(".mp4","")}'"""
 executedb(query)
 except:
 print(e)
 continue
 change_all_videos_extension()

 mkv_files = glob.glob('*.mkv')
 if len(mkv_files) > 0:
 for mkv_file in mkv_files:
 try:
 query = f"""UPDATE videos SET encoding_status = 'encoding360' WHERE file_uid LIKE '%{mkv_file.replace(".mkv","")}'"""
 executedb(query)
 vod(mkv_file, 360)
 query = f"""UPDATE videos SET encoding_status = 'done360' WHERE file_uid LIKE '%{mkv_file.replace(".mkv","")}'"""
 executedb(query)
 query = f"""UPDATE videos SET quality = 1 WHERE file_uid LIKE '%{mkv_file.replace(".mkv","")}'"""
 executedb(query)

 
 vod(mkv_file, 720)
 
 except Exception as e:
 query = f"""UPDATE videos SET encoding_status = 'error' WHERE file_uid LIKE '%{mkv_file.replace(".mkv","")}'"""
 executedb(query)
 video_data = get_video_data(
 mkv_file.replace(".mkv", ""))
 if video_data:
 cursor = db.cursor()
 video_id, video_title, video_uid, group_id = video_data
 error_log_query = f"""INSERT INTO error_logs (video_id, video_title, video_uid, group_id, log, created_at, updated_at) 
 VALUES (%s, %s, %s, %s, %s, NOW(), NOW())"""
 cursor.execute(
 error_log_query, (video_id, video_title, video_uid, group_id, str(e)))
 db.commit()
 write_log(f'Error: {e}')
 move_to_error(mkv_file)
 move_to_rclone()
 else:
 print(f'[{time_now()}] No new video found on upload folder')

 if os.path.exists(UPLOAD_PATH2):
 upload_files2 = os.listdir(UPLOAD_PATH2)
 upload_files2 = [os.path.join(UPLOAD_PATH2, x) for x in upload_files2]
 upload_files2.sort(key=lambda x: os.path.getmtime(x))
 else:
 upload_files2 = []

 if len(upload_files2) > 0:
 for upload_file2 in upload_files2:
 if get_length(upload_file2) < VIDEO_LENGTH:
 move_to_error(upload_file2)
 continue
 if len(os.listdir(UPLOAD_PATH)) != 0:
 main()
 try:
 os.replace(upload_file2, upload_file2.split('/')[-1])
 query = f"""UPDATE videos SET encoding_status = 'uploaded' WHERE file_uid LIKE '%{upload_file2.replace(".mkv","").replace(".mp4","")}'"""
 executedb(query)
 except:
 continue

 change_all_videos_extension()

 mkv_files = glob.glob('*.mkv')
 if len(mkv_files) > 0:
 for mkv_file in mkv_files:
 try:
 query = f"""UPDATE videos SET encoding_status = 'encoding360' WHERE file_uid LIKE '%{mkv_file.replace(".mkv","")}'"""
 executedb(query)
 vod(mkv_file, 360)
 query = f"""UPDATE videos SET encoding_status = 'done360' WHERE file_uid LIKE '%{mkv_file.replace(".mkv","")}'"""
 executedb(query)
 query = f"""UPDATE videos SET quality = 1 WHERE file_uid LIKE '%{mkv_file.replace(".mkv","")}'"""
 executedb(query)


 vod(mkv_file, 720)

 except Exception as e:
 query = f"""UPDATE videos SET encoding_status = 'error' WHERE file_uid LIKE '%{mkv_file.replace(".mkv","")}'"""
 executedb(query)
 video_data = get_video_data(
 mkv_file.replace(".mkv", ""))
 if video_data:
 cursor = db.cursor()
 video_id, video_title, video_uid, group_id = video_data
 error_log_query = f"""INSERT INTO error_logs (video_id, video_title, video_uid, group_id, log, created_at, updated_at) 
 VALUES (%s, %s, %s, %s, %s, NOW(), NOW())"""
 cursor.execute(
 error_log_query, (video_id, video_title, video_uid, group_id, str(e)))
 db.commit()
 write_log(f'Error: {e}')
 move_to_error(mkv_file)
 move_to_rclone()
 else:
 print(f'[{time_now()}] No new video found on upload2 folder.')
 move_to_rclone()
 db.close()

if __name__=="__main__":
 while True:
 try:
 main()
 except Exception as e:
 print(f'Error: {e}')
 for i in range(WAIT):
 print(f'[green][+][/green] Waiting for {WAIT-i} seconds ', end="\r")
 time.sleep(1)





looking for suggestion to improve encoding speed


-
how to get exact position in video as image view ?
16 février 2024, par Dhruvisha JoshiI want to give photo editing feature in my app. so I am allowing user to add text to photo and after that I want to convert it to video using Ffmpeg command.


here is my command that adds text and convert photo to video.

ffmpeg -loop 1 -i /var/mobile/Containers/Data/Application/88F535C3-A300-456C-97BB-1A9B83EAEE7B/Documents/Compress_Picture/input.jpg -filter_complex "[0]scale=1080:trunc(ow/a/2)*2[video0];[video0]drawtext=text='Dyjfyjyrjyfjyfkyfk':fontfile=/private/var/containers/Bundle/Application/DE5C8DAA-4D66-4345-834A-89F8AC19DF9B/Clear Status.app/avenyt.ttf:fontsize=66.55112651646448:fontcolor=#FFFFFF:x=349.92:y=930.051993067591" -c:v libx264 -t 5 -pix_fmt yuv420p -y /var/mobile/Containers/Data/Application/88F535C3-A300-456C-97BB-1A9B83EAEE7B/Documents/Compress_Picture/output0.mp4


here is my swift code to generate command.


var filterComplex = ""
var inputs = ""
var audioIndex = ""

if currentPhotoTextDataArray.contains(where: { $0.isLocation }) {
 // At least one element has isLocation set to true
 // Do something here
 print("There's at least one element with isLocation == true")
 inputs = "-i \(inputPath) -i \(self.locImagePath)"
 audioIndex = "2"
 
 } else {
 // No elements have isLocation == true
 print("No elements have isLocation set to true")
 inputs = "-i \(inputPath)"
 audioIndex = "1"
 }
 
 for (index, textData) in currentPhotoTextDataArray.enumerated() {
 print("x: \(textData.xPosition), y: \(textData.yPosition)")
 let x = (textData.xPosition) * 1080 / self.photoViewWidth
 let y = (textData.yPosition) * 1920 / self.photoViewHeight
 
 let fontSizeForWidth = (textData.fontSize * 1080) / self.photoViewWidth
 let fontSizeForHeight = (textData.fontSize * 1920) / self.photoViewHeight
 print("fontSizeForWidth: \(fontSizeForWidth)")
 print("fontSizeForHeight: \(fontSizeForHeight)")
 
 let fontPath = textData.font.fontPath
 let fontColor = textData.fontColor.toHexOrASS(format: "hex")
 let backColor = textData.backColor?.toHexOrASS(format: "hex")
 print("fontPath: \(fontPath)")
 print("fontColor: \(fontColor)")
 
 let breakedText = self.addBreaks(in: textData.text, with: UIFont(name: textData.font.fontName, size: fontSizeForHeight) ?? UIFont(), forWidth: 1080, padding: Int(x))
 
 if textData.isLocation {
 print("Location is there.")
 
 let textFont = UIFont(name: textData.font.fontName, size: fontSizeForHeight)
 let attributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: textFont ?? UIFont()]
 let size = (textData.text as NSString).size(withAttributes: attributes)
 let textWidth = Int(size.width) + 130
 
 var endTimeLoc = 0.0
 if let audioData = self.audioDataArray.first(where: { $0.photoIndex == mainIndex }) {
 let duration = audioData.audioEndTime - audioData.audioStartTime
 endTimeLoc = duration
 } else {
 endTimeLoc = 5
 }
 
 let layerFilter = "color=color=black@.38:size=\(textWidth)x130[layer0];[video\(index)][layer0]overlay=enable='between(t,0,\(endTimeLoc))':x=\(x):y=(\(y)-(overlay_h/2))[layer1];"
 filterComplex += layerFilter
 let imageFilter = "[1:v]scale=80:80[image];[layer1][image]overlay=enable='between(t,0,\(endTimeLoc))':x=\(x)+10:y=(\(y)-(overlay_h/2))[v\(index)];"
 filterComplex += imageFilter
 
 if index == currentPhotoTextDataArray.count - 1 {
 let textFilter = "[v\(index)]drawtext=text='\(breakedText)':fontfile=\(fontPath):fontsize=\(fontSizeForHeight):fontcolor=\(fontColor):x=(\(x)+100):y=(\(y)-(text_h/2))"
 filterComplex += textFilter
 } else {
 let textFilter = "[v\(index)]drawtext=text='\(breakedText)':fontfile=\(fontPath):fontsize=\(fontSizeForHeight):fontcolor=\(fontColor):x=(\(x)+100):y=(\(y)-(text_h/2))[video\(index + 1)];"
 filterComplex += textFilter
 }
 
 } else {
 
 let textBack = textData.backColor != nil ? ":box=1:boxcolor=\(backColor ?? "")@0.8:boxborderw=25" : ""
 
 if index == currentPhotoTextDataArray.count - 1 {
 let textFilter = "[video\(index)]drawtext=text='\(breakedText)':fontfile=\(fontPath):fontsize=\(fontSizeForHeight):fontcolor=\(fontColor):x=\(x):y=\(y)\(textBack)"
 filterComplex += textFilter
 } else {
 let textFilter = "[video\(index)]drawtext=text='\(breakedText)':fontfile=\(fontPath):fontsize=\(fontSizeForHeight):fontcolor=\(fontColor):x=\(x):y=\(y)\(textBack)[video\(index + 1)];"
 filterComplex += textFilter
 }
 }
 
 }
 
 if let audioData = self.audioDataArray.first(where: { $0.photoIndex == mainIndex }) {
 
 let audioSTime = self.getSTimeAudio(index: mainIndex, secondsPhoto: Int(audioData.audioStartTime))
 let audioETime = self.getETimeAudio(index: mainIndex, secondsPhoto: Int(audioData.audioEndTime))
 let duration = audioData.audioEndTime - audioData.audioStartTime
 
 command = "-loop 1 \(inputs) -ss \(audioSTime) -to \(audioETime) -i \"\(audioData.audioURL.path)\" -filter_complex \"[0]scale=1080:trunc(ow/a/2)*2[video0];\(filterComplex)[final_video]\" -map \"[final_video]\":v -map \(audioIndex):a -c:v libx264 -t \(duration) -pix_fmt yuv420p -y \(outputURL.path)"
 
 } else {
 command = "-loop 1 \(inputs) -filter_complex \"[0]scale=1080:trunc(ow/a/2)*2[video0];\(filterComplex)\" -c:v libx264 -t 5 -pix_fmt yuv420p -y \(outputURL.path)"
 }
 }



I am not getting exact position of text in generated video as added by user. if anyone knows please help me with this.