-
-
Notifications
You must be signed in to change notification settings - Fork 51
Use ffmpeg for live #4
Comments
With some adaptation yes, it's possible, it's not super friendly but will works, try this: import json
import subprocess
from ItsAGramLive import ItsAGramLive
FILE_PATH = "/path/to/the/file/you/want/to/streaming"
live = ItsAGramLive()
broadcast_id = live.create_broadcast()
ffmpeg_cmd = "ffmpeg -rtbufsize 256M -re -i '{file}' -acodec libmp3lame -ar 44100 -b:a 128k -pix_fmt yuv420p " \
"-profile:v baseline -s 720x1280 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -vcodec libx264 " \
"-preset veryfast -g 30 -r 30 -f flv '{stream_url}'" \
.format(file=FILE_PATH, stream_url=live.LastJson['upload_url'])
data = json.dumps({'_uuid': live.uuid,
'_uid': live.username_id,
'should_send_notifications': int(live.sendNotification),
'_csrftoken': live.token})
if live.send_request(endpoint='live/' + str(broadcast_id) + '/start/', post=live.generate_signature(data)):
print('CTRL+C to quit.')
try:
while True:
subprocess.call(ffmpeg_cmd, shell=True)
except KeyboardInterrupt:
pass
except Exception as error:
print(error)
live.end_broadcast(broadcast_id)
and run
|
Thank you very much for your attention to this feature. When I run "python3 ffmpegmyfile.py -u Username -p Password"
|
Are you using the last version? |
Are you using the last version? Yes I think it showed this error because it login several times. |
Question: do you clone the project here or are you using pip? I did a small modification, try again with this code: import json
import subprocess
from ItsAGramLive import ItsAGramLive
FILE_PATH = "/path/to/the/file/you/want/to/streaming"
live = ItsAGramLive()
broadcast_id = live.create_broadcast()
ffmpeg_cmd = "ffmpeg -rtbufsize 256M -re -i '{file}' -acodec libmp3lame -ar 44100 -b:a 128k -pix_fmt yuv420p " \
"-profile:v baseline -s 720x1280 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -vcodec libx264 " \
"-preset veryfast -g 30 -r 30 -f flv '{stream_url}'" \
.format(file=FILE_PATH, stream_url=live.LastJson['upload_url'])
data = json.dumps({'_uuid': live.uuid,
'_uid': live.username_id,
'should_send_notifications': int(live.sendNotification),
'_csrftoken': live.token})
if live.send_request(endpoint='live/' + str(broadcast_id) + '/start/', post=live.generate_signature(data)):
print('CTRL+C to quit.')
try:
subprocess.call(ffmpeg_cmd, shell=True)
except KeyboardInterrupt:
pass
except Exception as error:
print(error)
live.end_broadcast(broadcast_id) |
Question: do you clone the project here or are you using pip? pip |
The code I put below is code for live stream via Instagram with FFmpeg and php (mgp25/Instagram-API) `<?php set_time_limit(0); require DIR.'/../vendor/autoload.php'; /////// CONFIG /////// /////// MEDIA //////// $ig = new \InstagramAPI\Instagram($debug, $truncatedDebug); try { try {
} catch (\Exception $e) { |
There is no reason to login several times, the code it's working fine for me.
|
import json from ItsAGramLive import ItsAGramLive FILE_PATH = "1.mp4" live = ItsAGramLive() broadcast_id = live.create_broadcast() ffmpeg_cmd = "ffmpeg -rtbufsize 256M -re -i '{file}' -vf 'transpose=1' -acodec libmp3lame -ar 44100 -b:a 128k -pix_fmt yuv420p " data = json.dumps({'_uuid': live.uuid, if live.send_request(endpoint='live/' + str(broadcast_id) + '/start/', post=live.generate_signature(data)):
|
c:>pip -V |
Sorry, I did a mistake when I ask for The corret is: |
c:>pip show ItsAGramLive |
Sorry Try to check the spaces of your code one last time, maybe debugging line by line (I recommend PyCharm) As a last resort open a question on the stackoverflow. |
Thank a lot for your efforts |
No, the point is: I'm not able to reproduce your error/results and it's working for me 乁( •_• )ㄏ |
Thank a lot |
From #26 - @harrypython, is it possible to update this python script in order to stream using ffmpeg cli? I know you said that it's better to create 2 separate processes for this but in my case I can only do it using bash, but I think I will have an issue getting the Key (the only thing I need) since your tool calls an interactive CLI... By the time my bash script extracts the Key, it might leave the IG session and the Key won't be valid anymore (?) |
How to add code to the following simple script in order to just print the Server Key?
For example, I just need
|
`import json from ItsAGramLive import ItsAGramLive FILE_PATH = "/path/to/the/file/you/want/to/streaming" live = ItsAGramLive() broadcast_id = live.create_broadcast() ffmpeg_cmd = "ffmpeg -rtbufsize 256M -re -i '{file}' -acodec libmp3lame -ar 44100 -b:a 128k -pix_fmt yuv420p " data = json.dumps({'_uuid': live.uuid, if live.send_request(endpoint='live/' + str(broadcast_id) + '/start/', post=live.generate_signature(data)):
version 1.4.1 does not work. |
I put an example in the readme, let me know if works |
-deinterlace in FFmpeg is deprecated |
The following code is related to the live stream of the file using ffmpeg via LevPasha/Instagram-API-python.
LevPasha/Instagram-API-python is dead!
Can you look at it and add this feature to your beautiful code?
Thanks a lot
Sincerely
`#!/usr/bin/env python
-- coding: utf-8 --
Use text editor to edit the script and type in valid Instagram username/password
import subprocess
from InstagramAPI import InstagramAPI
USERNAME = ''
PASSWORD = ''
FILE_PATH = ''
PUBLISH_TO_LIVE_FEED = False
SEND_NOTIFICATIONS = False
api = InstagramAPI(USERNAME, PASSWORD, debug=False)
assert api.login()
first you have to create a broadcast - you will receive a broadcast id and an upload url here
assert api.createBroadcast()
broadcast_id = api.LastJson['broadcast_id']
upload_url = api.LastJson['upload_url']
we now start a boradcast - it will now appear in the live-feed of users
assert api.startBroadcast(broadcast_id, sendNotification=SEND_NOTIFICATIONS)
ffmpeg_cmd = "ffmpeg -rtbufsize 256M -re -i '{file}' -acodec libmp3lame -ar 44100 -b:a 128k -pix_fmt yuv420p -profile:v baseline -s 720x1280 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -vcodec libx264 -preset veryfast -g 30 -r 30 -f flv '{stream_url}'".format(
file=FILE_PATH,
stream_url=upload_url,
)
print("Hit Ctrl+C to stop broadcast")
try:
subprocess.call(ffmpeg_cmd, shell=True)
except KeyboardInterrupt:
print('Stop Broadcasting')
assert api.stopBroadcast(broadcast_id)
print('Finished Broadcast')
if PUBLISH_TO_LIVE_FEED:
api.addBroadcastToLive(broadcast_id)
print('Added Broadcast to LiveFeed')
`
The text was updated successfully, but these errors were encountered: