meetecho / janus-gateway

Janus WebRTC Server
https://janus.conf.meetecho.com
GNU General Public License v3.0
8.11k stars 2.46k forks source link

using janus-pp-rec to generate mp4 file, but h264 profile is not correct #1913

Closed yangpeiyong closed 4 years ago

yangpeiyong commented 4 years ago

I have video call encoded in h264 baseline, using janus to record the video into a mjr file.

Then I using janus-pp-rec to convert mjr file to a playable mp4 file.

When I play the mp4 file, the video has many green blocks. And the log of janus-pp-rec has something strange:

[libx264 @ 0x7fe89b001800] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 [libx264 @ 0x7fe89b001800] profile High, level 1.3 [libx264 @ 0x7fe89b001800] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=7 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00

The video send is h264 baseline, why the log shows h264 profile high. And the video play is not corrent.

I try to use ffmpeg to change mp4 file from profile high to profile baseline, the green blocks disappears.

lminiero commented 4 years ago

janus-pp-rec doesn't transcode, it only copies packets. IIRC we check what profile is in the first sps/pps we get and set that in the mp4 header, but I may be wrong. In case, that's what the RTP packets tell us and so that's what we save. Anyway, not at the office until tomorrow so can't check now.

lminiero commented 4 years ago

IIRC we check what profile is in the first sps/pps we get and set that in the mp4 header, but I may be wrong

I was indeed wrong: we do read the profile in janus_pp_h264_parse_sps, but we ignore it (we only use that to extract width and height). I guess that we can just extract the profile that way too, and save it to the header, since I guess by default this falls back to 100 (high).

@yangpeiyong do you have an .mjr we can use to test a fix, when available?

lminiero commented 4 years ago

Mh, just tried with two different .mjr files (one baseline, one high), and both were converted to playable .mp4 files: mediainfo seems to recognize the right profile for both. If you can share the .mjr file I asked about, I'll have a look to see why it's not working in that case.

yangpeiyong commented 4 years ago

Mh, just tried with two different .mjr files (one baseline, one high), and both were converted to playable .mp4 files: mediainfo seems to recognize the right profile for both. If you can share the .mjr file I asked about, I'll have a look to see why it's not working in that case.

Yes, I can send you .mjr file. Can you give me you email adress?

lminiero commented 4 years ago

You can send it at [redacted].

lminiero commented 4 years ago

@yangpeiyong please let me know when you've sent the mail, as I'd rather not keep the mail address here (I'm pretty sure we'll start getting spam now :wink: )

yangpeiyong commented 4 years ago

@yangpeiyong please let me know when you've sent the mail, as I'd rather not keep the mail address here (I'm pretty sure we'll start getting spam now 😉 )

Hi, Iminiero, I have just sent the mail.

lminiero commented 4 years ago

I think the recording is broken, this is what is printed when we use the --parse option:

SSRC detected: 271031110
[WARN] Dropping packet with unexpected SSRC: 1457645387 != 271031110
[WARN] Dropping packet with unexpected SSRC: 1457645387 != 271031110
[WARN] Dropping packet with unexpected SSRC: 1457645387 != 271031110
[WARN] Dropping packet with unexpected SSRC: 1457645387 != 271031110
[WARN] Dropping packet with unexpected SSRC: 1457645387 != 271031110
[WARN] Dropping packet with unexpected SSRC: 1457645387 != 271031110
[WARN] Dropping packet with unexpected SSRC: 1457645387 != 271031110
Counted 2508 RTP packets
Counted 2501 frame packets
[WARN] Profile is not baseline (-55 != 66)
  -- 240x240 (fps [2250,104940] ~ 40)

There are two SSRCs in it for some reason, which is weird: are you recording from your own plugin?

Besides, it finds a profile that doesn't exist (-55) when evaluating what it believes to be an SPS/PPS packet: this might mean that the recording is not actually H.264. The resolution is weird as well (square?) but that may be intended.

lminiero commented 4 years ago

Processing the recording actually crashed the processor for me, due to a buffer overflow that is now fixed in https://github.com/meetecho/janus-gateway/commit/60e5fef96548a0ada1f8bffd33b840eab4b5ad5f

Now I get an mp4 file that I can play: I do see some artifacts (ghosting, mostly), but no green blocks. Inspecting the file with mediainfo the profile seems correct:

Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Baseline@L2.1

and same thing with FFprobe:

    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 240x240, 62 kb/s, 19.69 fps, 30 tbr, 90k tbn, 180k tbc (default)

As such, I think the tool is doing its job, and what you experienced may have been a side effect of the crash I was getting instead. Closing as I don't think there's an issue, but feel free to reopen if you can provide more details: if you can provide a fix to pp-h264.c that works for you as a pull request, I'll gladly review that too.