Wrong frame rate when saving camera feed to a file using FFMPEG - camera

I'm trying to save the live feed from an IP camera to a file but the resulting file always plays much faster than the original speed.
I have tried with the following commands:
ffmpeg -i http://171.22.3.47/image -vcodec copy -an -t 900 c:\output.mp4
ffmpeg -i http://171.22.3.47/image -c:v libx264 -an c:\output.mp4
Does anybody know what I'm missing? Both commands create the file and I can use Windows Media Player to play them, but they run much faster.

Try forcing output framerate by adding -r key
ffmpeg -i http://171.22.3.47/image -c:v libx264 -an -r 30 c:\output.mp4
You can also try to slow down the resulting video as an option. This will make output.mp4 2 times slower:
ffmpeg -i output.mp4 -filter:v "setpts=2.0*PTS" -c:v libx264 -an output-slow.mp4

Related

Mediasoup inject stream freezes

I am using the following ffmpeg command to inject an rtmp stream to mediasoup.
ffmpeg \
-re \
-v info \
-stream_loop -1 \
-i rtmp://3.126.121.45:1935/live/stream \
-map 0:a:0 \
-acodec libopus -ab 128k -ac 2 -ar 48000 \
-map 0:v:0 \
-c:v libvpx -minrate 2500k -maxrate 2500k -b:v 2500k -r 30 -g 60 -max_delay 0 -bf 0 -deadline realtime -cpu-used 1 \
-f tee \
"[select=a:f=rtp:ssrc=11111111:payload_type=101]rtp://52.29.30.225:41299?rtcpport=40612&pkt_size=1300|[select=v:f=rtp:ssrc=22222222:payload_type=102]rtp://52.29.30.225:44083?rtcpport=48791&pkt_size=1300"
But the video seems to freeze randomly and plays again. Any idea how I can fix this? Tried the solution given here and here with no luck.
Update: Seems like it is the problem of RTP retransmission when some packets are lost. Unfortunately, ffmpeg doesn't fare well with RTP streaming as mentioned here. Meaning ffmpeg doesn't support retransmission mechanism like nack, pli etc. So considering gstreamer instead as suggested in the mediasoup discourse discussion.

ffmpeg always gives me input/output error for the first time running the command

I'm using ffmpeg to push raspberrypi video feeds (CSI camera) to a nginx-RTMP server then the nginx push it to youtube.
My problem is, every time when I run the ffmpeg command, it always gives me input/out error. Then it is working fine when I run the exact same ffmpeg command for the 2nd time.
How do I resolve this problem?
I want to start the ffmpeg command in a script file and put the script in crontab so that it can start the live streaming automatically. But this error makes it impossible to do that.
my ffmpeg command is as below(change the real domain name to mydomain.com):
ffmpeg -thread_queue_size 512 -f v4l2 -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -input_format yuyv422 -video_size 1280x720 -framerate 30 -i /dev/video0 -vf eq=gamma=1.5:saturation=1.3 -c:v h264_omx -b:v 20480K -vsync 1 -g 16 -f flv rtmp://mydomain.com:1935/live/
the error log:
Input #1, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 474200.421802, bitrate: 442368 kb/s
Stream #1:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1280x720, 442368 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
rtmp://rtmp.simonliu.space:1935/live/: Input/output error

ffmpeg image sequence specify input framerate

I am trying to set the input framerate of a sequence of images (many folders):
if I am working with a single image sequence everything works properly:
ffmpeg -framerate 30 -i folder01/img%05d.jpeg -filter:v "crop=640:360" -r 30 outfilm.mp4
then, because I have more folders (and I was unable to get the -i concat:filesequence1|filesequence2 working) I tried to use:
ffmpeg -framerate 30 -f concat -safe 0 -i filelist.txt -filter:v "crop=640:360" -r 30 outfilm.mp4
but I receive an error:
Option framerate not found.
then if I omit the -framerate 30, everything runs smoothly, but ffmpeg defaults to a 25 fps value for the input image sequences.
Any ideas on how to fix this?
Use
ffmpeg -f concat -safe 0 -r 30 -i filelist.txt -filter:v "crop=640:360" -r 30 outfilm.mp4
When -r is used as an input option, it generates new timestamps at the given rate and sets that as the input framerate.

How to capture screen and audio input and push to rtmp server?

I use avconv on ubuntu,I found this command
avconv -f alsa -i pulse -f x11grab -r 25 -s 1280x720 -i :0.0+0,0 -acodec libfaac -vcodec libx264 -pre:0 lossless_ultrafast -threads 0 video.mkv
to save as a file, and this command
avconv -i ./test.m4v -re -c copy -f flv "rtmp://localhost/livestream"
to push live stream.
How can I combine them together?
Firstly, you should ask such questions on video.stackexchange.com and not here.
Secondly, let's take apart the two commands that you have found:
-f alsa - format for the input is alsa
-i pulse - you are reading pulse (the pulseaudio driver)
-f x11grab - planning to read from the screen on x11
-r 25 -s 1280x720 - rate and size of the incoming video stream
-i :0.0+0,0 - this selects where the incoming video comes from
-acodec libfaac - here the output options start, you're setting audio code to libfaac, or at least trying to... since this option has been deprecated long time ago, currently -c:a would be used
-vcodec libx264 - setting video code, except that you should be using -c:v
-pre:0 lossless_ultrafast -threads 0 - some sort of parameters about how encoding should be done
video.mkv - this is the output file
And the second one
-i ./test.m4v - the file you're reading
-re - "Read input at native frame rate"
-c copy - do not reencode, but simply pipe as is
-f flv - the container format
"rtmp://localhost/livestream" - where you're planning to write all that.
When you understand that, it should be clear that what you are planning to do is to use the input and encoding part from the first command, and the format and output from the second one.
Here i didn't have time to check that everything that you found is working, you should do that yourself.

FFMpeg UDP streaming - random split video effect

I'm trying to get a simple local preview of my webcam from an FFMpeg udp stream using an embedded Mplayer window. I can view the live stream using MPlayer but the image is unstable. I'm using the following FFMpeg command:
ffmpeg -f dshow -video_size 640x480 -i video="Lenovo EasyCamera" -an -f rawvideo -pix_fmt yuyv422 -r 15 udp://127.0.0.1:1234
And this is the MPlayer command:
mplayer -demuxer rawvideo -rawvideo fps=15:w=640:h=480:format=yuy2 -nofs -noquiet -identify -idle -slave -nomouseinput -framedrop -wid 1051072
Sometimes the stream image is OK, but intermittently the image tears randomly and this is how it looks (sorry, not enough rep for images in posts)
http://imgur.com/sLC3FW0
I have tried with FFPlay to see if it's a problem with MPlayer, but I get the same result:
ffplay -s 640x480 -pix_fmt yuyv422 -f rawvideo -i udp://127.0.0.1:1234
http://imgur.com/06L42Cj
This effect is happening at random. If I stop and restart the video might be OK, or it may look like the above. Using aything other than udp and rawvideo adds a delay to the video stream, which I want to avoid.
The FFMpeg streaming guide suggest methods when you get packet loss, but as far as I'm aware I don't seem to be getting that.
I'm new to FFMpeg/Mplayer/video streaming and any help or thoughts greatly appreciated.