Skip to main content
added 47 characters in body
Source Link
Jon37
  • 21
  • 3

I have a single mpeg-ts input stream, http://192.168.1.100/stream0, and I wish to do two things with this stream. One output is to be a hls multipart stream with m3u8 so apache can serve to local clients in a browser. The other output is to copy the stream into a mp4 container that is 5 minutes long. The goal being to have a constant live stream that can be viewed, whilst also a number of 5 min long mp4 files saved to disk.

The command below accomplishes part of what I need:

ffmpeg -re -i http://192.168.1.100/stream0 -c:v copy -c:a copy -preset veryfast \
       -f hls -hls_time 3 -segment_list_flags +live \
           -hls_flags second_level_segment_index\
                      +second_level_segment_size\
                      +second_level_segment_duration \
                      -hls_flags delete_segments \
                      -hls_segment_filename \
                      /var/www/html/live-%1d.ts \
                      /var/www/html/live.m3u8 \
        -f mpegts -c:v copy -c:a copy -y -t 300 \
            /store/archive/archive.$(date +%Y%m%d-%H%M%S).mp4"

The problem is the 2nd part, creates just one file and doesn't continue to create multiple files.

I can run one ffmpeg to create the live stream, then run another instance using that live stream as the input within a loop so the it creates multiple files. Ideally I think I need to use Pipes, but I either end up with out multiple mp4 files, or a live stream that keeps freezing.

What would be the best way to approach this ?

Regards Jon

I have a single mpeg-ts input stream, http://192.168.1.100/stream0, and I wish to do two things with this stream. One output is to be a hls multipart stream with m3u8 so apache can serve to local clients in a browser. The other output is to copy the stream into a mp4 container that is 5 minutes long. The goal being to have a constant live stream that can be viewed, whilst also a number of 5 min long mp4 files saved to disk.

The command below accomplishes part of what I need:

ffmpeg -re -i http://192.168.1.100/stream0 -c:v copy -c:a copy -preset veryfast \
       -f hls -hls_time 3 -segment_list_flags +live \
           -hls_flags second_level_segment_index\
                      +second_level_segment_size\
                      +second_level_segment_duration \
                      -hls_flags delete_segments \
                      -hls_segment_filename \
                      /var/www/html/live-%1d.ts \
                      /var/www/html/live.m3u8 \
        -f mpegts -c:v copy -c:a copy -y -t 300 \
            /store/archive/archive.$(date +%Y%m%d-%H%M%S).mp4"

The problem is the 2nd part, creates just one file and doesn't continue to create multiple files.

I can run one ffmpeg to create the live stream, then run another instance using that live stream as the input. Ideally I think I need to use Pipes, but I either end up with out multiple mp4 files, or a live stream that keeps freezing.

What would be the best way to approach this ?

Regards Jon

I have a single mpeg-ts input stream, http://192.168.1.100/stream0, and I wish to do two things with this stream. One output is to be a hls multipart stream with m3u8 so apache can serve to local clients in a browser. The other output is to copy the stream into a mp4 container that is 5 minutes long. The goal being to have a constant live stream that can be viewed, whilst also a number of 5 min long mp4 files saved to disk.

The command below accomplishes part of what I need:

ffmpeg -re -i http://192.168.1.100/stream0 -c:v copy -c:a copy -preset veryfast \
       -f hls -hls_time 3 -segment_list_flags +live \
           -hls_flags second_level_segment_index\
                      +second_level_segment_size\
                      +second_level_segment_duration \
                      -hls_flags delete_segments \
                      -hls_segment_filename \
                      /var/www/html/live-%1d.ts \
                      /var/www/html/live.m3u8 \
        -f mpegts -c:v copy -c:a copy -y -t 300 \
            /store/archive/archive.$(date +%Y%m%d-%H%M%S).mp4"

The problem is the 2nd part, creates just one file and doesn't continue to create multiple files.

I can run one ffmpeg to create the live stream, then run another instance using that live stream as the input within a loop so the it creates multiple files. Ideally I think I need to use Pipes, but I either end up with out multiple mp4 files, or a live stream that keeps freezing.

What would be the best way to approach this ?

Regards Jon

added 2 characters in body
Source Link
Jon37
  • 21
  • 3

I have a single mpeg-ts input stream, http://192.168.1.100/stream0, and I wish to do two things with this stream. One output is to be a hls multipart stream with m3u8 so apache can serve to local clients in a browser. The other output is to copy the stream into a mp4 container that is 5 minutes long. The goal being to have a constant live stream that can be viewed, whilst also a number of 5 min long mp4 files saved to disk.

The command below accomplishes part of what I need:

