首页 > 解决方案 > python for loop result in ffmpeg command

问题描述

hi im trying to insert for loop results in a ffmpeg command i tried some code but all i get is first text with no sound and it glitches and freezes i tried many modification but no success i appreciate if you have any ideas that would be great, the imported text from api should display only the duration of audio file here is my code:


import requests
import json
import os
import requests
import http.client
import io
import subprocess


response = requests.get('http://api.quran.com:3000/api/v3/chapters/2/verses?text_type=image&language=ar&recitation=10')

json = json.loads(response.content)

data= json['verses']
#print(data)

for i in data:
    input_text = i['text_madani'] 
    input_duration = i['audio']['duration'] 
    input_mp3 = i['audio']['url']
    input_img = i['image']['url']
 #   print(input_duration)
    command = f'''ffmpeg -re -stream_loop -1 \
                    -i img2.jpeg \
                    -i {input_mp3} \
                    -vf 'pad=ceil(iw/2)*2:ceil(ih/2)*2,drawtext=enable='between(t, n, {input_duration})':text={input_text}:fontsize=90:x=50:y=50:fontcolor=black@0.8' \
                    -c:v libx264 -preset veryfast -b:v 3000k \
                    -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 50 \
                    -c:a aac -b:a 160k \
                    -ac 2 -ar 44100 \
                    -y -f flv rtmp://localhost/hls/test''' 
    print(command)
    os.system(command)

标签: pythonpython-3.xffmpegvideo-streaming

解决方案


推荐阅读