<p>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:</p>
<pre><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&amp;language=ar&amp;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)
</code></pre>

CC BY-SA 4.0
2020-08-06T01:37:58.640Z
minor nitpick. If you're executing ffmpeg on the command line like you are, you don't need to import ffmpeg from your code.
WyattBlue
CC BY-SA 4.0
2020-08-06T07:29:01.207Z
thanks i did not see the import but i'm using the command for now not python module
madiha bout
CC BY-SA 4.0
2020-08-09T06:06:54.107Z
It should be a ffmpeg command to stream loop contents instead of commands of breaking rtmp connection
xer-rex
CC BY-SA 4.0
2020-08-09T16:13:24.550Z
would plz explain more i think i'm using an ffmpeg command with loop option
madiha bout
CC BY-SA 4.0
2020-08-10T03:52:01.630Z
Idea attributes to https://trac.ffmpeg.org/wiki/Concatenate
xer-rex
<ffmpeg><streaming>
python for loop result in ffmpeg command
madiha bout
# python for loop result in ffmpeg command

(Asked by: username_0 on 2020-08-05)

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)

**Tags:** ffmpeg, streaming

> **Comments:**
> **username_1**: minor nitpick. If you're executing ffmpeg on the command line like you are, you don't need to import ffmpeg from your code.  
> **username_0**: thanks i did not see the import but i'm using the command for now not python module  
> **username_2**: It should be a ffmpeg command to stream loop contents instead of commands of breaking rtmp connection  
> **username_0**: would plz explain more i think i'm using an ffmpeg command with loop option  
> **username_2**: Idea attributes to https://trac.ffmpeg.org/wiki/Concatenate  

---

## 0 answers

