Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save init.mp4 to disk #1648

Closed
1 of 13 tasks
pikachu937 opened this issue Apr 3, 2023 · 10 comments · Fixed by bluenviron/gohlslib#20
Closed
1 of 13 tasks

save init.mp4 to disk #1648

pikachu937 opened this issue Apr 3, 2023 · 10 comments · Fixed by bluenviron/gohlslib#20
Labels
enhancement New feature or request hls

Comments

@pikachu937
Copy link

pikachu937 commented Apr 3, 2023

Which version are you using?

v0.22.0

Which operating system are you using?

  • Linux amd64 standard
  • Linux amd64 Docker
  • Linux arm64 standard
  • Linux arm64 Docker
  • Linux arm7 standard
  • Linux arm7 Docker
  • Linux arm6 standard
  • Linux arm6 Docker
  • Windows amd64 standard
  • Windows amd64 Docker (WSL backend)
  • macOS amd64 standard
  • macOS amd64 Docker
  • Other (please describe)

Describe the issue

when saving files to disk in lowLatency and fmp4 mode, the resulting files cannot be played.

ffprobe outputs the following:
ffprobe seg355.mp4
ffprobe version 4.3.5-0+deb11u1 Copyright (c) 2007-2022 the FFmpeg developers
built with gcc 10 (Debian 10.2.1-6)
configuration: --prefix=/usr --extra-version=0+deb11u1 --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-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --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-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --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-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
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
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5564c90a1a00] could not find corresponding trex (id 1)
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5564c90a1a00] could not find corresponding track id 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5564c90a1a00] trun track id unknown, no tfhd was found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5564c90a1a00] error reading header
seg355.mp4: Invalid data found when processing input

while files of the "ts" format are read and played perfectly

Describe how to replicate the issue

  1. set var hlsEncryption, hlsServerKey, hlsServerCert
  2. set var hlsVarian - lowLatency or fmp4
  3. set var hlsDirectory
  4. start the server
  5. publish with rtsp
  6. download segXXX.mp4 file from server
  7. read with vlc or quicktime player

Did you attach the server logs?

yes / no

Did you attach a network dump?

yes / no

@aler9
Copy link
Member

aler9 commented Apr 4, 2023

Hello, this is expected since MP4 segments can be decoded only after decoding an initialization file called "init.mp4".
This file is placed in the header of the HLS playlist:

#EXTM3U
#EXT-X-VERSION:7
#EXT-X-MEDIA-SEQUENCE:20
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:2
#EXT-X-MAP:URI="init.mp4"
#EXTINF:2,
segment.mp4
#EXT-X-ENDLIST

A HLS player usually downloads init.mp4 and segment.mp4, merges them together and passes them to the video decoder.

We can improve the server in order to save init.mp4 on the disk too, but, in order to read the segments with a normal player like VLC or FFmpeg, you'll still have to append them to init.mp4.

@aler9 aler9 added enhancement New feature or request hls labels Apr 4, 2023
@pikachu937
Copy link
Author

ok, that would be great. there are a few more questions. are you planning a permanent storage option, as well as an option to work with a database?

@aler9
Copy link
Member

aler9 commented Apr 9, 2023

Native stream recording is tracked here: #1399

Files don't fit well with databases, therefore no database.

@aler9 aler9 changed the title save segment to disk save init.mp4 to disk Apr 10, 2023
@pikachu937
Copy link
Author

Files don't fit well with databases, therefore no database.

I do not agree with you. it is much easier to search for files on a disk using a known path than it is to go through all the directories and look for the desired file. the database can store file paths, size, creation date, duration, name of the stream to which the file belongs.

@aler9
Copy link
Member

aler9 commented Apr 10, 2023

@pikachu937 i thought you were suggesting to use a database to store files, instead you are suggesting to use a database to store the file metadata, which is reasonable. It may be an improvement of the stream recording feature.

Regarding HLS, the option hlsDirectory was conceived in order to offload RAM from segments, since segments use a significant amount of space when they are kept exclusively in RAM, but at the same time performance is a requirement, therefore i'd rather not add a database. Anyway, the missing file init.mp4 will be soon added to the corresponding directory.

@pikachu937
Copy link
Author

@pikachu937 i thought you were suggesting to use a database to store files, instead you are suggesting to use a database to store the file metadata, which is reasonable. It may be an improvement of the stream recording feature.

Regarding HLS, the option hlsDirectory was conceived in order to offload RAM from segments, since segments use a significant amount of space when they are kept exclusively in RAM, but at the same time performance is a requirement, therefore i'd rather not add a database. Anyway, the missing file init.mp4 will be soon added to the corresponding directory.

Excellent, thank you. Then I think you won't mind if I open a new ticket to add metadata storage functionality to the database?

aler9 added a commit to bluenviron/gohlslib that referenced this issue Apr 11, 2023
aler9 added a commit to bluenviron/gohlslib that referenced this issue Apr 11, 2023
@aler9
Copy link
Member

aler9 commented Apr 11, 2023

init.mp4 is now saved on disk.

@pikachu937
Copy link
Author

thank you... you are the best...

@aler9
Copy link
Member

aler9 commented Apr 13, 2023

added in v0.22.1

@github-actions
Copy link
Contributor

This issue is being locked automatically because it has been closed for more than 6 months.
Please open a new issue in case you encounter a similar problem.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request hls
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants