Skip to content

This initiative created a dedicated video quality assessment dataset to drive the development of intelligent pre-processing and post-processing filters for next-generation video compression.

Notifications You must be signed in to change notification settings

zhaishuyan/A-Study-of-Subjective-Video-Quality-at-Prefiltering-and-Postfiltering-in-Video-Compression

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

A Study of Subjective Video Quality at Prefiltering and Postfiltering in Video Compression

Academic Use Only Python 3.8+ PyTorch

This initiative created a dedicated video quality assessment dataset to drive the development of intelligent pre-processing and post-processing filters for next-generation video compression.

Video Source

BVI-SR

This dataset contains 24 4K YUV 4:2:0 video sequences.

Pipelines

For each category, we sample four bitrates, each corresponding to a distinct downsampling resolution, and apply them to both H.265 and AV1 encoders. This results in a total of eight pipelines per category.

1. Baseline

Pipeline:

YUV $\rightarrow$ Lanczos Downsampling $\rightarrow$ YUV $\rightarrow$ Encoding $\rightarrow$ mp4 $\rightarrow$ Decoding $\rightarrow$ YUV $\rightarrow$ Lanczos Upsampling $\rightarrow$ YUV

Commands:

  • Lanczos downsampling
ffmpeg -s 3840x2160 -r 30 -pix_fmt yuv420p -f rawvideo -i Boat.yuv -vf scale={WIDTH_IN}:{HEIGHT_IN}:flags=lanczos -f rawvideo -pix_fmt yuv420p Boat_ds.yuv
  • Encoding
# H.265
ffmpeg -s f'{WIDTH_DS}x{HEIGHT_DS}' -r 30 -pix_fmt yuv420p -f rawvideo -i Boat_ds.yuv -c:v libx265 -preset medium -b:v 30 -maxrate f'{BIT_RATE}' -bufsize f'{BUF_SIZE}' -x265-params profile=main -movflags +faststart Boat_ec.yuv
# AV1
ffmpeg -s f'{WIDTH_DS}x{HEIGHT_DS}' -r 30 -pix_fmt yuv420p -f rawvideo -i Boat_ds.yuv -c:v libsvtav1 -b:v f'{BIT_RATE}' -bufsize f'{BUF_SIZE}' -movflags +faststart Boat_ec.mp4
  • Decoding
ffmpeg -i Boat_ec.mp4 -c:v rawvideo -pix_fmt yuv420p -f rawvideo Boat_dc.yuv
  • Lanczos upsamling
ffmpeg -s f'{WIDTH_DS}x{HEIGHT_DS}' -r 30 -pix_fmt yuv420p -f rawvideo -i Boat_dc.yuv -vf scale=3840:2160:flags=lanczos -f rawvideo -pix_fmt yuv420p Boat_us.yuv

Here, the variable are valued as follow:

WIDTH_DS $\in$ [1920, 1280, 960, 640]

HEIGHT_DS $\in$ [1080, 720, 540, 360]

BIT_RATE $\in$ ['5800k', '3000k', '1750k', '750k']

BUF_SIZE $\in$ ['11600k', '6000k', '3500k', '1500k']

2. Prefiltering

2.1 Deep Downsampling

Deep Downsampler: CAR (TIP 2020)

Pipeline:

YUV $\rightarrow$ Deep Downsampling $\rightarrow$ YUV $\rightarrow$ Encoding $\rightarrow$ mp4 $\rightarrow$ Decoding $\rightarrow$ YUV $\rightarrow$ Lanczos Upsampling $\rightarrow$ YUV

Commands:

Compared to the baseline, only the downsampling command is changed in this pipeline. The encoding, decoding and upsampling commands are the same as those in the baseline.

The deep downsampling procedure can be divided into three steps:

Step 1 (optional). 1.5x downsample the RGB images by the Lanczos filter

The published CAR parameters include 2x and 4x downsampling filters. Since our settings also require 3x and 6x downsampling, we first apply a 1.5x downsampling using the Lanczos filter.

Step 2. Convert a yuv420p video to RGB images;

