[FFmpeg-user] Split stream in equal chunks
Marian Klymov
nekto1989 at gmail.com
Thu Mar 25 13:05:52 EET 2021
Sorry, I've copied a message from #ffmpeg IRC channel which suggested using
pastebin for ffmpeg commands. This is the command that was the closest to
what I want but still doesn't always work.
ffmpeg -i rtmp://localhost/live/$name -s 1920x1080 -codec:a aac -ar
48000 -ac 1 -codec:v libx264 -r 25 -g 1 -f stream_segment
-segment_time 30 -reset_timestamps 1 -segment_atclocktime 1 -strftime
1 /var/rec/high%H%M%S.ts;
Example of output files:
1) ffprobe C:\dev\records_test\high162001.ts
ffprobe version 4.3.2-2021-02-27-full_build-www.gyan.dev Copyright (c)
2007-2021 the FFmpeg developers
built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static
--disable-w32threads --disable-autodetect --enable-fontconfig
--enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp
--enable-lzma --enable-libsnappy --enable-zlib --enable-libsrt
--enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray
--enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi
--enable-librav1e --enable-libwebp --enable-libx264 --enable-libx265
--enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx
--enable-libass --enable-frei0r --enable-libfreetype
--enable-libfribidi --enable-libvidstab --enable-libvmaf
--enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid
--enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va
--enable-dxva2 --enable-libmfx --enable-libcdio --enable-libgme
--enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb
--enable-libmp3lame --enable-libshine --enable-libtheora
--enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc
--enable-libgsm --enable-libopencore-amrnb --enable-libopus
--enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b
--enable-libflite --enable-libmysofa --enable-librubberband
--enable-libsoxr --enable-chromaprint
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mpegts, from 'C:\dev\records_test\high162001.ts':
Duration: 00:00:28.66, start: 1.400000, bitrate: 18837 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B),
yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr,
90k tbn, 50 tbc
Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F),
48000 Hz, mono, fltp, 4 kb/s
This was the start of the stream, so it's ok to have it not 30.00 seconds
I'm omitting uninteresting lines for next paragraphs - only bitrate
and duration are different.
2) Input #0, mpegts, from 'C:\dev\records_test\high162029.ts':
Duration: 00:00:30.04, start: 1.400000, bitrate: 17092 kb/s - 29 in
name for some reason. And also not 30.00.
3) 2 more chunks with 30.00
4) Input #0, mpegts, from 'C:\dev\records_test\high162200.ts':
Duration: 00:00:29.96, start: 1.400000, bitrate: 16452 kb/s
I don't care about file size. I want to always have 30.00 seconds. Without
specifying -g 1 I'm usually getting 30.06-30.07 (this is what ffprobe shows
me).
I've also tried keyint=1 and force_key_frames expr:gte(t,n_forced*30)
I'm testing this inside a very simple Docker container based on Debian
Buster. ffmpeg is triggered by nginx if it matters at all.
# ffmpeg -version
ffmpeg version 4.1.6-1~deb10u1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)
configuration: --prefix=/usr --extra-version='1~deb10u1'
--toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu
--incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl
--disable-stripping --enable-avresample --disable-filter=resample
--enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom
--enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca
--enable-libcdio --enable-libcodec2 --enable-libflite
--enable-libfontconfig --enable-libfreetype --enable-libfribidi
--enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame
--enable-libmysofa --enable-libopenjpeg --enable-libopenmpt
--enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband
--enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex
--enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab
--enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp
--enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq
--enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl
--enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883
--enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Best regards,
Marian Klymov
чт, 25 бер. 2021 о 11:28 Carl Eugen Hoyos <ceffmpeg at gmail.com> пише:
> Am Do., 25. März 2021 um 08:03 Uhr schrieb Marian Klymov <
> nekto1989 at gmail.com>:
> >
> > I want to receive rtmp stream (using nginx-rtmp module), transcode
> > it and save it in chunks.
> > I would like to have splitting at specific times and to have all chunks
> > equal to 30.00 seconds (except first and last obviously). I've tried
> > playing with different parameters. segment_atclocktime looked like
> > it should do what I want but it creates chunks of different sizes.
>
> Either I misunderstand or this makes no sense:
> You write that you want 30-second-chunks which is not unusual I
> guess. With each real encoder (like x264), each 30-second-chunk
> has a different size (in bytes). Then you write that you expect that
> your chunks all have the same size.
> You would that be possible?
>
> Generally, when asking questions here, always post the command
> line you used together with the complete, uncut console output in
> your email, do not use external resources.
>
> Carl Eugen
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-user
mailing list