FFmpeg Live Stream - Loop Video?

Am I trying to stream a video loop to justin.tv using FFmpeg? I managed to loop through the image and combine it with a line in the audio:

  ffmpeg -loop 1 -i imageSequence% 04d.jpg -f alsa -ac 2 -ar 22050 -ab 64k \
   -i pulse -acodec adpcm_swf -r 10 -vcodec flv \
   -f flv rtmp: //live.justin.tv/app/ <yourStreamKeyHere>

Is it possible to do this with a video file?

+6
source share
3 answers

Definitely possible. In recent versions of ffmpeg, they have added the -stream_loop flag, which allows you to cycle through the input as many times as needed.

It turns out that if you do not regenerate pts from the source, ffmpeg will drop frames after the first loop (since the timestamp will suddenly return in time). To avoid this, you need to inform ffmpeg about the generation of points, so that you increase the time stamp between cycles. This is done by calling + genpts (it must be before -i arg).

Here is an example ffmpeg call (replace $ F with your input file). In this example, two output streams are generated, and the argument -stream_loop -1 tells ffmpeg a continuous input loop. The output signal in this case is intended for a similar streaming broadcast (MetaCDN), according to your requirements.

ffmpeg -threads 2 -re -fflags +genpts -stream_loop -1 -i $F \ -s 640x360 -ac 2 -f flv -vcodec libx264 -profile:v baseline -b:v 600k -maxrate 600k -bufsize 600k -r 24 -ar 44100 -g 48 -c:a libfdk_aac -b:a 64k "rtmp://publish.live.metacdn.com/2050C7/dfsdfsd/lowquality_664?hello&adbe-live-event=lowquality_" \ -s 1920x1080 -ac 2 -f flv -vcodec libx264 -profile:v baseline -b:v 2000k -maxrate 2000k -bufsize 2000k -r 24 -ar 44100 -g 48 -c:a libfdk_aac -b:a 64k "rtmp://publish.live.metacdn.com/2050C7/dfsdfsd/highquality_2064?mate&adbe-live-event=highquality_" 
+8
source

Sinclair Media found a solution using the lavfi filter and adding :loop=0 to the file name:

This is not verified:

 ffmpeg -f lavfi -re -i movie=StreamTest.avi:loop=0 \ -acodec libfaac -b:a 64k -pix_fmt yuv420p -vcodec libx264 \ -x264opts level=41 -r 25 -profile:v baseline -b:v 1500k \ -maxrate 2000k -force_key_frames 50 -s 640×360 -map 0 -flags \ -global_header -f segment -segment_list index_1500.m3u8 \ -segment_time 10 -segment_format mpeg_ts \ -segment_list_type m3u8 segmented.ts 

But he has to create a local file "index_1500.m3u8", which transfers the video to "StreamTest.avi".

+2
source

I just reuse Rob's answers with some changes to provide a live stream file

 ffmpeg -threads 2 -re -fflags +genpts -stream_loop -1 -i gvf.mp4 -c copy -f mpegts -mpegts_service_id 102 -metadata service_name=My_channel -metadata service_provider=My_Self -max_interleave_delta 0 -use_wallclock_as_timestamps 1 -flush_packets 1 "udp://233.0.0.1:1001?localaddr=10.60.4.237&pkt_size=188" 
-1
source

Source: https://habr.com/ru/post/943457/


All Articles