ffmpeg -re -i http://192.168.1.100/stream0 -c:v copy -c:a copy -preset veryfast \
       -f hls -hls_time 3 -segment_list_flags +live \
           -hls_flags second_level_segment_index\
                      +second_level_segment_size\
                      +second_level_segment_duration \
                      -hls_flags delete_segments \
                      -hls_segment_filename \
                      /var/www/html/live-%1d.ts \
                      /var/www/html/live.m3u8 \
        -f mpegts -c:v copy -c:a copy -y -t 300 \
            /store/archive/archive.$(date +%Y%m%d-%H%M%S).mp4"

The problem is the 2nd part, creates just one file and doesn't continue to create multiple files.

I can run one ffmpeg to create the live stream, then run another instance using that live stream as the input. Ideally I think I need to use Pipes, but I either end up with out multiple mp4 files, or a live stream that keeps freezing.

What would be the best way to approach this ?

Regards Jon

I have a single mpeg-ts input stream, http://192.168.1.100/stream0, and I wish to do two things with this stream. One output is to be a hls multipart stream with m3u8 so apache can serve to local clients in a browser. The other output is to copy the stream into a mp4 container that is 5 minutes long. The goal being to have a constant live stream that can be viewed, whilst also a number of 5 min long mp4 files saved to disk.

The command below accomplishes part of what I need:

       -f hls -hls_time 3 -segment_list_flags +live \
           -hls_flags second_level_segment_index\
                      +second_level_segment_size\
                      +second_level_segment_duration \
                      -hls_flags delete_segments \
                      -hls_segment_filename \
                      /var/www/html/live-%1d.ts \
                      /var/www/html/live.m3u8 \
        -f mpegts -c:v copy -c:a copy -y -t 300 \
            /store/archive/archive.$(date +%Y%m%d-%H%M%S).mp4"

The problem is the 2nd part, creates just one file and doesn't continue to create multiple files.

I can run one ffmpeg to create the live stream, then run another instance using that live stream as the input. Ideally I think I need to use Pipes, but I either end up with out multiple mp4 files, or a live stream that keeps freezing.

What would be the best way to approach this ?

Regards Jon

I have a single mpeg-ts input stream, http://192.168.1.100/stream0, and I wish to do two things with this stream. One output is to be a hls multipart stream with m3u8 so apache can serve to local clients in a browser. The other output is to copy the stream into a mp4 container that is 5 minutes long. The goal being to have a constant live stream that can be viewed, whilst also a number of 5 min long mp4 files saved to disk.

The command below accomplishes part of what I need:

ffmpeg -re -i http://192.168.1.100/stream0 -c:v copy -c:a copy -preset veryfast \
       -f hls -hls_time 3 -segment_list_flags +live \
           -hls_flags second_level_segment_index\
                      +second_level_segment_size\
                      +second_level_segment_duration \
                      -hls_flags delete_segments \
                      -hls_segment_filename \
                      /var/www/html/live-%1d.ts \
                      /var/www/html/live.m3u8 \
        -f mpegts -c:v copy -c:a copy -y -t 300 \
            /store/archive/archive.$(date +%Y%m%d-%H%M%S).mp4"

The problem is the 2nd part, creates just one file and doesn't continue to create multiple files.

I can run one ffmpeg to create the live stream, then run another instance using that live stream as the input. Ideally I think I need to use Pipes, but I either end up with out multiple mp4 files, or a live stream that keeps freezing.

What would be the best way to approach this ?

Regards Jon

Source Link
Jon37
  • 21
  • 3

Using ffmpeg, how can I split an incoming stream, one live web streaming, the other mp4 but in timed chunks?

I have a single mpeg-ts input stream, http://192.168.1.100/stream0, and I wish to do two things with this stream. One output is to be a hls multipart stream with m3u8 so apache can serve to local clients in a browser. The other output is to copy the stream into a mp4 container that is 5 minutes long. The goal being to have a constant live stream that can be viewed, whilst also a number of 5 min long mp4 files saved to disk.

The command below accomplishes part of what I need:

       -f hls -hls_time 3 -segment_list_flags +live \
           -hls_flags second_level_segment_index\
                      +second_level_segment_size\
                      +second_level_segment_duration \
                      -hls_flags delete_segments \
                      -hls_segment_filename \
                      /var/www/html/live-%1d.ts \
                      /var/www/html/live.m3u8 \
        -f mpegts -c:v copy -c:a copy -y -t 300 \
            /store/archive/archive.$(date +%Y%m%d-%H%M%S).mp4"

The problem is the 2nd part, creates just one file and doesn't continue to create multiple files.

I can run one ffmpeg to create the live stream, then run another instance using that live stream as the input. Ideally I think I need to use Pipes, but I either end up with out multiple mp4 files, or a live stream that keeps freezing.

What would be the best way to approach this ?

Regards Jon