Zend certified PHP/Magento developer

MP4 to HLS stream conversion error after resizing video using FFmpeg

When trying to create HLS stream from original video, FFmpeg creates HLS stream without errors.

~ $ ffmpeg -i test.mp4 -f hls -hls_time 3 -hls_segment_filename seg%02d.ts stream.m3u8

But when I resize video using this command, I get a timestamps warning:

~ $ ffmpeg -i test.mp4 -vf scale=426:240 test_240p.mp4
[mp4 @ 0xb400007429e52d00] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[mp4 @ 0xb400007429e52d00] Encoder did not produce proper pts, making some up.

And when creating HLS stream from resized video, I’m getting an error:

~ $ ffmpeg -i test_240p.mp4 -f hls -hls_time 3 -hls_segment_filename seg%02d.ts stream.m3u8                     ffmpeg version N-111626-g0ba719f726 Copyright (c) 2000-2023 the FFmpeg developers
  built with clang version 16.0.6
  configuration: --arch=aarch64 --as=aarch64-linux-android-clang --cc=aarch64-linux-android-clang --cxx=aarch64-linux-android-clang++ --nm=llvm-nm --pkg-config=/data/data/com.termux/files/usr/bin/pkg-config --strip=llvm-strip --cross-prefix=aarch64-linux-android- --disable-indevs --disable-outdevs --enable-indev=lavfi --disable-static --disable-symver --enable-cross-compile --enable-gnutls --enable-gpl --enable-jni --enable-lcms2 --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgme --enable-libmp3lame --enable-libopus --enable-librav1e --enable-libsoxr --enable-libsrt --enable-libssh --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-mediacodec --enable-opencl --enable-shared --prefix=/data/data/com.termux/files/usr --target-os=android --extra-libs=-landroid-glob --disable-vulkan --enable-neon --disable-libfdk-aac                                                      libavutil      58. 14.100 / 58. 14.100                  libavcodec     60. 22.100 / 60. 22.100
  libavformat    60. 10.100 / 60. 10.100                  libavdevice    60.  2.101 / 60.  2.101
  libavfilter     9. 10.100 /  9. 10.100
  libswscale      7.  3.100 /  7.  3.100
  libswresample   4. 11.100 /  4. 11.100
  libpostproc    57.  2.100 / 57.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_240p.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf60.10.100
  Duration: 00:00:10.01, start: 0.000000, bitrate: 178 kb/s
  Stream #0:0[0x1](und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/smpte170m, progressive), 426x240, 44 kb/s, SAR 640:639 DAR 16:9, 25 fps, 25 tbr, 12800 tbn (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc. Created on: 02/24/2023.
      vendor_id       : [0][0][0][0]
      encoder         : Lavc60.22.100 h264_mediacodec
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc. Created on: 02/24/2023.
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_mediacodec))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[h264_mediacodec @ 0xb400007da1f2ac00] Use 1 as the default MediaFormat i-frame-interval, please set gop_size properly (>= fps)
[h264_mediacodec @ 0xb400007da1f2ac00] Mediacodec encoder doesn't support AV_CODEC_FLAG_GLOBAL_HEADER. Use extract_extradata bsf when necessary.
Output #0, hls, to 'stream.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf60.10.100
  Stream #0:0(und): Video: h264, yuv420p(tv, bt709/bt709/smpte170m, progressive), 426x240 [SAR 640:639 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 90k tbn (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc. Created on: 02/24/2023.
      vendor_id       : [0][0][0][0]
      encoder         : Lavc60.22.100 h264_mediacodec
  Stream #0:1(und): Audio: aac (LC), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc. Created on: 02/24/2023.
      vendor_id       : [0][0][0][0]
      encoder         : Lavc60.22.100 aac
frame=    0 fps=0.0 q=0.0 size=N/A time=00:00:00.25 bitr[hls @ 0xb400007da1f27d00] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[hls @ 0xb400007da1f27d00] Encoder did not produce proper pts, making some up.
[mpegts @ 0xb400007da1f29100] H.264 bitstream error, startcode missing, size 0
[hls @ 0xb400007da1f27d00] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 3600 >= 3600
[vost#0:0/h264_mediacodec @ 0xb400007da200a000] Error submitting a packet to the muxer: Invalid argument
[out#0/hls @ 0xb400007da1eaa6c0] Error muxing a packet
[hls @ 0xb400007da1f27d00] Opening 'seg00.ts' for writing
[hls @ 0xb400007da1f27d00] Opening 'stream.m3u8.tmp' for writing
[out#0/hls @ 0xb400007da1eaa6c0] video:2kB audio:5kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
frame=    3 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.41 bitrate=N/A speed=3.39x
[aac @ 0xb400007da2051400] Qavg: 32468.840
Conversion failed!
~ $

I tried to build FFmpeg from GitHub and install FFmpeg from repositories, and I’m still getting this error.