Chocobozzz / PeerTube

ActivityPub-federated video streaming platform using P2P directly in your web browser
https://joinpeertube.org/
GNU Affero General Public License v3.0
13.11k stars 1.51k forks source link

6.3.0 peertube-runner transcodes do not use original uploaded file as input for FFmpeg command #6601

Open agrathwohl opened 2 months ago

agrathwohl commented 2 months ago

Describe the current behavior

When peertube runners are enabled for VOD transcoding on my 6.3.0 peertube instance, requesting a "Run HLS transcodes" from the videos Overview page causes the peertube runner to download a low quality version of the uploaded video file. This results in the 1080p version in the resulting HLS manifest to have very poor visual quality.

In this screenshot you will see that the 1080p version available for this uploaded video is only a little bit bigger than the 720p, but it should of course be around double the file size. image

On a video that was uploaded to my peertube instance prior to 6.3.0, the 1080p version would typically be 2x the 720p file size. This video was the video uploaded prior to the ones that began showing this issue. It was when I was running 6.2.1: image

You can see that the input file is low quality when running mediainfo on the file downloaded by the peertube-runner node when requesting the 1080p transcode:

General
Complete name                            : e9729920-f222-4819-9ee1-61a55a313b2c
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : iso5 (iso5/iso6/mp41)
File size                                : 396 MiB
Duration                                 : 1 h 0 min
Overall bit rate                         : 918 kb/s
Frame rate                               : 30.000 FPS
Writing application                      : Lavf60.16.100
FileExtension_Invalid                    : braw mov mp4 m4v m4a m4b m4p m4r 3ga 3gpa 3gpp 3gp 3gpp2 3g2 k3g jpm jpx mqv ismv isma ismt f4a f4b f4v

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 1 h 0 min
Bit rate                                 : 915 kb/s
Maximum bit rate                         : 1 244 kb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 30.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.015
Stream size                              : 395 MiB (100%)
Writing library                          : x264 core 164
Encoding settings                        : cabac=1 / ref=1 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=2 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=20 / lookahead_threads=6 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=16 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=1 / keyint=60 / keyint_min=6 / scenecut=40 / intra_refresh=0 / rc_lookahead=10 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / vbv_maxrate=1244 / vbv_bufsize=2488 / crf_max=0.0 / nal_hrd=none / filler=0 / ip_ratio=1.40 / aq=1:1.00
Codec configuration box                  : avcC

Whereas, the actual uploaded original video's mediainfo output is:

General
Complete name                            : c6069b37-f678-485c-9f97-b34f1daf05d4-1080.mp4
Format                                   : MPEG-4
Format profile                           : Base Media / Version 2
Codec ID                                 : mp42 (mp41/isom)
File size                                : 5.12 GiB
Duration                                 : 1 h 0 min
Overall bit rate                         : 12.2 Mb/s
Frame rate                               : 29.970 FPS
Encoded date                             : 2024-09-19 17:11:41 UTC
Tagged date                              : 2024-09-19 17:11:41 UTC

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4
Format settings                          : CABAC / 1 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 1 frame
Format settings, GOP                     : M=1, N=30
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 1 h 0 min
Bit rate                                 : 12.0 Mb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Variable
Frame rate                               : 29.970 FPS
Minimum frame rate                       : 15.000 FPS
Maximum frame rate                       : 30.030 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.192
Stream size                              : 5.04 GiB (98%)
Encoded date                             : 2024-09-19 17:11:41 UTC
Tagged date                              : 2024-09-19 17:11:41 UTC
mdhd_Duration                            : 3619330
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 1 h 0 min
Bit rate mode                            : Constant
Bit rate                                 : 192 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 82.8 MiB (2%)
Encoded date                             : 2024-09-19 17:11:41 UTC
Tagged date                              : 2024-09-19 17:11:41 UTC
mdhd_Duration                            : 3619349

Steps to reproduce

  1. Start a peertube-runner server node that is registered with the peertube 6.3.0 instance.
  2. Navigate to videos Overview page on peertube
  3. Select "Run HLS transcode" on an uploaded video where the original video file was preserved in object storage (i.e., uploaded after upgrading to 6.3.0)

Describe the expected behavior

I would instead expect the peertube runners to always download the original source file to use as the FFmpeg input, since this will produce the best quality results. Is there a way to do this in 6.3.0? If not I would personally label the current behavior as a bug, but if this is the intentional I would then be curious if there's documentation on how to prevent this lower quality version from being downloaded, in favor of the originally uploaded file stored on S3?

Additional information

ilfarpro commented 2 months ago

Yeah, that's true. I can confirm that. It was like that in previous versions of Peertube too

Also I want mention another thing that is not really related to this, but affects quality of encoded videos: https://github.com/Chocobozzz/PeerTube/issues/6539

agrathwohl commented 2 months ago

I have found that the problem is resolved if you replace the uploaded file in the video's "Update" page. It can even be the same exact file that was originally uploaded. I can't quite figure out why replacing the video file makes the runners behave properly so far, but I will keep digging.

Chocobozzz commented 2 months ago

Hi,

PeerTube doesn't use the original file in transcoding. But it's weird that you have so low quality when using the remote runner :thinking: Do you have the same issue if you use local transcoding?

Can you retry to upload this video using remote runners and debug logs so we can see what file is picked up?

agrathwohl commented 1 month ago

Hi,

PeerTube doesn't use the original file in transcoding. But it's weird that you have so low quality when using the remote runner 🤔 Do you have the same issue if you use local transcoding?

Can you retry to upload this video using remote runners and debug logs so we can see what file is picked up?

When I retried the transcode on the local instance, it sourced a file that was about 3 Mbps, 1080p and at the original uploaded constant frame rate of 24 FPS. So no, I cannot seem to recreate this on local.

Chocobozzz commented 1 month ago

Thanks, can you retry with the runner using the --verbose CLI arg so we can see which file the runner is downloading?

Chocobozzz commented 1 month ago

Ping @agrathwohl

agrathwohl commented 1 month ago

Ping @agrathwohl

Hi @Chocobozzz I apologize for my delayed reply. I just started a new job and had to put this on the backburner for a little bit. I will be able to try the --verbose CLI argument in a couple of days.