def YUVvideo2IMGs(yuv_video_path, output_dir, height, width):
    img_size = (height * width * 3 // 2)
    frames = int(os.path.getsize(yuv_video_path) / img_size)

    with open(yuv_video_path, 'rb') as f:
        for frame_idx in range(frames):
            yuv = np.zeros(shape=img_size, dtype='uint8', order='C')
            for j in range(img_size):
                yuv[j] = ord(f.read(1))
            img = yuv.reshape((height * 3 // 2, width))
            bgr_img = cv2.cvtColor(img, cv2.COLOR_YUV2BGR_I420)
            if bgr_img is not None:
                output_path = os.path.join(output_dir, f'frame_{frame_idx:05d}.bmp')
                cv2.imwrite(output_path, bgr_img)

Step 3. Downsample the RGB images by CAR;

Download pre-trained models from link and add them into CAR/models.

python run_downsample.py --img_dir /path/to/high/resolution/images/ --scale 2 --output_dir /path/to/low/resolution/images/

Step 4. Convert RGB images to a yuv420p video.

def IMG2YUVvideo(img_dir, prefix, save_path):
    image_files = [f for f in os.listdir(img_dir)
                   if f.startswith(prefix) and f.lower().endswith(('.bmp'))]
    img_list = sorted(image_files)
    img = cv2.imread(os.path.join(img_dir, img_list[0]))
    (height, width, _) = img.shape
    with open(save_path, 'wb') as f:
        for img_name in img_list:
            img_path = os.path.join(img_dir, img_name)
            img = cv2.imread(img_path)
            yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV_I420)
            yuv = yuv.reshape(height * width * 3 // 2)
            f.write(np.array(yuv, dtype='uint8').tobytes())

2.2 Denoising

Denoising filter: BM3D

Pipeline:

YUV $\rightarrow$ BM3D Denoising $\rightarrow$ Lanczos Downsampling $\rightarrow$ YUV $\rightarrow$ Encoding $\rightarrow$ mp4 $\rightarrow$ Decoding $\rightarrow$ YUV $\rightarrow$ Lanczos Upsampling $\rightarrow$ YUV

Denoising should be operated before downsampling, which is claimed in link.

Commands:

# Denoising
ffmpeg -s {WIDTH_IN}x{HEIGHT_IN} -r 30 -pix_fmt yuv420p -f rawvideo -i Boat.yuv -filter_complex bm3d=sigma=20:block=16:bstep=2:group=1:estim=basic -f rawvideo -pix_fmt yuv420p Boat_dn.yuv

Besides, the Lanczos downsampling command, encoding command, decoding command and Lanczos upsampling command are the same as those in the baseline.

2.3 Sharpening

Sharpening filter improves the end-to-end compression efficiency with respect to the original source video under a fixed heuristic filter parameter set, which is mentioned in [VMAF Based Rate-Distortion Optimization for Video Coding. MMSP 2020].

Sharpening filter: ffmpeg unsharp

Pipeline:

YUV $\rightarrow$ Lanczos Downsampling $\rightarrow$ Sharpening $\rightarrow$ YUV $\rightarrow$ Encoding $\rightarrow$ mp4 $\rightarrow$ Decoding $\rightarrow$ YUV $\rightarrow$ Lanczos Upsampling $\rightarrow$ YUV

Commands:

# Unsharp
ffmpeg -s {WIDTH_DS}x{HEIGHT_DS} -r str(FPS) -pix_fmt yuv420p -f rawvideo -i Boat_ds.yuv -vf unsharp=luma_msize_x=5:luma_msize_y=5:luma_amount=1.0:chroma_msize_x=3:chroma_msize_y=3:chroma_amount=0.0 -f rawvideo -pix_fmt yuv420p Boat_sharp.yuv

Besides, the Lanczos downsampling command, encoding command, decoding command and Lanczos upsampling command are the same as those in the baseline.

3. Postfiltering

3.1 General Deep Upsampling

General deep upsampler: Swin-IR (ICCV 2021)

Pipeline:

YUV $\rightarrow$ Lanczos Downsampling $\rightarrow$ YUV $\rightarrow$ Encoding $\rightarrow$ mp4 $\rightarrow$ Decoding $\rightarrow$ YUV $\rightarrow$ Deep Upsampling $\rightarrow$ YUV

Commands:

Similar to the deep downsampler CAR, this method is also based on RGB images with 2x and 4x parameters published. Therefore, I apply 1.5x upsampling to the low-resolution YUV video when its resolution is 1280x720 and 640x360. Then, I transform the low-resolution YUV video to RGB images and upsample them by Swin-IR. Finally, I transform the high-resolution RGB images into a YUV video.

Step 1 (optional). Lanczos upsample the YUV video to 1.5x when the resolution of the input vidoes are 1280x720 or 640x360.

ffmpeg -s 1280x720 -r 30 -pix_fmt yuv420p -f rawvideo -i Boat_us.yuv -vf scale={1920}:{1080}:flags=lanczos -f rawvideo -pix_fmt yuv420p Boat_us2.yuv

Step 2. Transform a YUV video into RGB images.

The same as the YUVvideo2IMGs function in 2.1 Deep Downsampling.

Step 3. Deep upsampling 2x or 4x using Swin-IR.

Download 4x and 2x models and save them into SwinIR/model_zoo/.

python main_test_swinir.py --task real_sr --scale 2 --model_path model_zoo/003_realSR_BSRGAN_DFO_s64w8_SwinIR-M_x2_GAN.pth --folder_lq /path/to/low/quality/images

Step 4. Transform RGB images into a YUV video.

The same as the IMG2YUVvideo function in 2.1 Deep Downsampling.

Besides, the Lanczos downsampling command, encoding command and decoding command are the same as those in the baseline.

3.2 Compression-aware Deep Upsampling

Compression-aware deep upsampler: PnP-VCVE (CVPR 2025)

Only 4x model parameters are published. Hence, I haven't run this pipeline.

Pipeline:

YUV $\rightarrow$ Lanczos Downsampling $\rightarrow$ YUV $\rightarrow$ Encoding $\rightarrow$ mp4 $\rightarrow$ Decoding $\rightarrow$ YUV $\rightarrow$ Deep Upsampling $\rightarrow$ YUV

3.3 Debanding

Despite the improved capabilities of video codecs, banding artifacts remain a dominant visual impairment of high-quality, high-definition compressed videos. This fact is mentioned in [Adaptive Debanding Filter. IEEE Signal Processing Letters 2020.]

Debanding filter: ffmpeg deband

Pipeline:

YUV $\rightarrow$ Lanczos Downsampling $\rightarrow$ YUV $\rightarrow$ Encoding $\rightarrow$ mp4 $\rightarrow$ Decoding $\rightarrow$ YUV $\rightarrow$ Lanczos Upsampling $\rightarrow$ Debanding $\rightarrow$ YUV

Commands:

# deband
ffmpeg -s 3840x2160 -r 30 -pix_fmt yuv420p -f rawvideo -i Boat_us.yuv -vf deband -f rawvideo -pix_fmt yuv420p Boat_db.yuv

Besides, the Lanczos downsampling, encoding, decoding and Lanczos upsampling commands are the same as those in the baseline.

3.4 Deblocking

Deblocking filter: ffmpeg deblock

Pipeline:

YUV $\rightarrow$ Lanczos Downsampling $\rightarrow$ YUV $\rightarrow$ Encoding $\rightarrow$ mp4 $\rightarrow$ Decoding $\rightarrow$ YUV $\rightarrow$ Lanczos Upsampling $\rightarrow$ Deblocking $\rightarrow$ YUV

Commands:

# deblock
ffmpeg -s 3840x2160 -r 30 -pix_fmt yuv420p -f rawvideo -i Boat_us.yuv -vf deblock=filter=strong -f rawvideo -pix_fmt yuv420p Boat_deblock.yuv

Besides, the Lanczos downsampling, encoding, decoding and Lanczos upsampling commands are the same as those in the baseline.

3.5 Decompression

Decompression filter: STDF (AAAI 2020)

Pipeline:

YUV $\rightarrow$ Lanczos Downsampling $\rightarrow$ YUV $\rightarrow$ Encoding $\rightarrow$ mp4 $\rightarrow$ Decoding $\rightarrow$ YUV $\rightarrow$ Lanczos Upsampling $\rightarrow$ Decompression $\rightarrow$ YUV

Commands:

# decompression
python test_one_video.py

I modified the inference code so that this model can be applied directly to YUV videos.

Besides, the Lanczos downsampling, encoding, decoding and Lanczos upsampling commands are the same as those in the baseline.

4. Combination

4.1 Pre (Deep Downsampling) + Post (Deep Upsampling)

Deep Downsampler: CAR

Deep Upsampler: SwinIR

Pipeline:

YUV $\rightarrow$ Deep Downsampling $\rightarrow$ YUV $\rightarrow$ Encoding $\rightarrow$ mp4 $\rightarrow$ Decoding $\rightarrow$ YUV $\rightarrow$ Deep Upsampling $\rightarrow$ YUV

All commands are defined before.

4.2 Pre (Denoising + Sharpening) + Post (Debanding + Deblocking)

Pipeline:

YUV $\rightarrow$ Denoising $\rightarrow$ Lanczos Downsampling $\rightarrow$ Sharpening $\rightarrow$ YUV $\rightarrow$ Encoding $\rightarrow$ mp4 $\rightarrow$ Decoding $\rightarrow$ YUV $\rightarrow$ Lanczos Upsampling $\rightarrow$ Debanding $\rightarrow$ Deblocking $\rightarrow$ YUV

All commands are defined before.

4.3 Pre (Denoising + Sharpening) + Post (Decompression)

Pipeline:

YUV $\rightarrow$ Denoising $\rightarrow$ Lanczos Downsampling $\rightarrow$ Sharpening $\rightarrow$ YUV $\rightarrow$ Encoding $\rightarrow$ mp4 $\rightarrow$ Decoding $\rightarrow$ YUV $\rightarrow$ Lanczos Upsampling $\rightarrow$ Decompression $\rightarrow$ YUV

All commands are defined before.

4.4 Jointly-trained Deep Rescaling

Deep Rescaler: CAR

Pipeline:

YUV $\rightarrow$ Deep Downsampling $\rightarrow$ YUV $\rightarrow$ Encoding $\rightarrow$ mp4 $\rightarrow$ Decoding $\rightarrow$ YUV $\rightarrow$ Deep Upsampling $\rightarrow$ YUV

Commands:

# CAR upsampling
python run_upsample.py --img_dir /path/to/decoded/videos/ --scale 2 --output_dir /path/to/output/dir/

Other commands are defined before.

About

This initiative created a dedicated video quality assessment dataset to drive the development of intelligent pre-processing and post-processing filters for next-generation video compression.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published