Is there any way howto create an infinite h264
stream from a video file (eg. mp4, avi, ...). I'd like to use ffmpeg to transcode avi file to h264
but there's no loop
option for output.
No you can't. There is no such command in ffmpeg to loop video. You can use -loop
for image only. If you are interested you can use concat demuxer. Create a playlist file e.g. playlist.txt
Inside playlist.txt add the video location
file '/path/to/video/video.mp4'
file '/path/to/video/video.mp4'
file '/path/to/video/video.mp4'
file '/path/to/video/video.mp4'
file '/path/to/video/video.mp4'
Run ffmpeg
ffmpeg -f concat -i playlist.txt -c copy output.mp4
See here
movie=
which can loop, and works fine here. –
Tanbark playlist.txt
is file playlist.txt
(thus providing an infinite loop), as @Bisexual has mentioned, you use -stream_loop -1
to accomplish infinite looping of all kinds of streamable content — and not -loop
. –
Yser You should be able to use the -stream_loop -1
flag before the input (-i
):
ffmpeg -threads 2 -re -fflags +genpts -stream_loop -1 -i ./test.mp4 -c copy ./test.m3u8
The -fflags +genpts
will regenerate the pts timestamps so it loops smoothly, otherwise the time sequence will be incorrect as it loops.
No you can't. There is no such command in ffmpeg to loop video. You can use -loop
for image only. If you are interested you can use concat demuxer. Create a playlist file e.g. playlist.txt
Inside playlist.txt add the video location
file '/path/to/video/video.mp4'
file '/path/to/video/video.mp4'
file '/path/to/video/video.mp4'
file '/path/to/video/video.mp4'
file '/path/to/video/video.mp4'
Run ffmpeg
ffmpeg -f concat -i playlist.txt -c copy output.mp4
See here
-stream_loop
or a loop filter: `-filter_complex loop=repeat:size:start' for more info read the documentation on the FFMPEG site –
Bisexual movie=
which can loop, and works fine here. –
Tanbark playlist.txt
is file playlist.txt
(thus providing an infinite loop), as @Bisexual has mentioned, you use -stream_loop -1
to accomplish infinite looping of all kinds of streamable content — and not -loop
. –
Yser If you want to have a live stream by looping a single video file then you could split it into .ts files and then simulate .m3u8 file with a php script which would return different .ts based on current time. You could try something similar to this:
<?php
// lets assume that we have stream splitted to parts named testXXXXX.ts
// and all parts have 2.4 seconds and we want to play in loop part
// from test0.ts to test29.ts forever in a live stream
header('Content-Type: application/x-mpegURL');
$time = intval(time() / 2.40000);
$s1 = ($time + 1) % 30;
$s2 = ($time + 2) % 30;
$s3 = ($time + 3) % 30;
$s4 = ($time + 4) % 30;
?>
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:2
#EXT-X-MEDIA-SEQUENCE:<?php echo "$time\n"; ?>
#EXTINF:2.40000,
test<?php echo $s1; ?>.ts
<?php if ($s2 < $s1) echo "#EXT-X-DISCONTINUITY\n"; ?>
#EXTINF:2.40000,
test<?php echo $s2; ?>.ts
<?php if ($s3 < $s2) echo "#EXT-X-DISCONTINUITY\n"; ?>
#EXTINF:2.40000,
test<?php echo $s3; ?>.ts
<?php if ($s4 < $s3) echo "#EXT-X-DISCONTINUITY\n"; ?>
#EXTINF:2.40000,
test<?php echo $s4; ?>.ts
© 2022 - 2024 — McMap. All rights reserved.
-stream_loop
or a loop filter: `-filter_complex loop=repeat:size:start' for more info read the documentation on the FFMPEG site – Bisexual