Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
FFmpeg RTSP + RTMP get errors
19 décembre 2017, par Akim BenchihaI'm working with live streaming on nginx. What I have is a RTSP (broadcast video) stream coming from a server and a RTMP stream coming from camera. I combine them using ffmpeg. I want to send a bool to the back-end using cURL when RTMP has been stopped or if RTSP is not found/stopped
Here the use case: -Send false to the back-end when the user stop recording the video (RTSP) -Send false to the back-end when the user stop the camera (RTMP) -Send true if everything is ok
NGINX config:
rtmp { server { listen 1935; ping 30s; notify_method get; application ingest { live on; exec_kill_signal term; idle_streams off; exec_push /usr/local/bin/ffmpeg_push.sh $name ; } } }
FFMPEG
ffmpeg -i $rtspstream -i rtmp://localhost/ingest/$name -ignore_unknown -filter_complex "[0]scale=-1:-1[b];[1]scale=128:128[w];[b][w] overlay=10:10" -vcodec libx264 -x264opts keyint=20:min-keyint=1 -preset ultrafast -c:a aac -f flv rtmp://IPADDRESS/ingest/$streamname 1>>/var/log/ffmpeg/$name.log 2>>/var/log/ffmpeg/$name.log & echo $! > /var/log/ffmpeg/${name}.pid
Thank you
-
UDP streaming using ffmpeg container webm
19 décembre 2017, par P AkhtarIs there possible to stream webm container stream on udp://@127.0.0.1:1234 I found below error
avformat_alloc_output_context2(&oc, NULL, "webm", filename);
while receiving its give error invalid data found when processing input.
avformat_alloc_output_context2(&oc, NULL, "mpegts", filename);
while receiving this it work fine
-
ffmpeg shared libraries setup on visual studio 2013
19 décembre 2017, par Hyun JungSetting up ffmpeg shared libraries that are downloaded from ffmpeg zenaroe (https://ffmpeg.zeranoe.com/builds/) for windows_64bit. The IDE is VS2013.
I downloaded dev and shared build for windows 64bit.
And followed steps like bellow but when building, linker error happens. The object file is created so compiling seems done. But there seems to be a problem finding referenced functions at the linking stage.
- Create win32 project and main.cpp
- Copy ffmpeg_dev's include and lib folders to solution directory.
- Open project properties and add the include dir and the lib dir.
- Add lib names to linker input.
Build
main.cpp
extern "C"{ #include } int main(void){ av_register_all(); return 0; }
The linker error is:
LNK2019 unresloved external symbol _av_register_all referenced in function _main.
-
Combine Audio and Images in Stream
19 décembre 2017, par SenorContentoI would like to be able to create images on the fly and also create audio on the fly too and be able to combine them together into an rtmp stream (for Twitch or YouTube). The goal is to accomplish this in Python 3 as that is the language my bot is written in. Bonus points for not having to save to disk.
So far, I have figured out how to stream to rtmp servers using ffmpeg by loading a PNG image and playing it on loop as well as loading a mp3 and then combining them together in the stream. The problem is I have to load at least one of them from file.
I know I can use Moviepy to create videos, but I cannot figure out whether or not I can stream the video from Moviepy to ffmpeg or directly to rtmp. I think that I have to generate a lot of really short clips and send them, but I want to know if there's an existing solution.
There's also OpenCV which I hear can stream to rtmp, but cannot handle audio.
A redacted version of an ffmpeg command I have successfully tested with is
ffmpeg -loop 1 -framerate 15 -i ScreenRover.png -i "Song-Stereo.mp3" -c:v libx264 -preset fast -pix_fmt yuv420p -threads 0 -f flv rtmp://SITE-SUCH-AS-TWITCH/.../STREAM-KEY
or
cat Song-Stereo.mp3 | ffmpeg -loop 1 -framerate 15 -i ScreenRover.png -i - -c:v libx264 -preset fast -pix_fmt yuv420p -threads 0 -f flv rtmp://SITE-SUCH-AS-TWITCH/.../STREAM-KEY
I know these commands are not set up properly for smooth streaming, the result manages to screw up both Twitch's and Youtube's player and I will have to figure out how to fix that.
The problem with this is I don't think I can stream both the image and the audio at once when creating them on the spot. I have to load one of them from the hard drive. This becomes a problem when trying to react to a command or user chat or anything else that requires live reactions. I also do not want to destroy my hard drive by constantly saving to it.
As for the python code, what I have tried so far in order to create a video is the following code. This still saves to the HD and is not responsive in realtime, so this is not very useful to me. The video itself is okay, with the one exception that as time passes on, the clock the qr code says versus the video's clock start to spread apart farther and farther as the video gets closer to the end. I can work around that limitation if it shows up while live streaming.
def make_frame(t): img = qrcode.make("Hello! The second is %s!" % t) return numpy.array(img.convert("RGB")) clip = mpy.VideoClip(make_frame, duration=120) clip.write_gif("test.gif",fps=15) gifclip = mpy.VideoFileClip("test.gif") gifclip.set_duration(120).write_videofile("test.mp4",fps=15)
My goal is to be able to produce something along the psuedo-code of
original_video = qrcode_generator("I don't know, a clock, pyotp, today's news sources, just anything that can be generated on the fly!") original_video.overlay_text(0,0,"This is some sample text, the left two are coordinates, the right three are font, size, and color", Times_New_Roman, 12, Blue) original_video.add_audio(sine_wave_generator(0,180,2)) # frequency min-max, seconds # NOTICE - I did not add any time measurements to the actual video itself. The whole point is this is a live stream and not a video clip, so the time frame would be now. The 2 seconds list above is for our psuedo sine wave generator to know how long the audio clip should be, not for the actual streaming library. stream.send_to_rtmp_server(original_video) # Doesn't matter if ffmpeg or some native library
The above example is what I am looking for in terms of video creation in Python and then streaming. I am not trying to create a clip and then stream it later, I am trying to have the program be able to respond to outside events and then update it's stream to do whatever it wants. It is sort of like a chat bot, but with video instead of text.
def track_movement(...): ... return ... original_video = user_submitted_clip(chat.lastVideoMessage) original_video.overlay_text(0,0,"The robot watches the user's movements and puts a blue square around it.", Times_New_Roman, 12, Blue) original_video.add_audio(sine_wave_generator(0,180,2)) # frequency min-max, seconds # It would be awesome if I could also figure out how to perform advance actions such as tracking movements or pulling a face out of a clip and then applying effects to it on the fly. I know OpenCV can track movements and I hear that it can work with streams, but I cannot figure out how that works. Any help would be appreciated! Thanks!
Because I forgot to add the imports, here are some useful imports I have in my file!
import pyotp import qrcode from io import BytesIO from moviepy import editor as mpy
The library, pyotp, is for generating one time pad authenticator codes, qrcode is for the qr codes, BytesIO is used for virtual files, and moviepy is what I used to generate the GIF and MP4. I believe BytesIO might be useful for piping data to the streaming service, but how that happens, depends entirely on how data is sent to the service, whether it be ffmpeg over command line (from subprocess import Popen, PIPE) or it be a native library.
-
How to set the moov atom position when encoding video using ffmpeg in c++
19 décembre 2017, par Zhiqiang LiI'm encoding some h264 video into a mp4 container using ffmpeg in c++. But the result videos place the moov atom(or metadata?) at the end of the video file, it's bad for internet streaming. So how can I set the moov atom position to the front?