kaltura / nginx-vod-module

NGINX-based MP4 Repackager
GNU Affero General Public License v3.0
1.99k stars 439 forks source link

Duplicated video stream in av1-encoded dash stream #1543

Open maximk-1 opened 1 week ago

maximk-1 commented 1 week ago

Hi.

Seems to be a bug - vod-module makes a duplicate of video stream in video metadata of video fragments in mpeg-dash streaming. sample https://github.com/SPBTV/video_av1_samples/blob/master/spbtv_sample_bipbop_av1_960x540_25fps.mp4 server config:

worker_processes  auto;

events {
    use epoll;
    worker_connections 65536;
}

error_log /dev/stderr warn;

http {
    access_log /dev/stdout;

    server {
        listen 8080;
        root /var/www/video;

        location /dash/ {
            vod dash;
            vod_dash_absolute_manifest_urls off;
            rewrite ^/dash/(.+) /$1 break;
        }
    }
}

dash stream

$ ffmpeg -hide_banner -i http://localhost/dash/av1.mp4/manifest.mpd -c copy -map a -map v -f null -
[in#0/dash @ 0x6000017e4200] could not find codec parameters
[aist#0:2/aac @ 0x14cf075a0] Guessed Channel Layout: mono
Input #0, dash, from 'http://localhost/dash/av1.mp4/manifest.mpd':
  Duration: 00:00:15.00, bitrate: N/A
  Program 0 
  Stream #0:0: Video: av1 (libdav1d), none, 960x540, 1k tbn (default)
      Metadata:
        variant_bitrate : 116819
        id              : v1-x3
  Stream #0:1: Video: av1 (libdav1d), none, 960x540, 1k tbn (default)
      Metadata:
        variant_bitrate : 96000
        id              : a1-x3
  No Program
  Stream #0:2: Audio: aac (mp4a / 0x6134706D), 32000 Hz, mono, 8 kb/s (default)
Stream mapping:
  Stream #0:2 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (copy)
  Stream #0:1 -> #0:2 (copy)
Output #0, null, to 'pipe:':
  Metadata:
    encoder         : Lavf61.7.100
  Stream #0:0: Audio: aac (mp4a / 0x6134706D), 32000 Hz, mono, 8 kb/s (default)
  Stream #0:1: Video: av1, none, 960x540, q=2-31, 1k tbn (default)
      Metadata:
        variant_bitrate : 116819
        id              : v1-x3
  Stream #0:2: Video: av1, none, 960x540, q=2-31, 1k tbn (default)
      Metadata:
        variant_bitrate : 96000
        id              : a1-x3
Press [q] to stop, [?] for help

As you can see in ffmpeg output input stream has 3 tracks. But source video file has 1 video and 1 audio.

$ ffprobe -hide_banner https://github.com/SPBTV/video_av1_samples/raw/refs/heads/master/spbtv_sample_bipbop_av1_960x540_25fps.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://github.com/SPBTV/video_av1_samples/raw/refs/heads/master/spbtv_sample_bipbop_av1_960x540_25fps.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: avc1isommp42avc1
    creation_time   : 2018-10-05T14:40:45.000000Z
  Duration: 00:00:15.04, start: 0.000000, bitrate: 130 kb/s
  Stream #0:0[0x1](und): Audio: aac (LC) (mp4a / 0x6134706D), 32000 Hz, mono, fltp, 8 kb/s (default)
      Metadata:
        handler_name    : snd
        vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Video: av1 (libdav1d) (Main) (av01 / 0x31307661), yuv420p(tv), 960x540, 116 kb/s, 25 fps, 25 tbr, 90k tbn (default)
      Metadata:
        handler_name    : vid
        vendor_id       : [0][0][0][0]

Here i downloaded init and 1st segment of dash stream and concatenated - same duplication:

$ ffprobe -hide_banner fragment-1-full.webm 
[matroska,webm @ 0x13de05c70] Could not find codec parameters for stream 1 (Video: av1 (libdav1d), none, 960x540): unspecified pixel format
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, matroska,webm, from 'fragment-1-full.webm':
  Metadata:
    encoder         : nginx-vod-module
  Duration: 00:00:15.00, start: 0.000000, bitrate: 77 kb/s
  Stream #0:0(eng): Video: av1 (libdav1d) (Main), yuv420p(tv), 960x540 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn (default)
  Stream #0:1(eng): Video: av1 (libdav1d), none, 960x540, SAR 1:1 DAR 16:9, 1k tbr, 1k tbn (default)
erankor commented 1 week ago

Sorry, but this doesn't make sense, the MPD has 2 tracks video (v1-x3) and audio (a1-x3). I downloaded both init segments, and analyzed their content, video -

# wget http://localhost:8001/local/dash/content/spbtv_sample_bipbop_av1_960x540_25fps.mp4/init-v1-x3.webm
# python ~/matroska.py init-v1-x3.webm
unknown tag 1a45dfa3
 Segment 36 master 48
   Info 48 master 60
     TimestampScale 1000000
     Duration 15000.0
     MuxingApp nginx-vod-module
     WritingApp nginx-vod-module
   Tracks 116 master 128
     TrackEntry 128 master 137
       TrackNumber 1
       TrackUID 4466639144919767476
       CodecID V_AV1
       TrackType 1
       Video 161 master 170
         PixelWidth 960
         PixelHeight 540

audio -

# wget http://localhost:8001/local/dash/content/spbtv_sample_bipbop_av1_960x540_25fps.mp4/init-a1-x3.mp4
# python /opt/nginx-vod-module/test/print_mp4_atoms.py init-a1-x3.mp4
ftyp
69736f350000000169736f35646173686d736978
moov
  mvhd
00000000000000000000000000015f900014a78000010000010000000000000000000000000100000000000000000000000000000001000000000000000000000000000040000000000000000000000000000000000000000000000000000000ffffffff
  trak
    mdia
      mdhd
00000000000000000000000000015f900014a78000000000
      minf
        dinf
          dref
00000000000000010000000c75726c2000000001
        smhd
0000000000000000
        stbl
          stsz
000000000000000000000000
          stsc
0000000000000000
          stsd
00000000000000010000004b6d7034610000000000000001000000000000000000010010000000007d0000000000002765736473000000000319000000041140150002bc0002ee000001770005021288060102
          stts
0000000000000000
          stco
0000000000000000
      hdlr
0000000000000000736f756e000000000000000000000000536f756e6448616e646c657200
    tkhd
00000003000000000000000000000001000000000014a780000000000000000000000000010000000001000000000000000000000000000000010000000000000000000000000000400000000000000000000000
  mvex
    trex
000000000000000100000001000000000000000000000000

Each one has a single track, as expected.

maximk-1 commented 1 week ago

Yep. Same does other tools, like MKVToolNix. Also stream is not playable in VLC. No video, only audio. Failing with error

mkv debug: |   + Cluster
mkv error: cannot find any cluster or chapter, damaged file ?

VLC Debug Log (3.0.20 Vetinari).txt