[FFmpeg-user] Fwd: Split stream in equal chunks

Marian Klymov nekto1989 at gmail.com
Sun Jul 18 17:00:32 EEST 2021


чт, 25 бер. 2021 о 18:12 Carl Zwanzig <cpz at tuunq.com> пише:
> IRC isn't email, of course :); PB may be ok for sharing the text on IRC.
> Please take a look at the mailing list FAQ-
> https://ffmpeg.org/mailing-list-faq.html
>
> (which also tells us not to top-post)
>
> Later,
>
> z!


So I've come back to this task after some time. I've switched to
using Alpine with building ffmpeg from the latest snapshot.

I want to achieve such a workflow:
1) Have 24 * 60 * 2 chunks for each day in high and low quality.
Each chunk corresponds to 30-seconds period. Video should be black
if there was no input stream.
2) Afterwards I want to be able to cut/concatenate any part from all
this chunks as mp4.

Currently I'm using this command to save video every 30 seconds
(except first chunk), transcode it, save on disk and also restream
to another server:

ffmpeg -i rtmp://localhost/live/test -vsync passthrough -c:v libx264
-preset fast -crf 23 -b:v 6000k -minrate 6000k -maxrate 6000k
-vf "scale=1920:1080" -r 25 -g 25 -keyint_min 25 -sc_threshold 0
-codec:a aac -af "aresample=48000:async=1000" -ac 2 -b:a 128k
-reset_timestamps 1 -f tee -map 0
"[f=stream_segment:segment_atclocktime=1:segment_time=30:strftime=1]
/var/rec/%s.ts|[f=flv]rtmp://localhost/transcoded/test";

Having gop 25 has helped with segment sizes. Keyframe is inserted
every second and ffmpeg doesn't have any problems cutting segments.
The problem happens with concatenating parts. I'vetried to cut first
part, cut last part and then use ffconcat to glue everything together
without having to reencode. I'm using the same parameters to be able
to use "-c copy" afterwards. Example:
ffmpeg -y -i 000000.ts -ss 01.10 -codec:v libx264 -preset fast
-crf 23 -b:v 6000k -minrate 6000k -maxrate 6000k -codec:a aac
-f mpegts tempchunkstart.ts

ffmpeg -y -i 000100.ts -codec:v libx264 -preset fast
-crf 23 -b:v 6000k -minrate 6000k -maxrate 6000k -codec:a aac
-to 05.00 -f mpegts tempchunkend.ts

Then I'm preparing input for ffconcat like
file 'tempchunk.ts'
file '000030.ts'
file 'tempchunkend.ts'

ffmpeg -y -f concat -safe 0 -i concat_list.txt -c copy output.ts

Afterwards I'm converting .ts to .mp4

ffmpeg -i output.ts -map 0 -c copy output.mp4

The problem happens with the last audio frame between chunks. I'm
feeling that I'm doing something completely wrong. Should I somehow
tell ffmpeg explicitly to use timestamps from original .ts files?

Thanks for pointing me in the right direction,
Marian Klymov


More information about the ffmpeg-user mailing list