About‎ > ‎

JSVM Batch Script

The following batch files and some source codes are for encoding YUV format video into H.264/SVC format with spatial scalability & temporal scalability (no SNR scalability in this case). Some modifications might be needed for different source video resolution and filename.

Upsampling (.java)


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class Upsampling {
    public static void main(String[] args) {
        if (args.length == 0) {
            System.out.println("Upsampling <Input filename> <OutFilename> <width> <height> <duplicate>");
            return;
        }
        try {
            String inFilename = args[0];
            String outFilename = args[1];
            int width = Integer.parseInt(args[2]);
            int height = Integer.parseInt(args[3]);
            int duplicate = Integer.parseInt(args[4]);
            int yuvSize = (int) (width * height * 1.5);
            byte[] yuvFrame = new byte[yuvSize];

            InputStream in = new BufferedInputStream(new FileInputStream(inFilename));
            OutputStream out = new BufferedOutputStream(new FileOutputStream(outFilename));
            while (in.available() > 0) {
                if (yuvSize == in.read(yuvFrame)) {
                    for (int i=0 ; i<duplicate+1 ; i++){
                        out.write(yuvFrame);
                    }
                }
            }
            out.flush();
            in.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


SVC-main.cfg

# JSVM Main Configuration File
OutputFile              output\fm.264       # Bitstream file
FrameRate               30.0               # Maximum frame rate [Hz]
FramesToBeEncoded       300                # Number of frames (at input frame rate)
GOPSize                 8                  # GOP Size (at maximum frame rate)
BaseLayerMode           2                  # Base layer mode (0: AVC w larger DPB,
                                           #   1:AVC compatible, 2:AVC w subseq SEI)
SearchMode              4                  # Search mode (0:BlockSearch, 4:FastSearch)
SearchRange             32                 # Search range (Full Pel)
NumLayers               2                  # Number of layers
LayerCfg                SVC-layer0.cfg     # Layer configuration file
LayerCfg                SVC-layer1.cfg     # Layer configuration file

SVC-layer0.cfg

# JSVM Layer Configuration File
InputFile            src\fm176144.yuv # Input  file
SourceWidth          176            # Input  frame width
SourceHeight         144            # Input  frame height
FrameRateIn          30             # Input  frame rate [Hz]
FrameRateOut         30             # Output frame rate [Hz]


SVC-layer1.cfg

# JSVM Layer Configuration File


InputFile            src\fm352288.yuv  # Input  file
SourceWidth          352                # Input  frame width
SourceHeight         288                # Input  frame height
FrameRateIn          30                 # Input  frame rate [Hz]
FrameRateOut         30                 # Output frame rate [Hz]
InterLayerPred       2                  # Inter-layer Pred. (0: no, 1: yes, 2:adap.)

UseESS          1         # ESS
ESSCropWidth    352       # cropping width
ESSCropHeight   288       # cropping height
ESSOriginX      0         # cropping origin X
ESSOriginY      0         # cropping origin Y
ESSChromaPhaseX 0         # chroma phase x 0 or -1, default = -1
ESSChromaPhaseY 0         # chroma phase y -1 to +1, default = 0
ESSBaseChromaPhaseX 0     # base chroma phase x 0 or -1, default = -1
ESSBaseChromaPhaseY 0     # base chroma phase y -1 to +1, default = 0 0

Batch Script (.bat)

REM Down Sampling (352*288 -> 176*144)
DownConvertStatic 352 288 src\fm352288.yuv 176 144 src\fm176144.yuv 0 0 0 frms -phase 0 0 0 0

REM Down Sampling (352*288, 30 Hz-> 176*144, 15 Hz)
REM DownConvertStatic 352 288 src\fm352288.yuv 176 144 src\fm176144.yuv 0 1 0 frms -phase 0 0 0 0

REM Encode (Peng-Jung Wu)
H264AVCEncoderLibTestStatic -pf SVC-main.cfg
REM                     bitrate    Min-bitr   Y-PSNR   U-PSNR   V-PSNR
REM                    --------- ---------- -------- -------- --------
REM 176x144 @  3.7500    45.0426    45.0426  36.8608  40.6911  41.5403
REM 176x144 @  7.5000    62.0184    62.0184  36.5485  40.5958  41.3881
REM 176x144 @ 15.0000    80.0184    80.0184  36.3145  40.5098  41.2712
REM 176x144 @ 30.0000    97.3544    97.3544  36.1332  40.4349  41.1823
REM 352x288 @  3.7500   164.3597   164.3597  37.0768  41.0937  42.9080
REM 352x288 @  7.5000   208.0216   208.0216  36.4385  40.9543  42.7038
REM 352x288 @ 15.0000   253.6872   253.6872  35.9834  40.8556  42.5646
REM 352x288 @ 30.0000   302.7336   302.7336  35.6887  40.7888  42.4744
 
REM Check layers (Peng-Jung Wu)
BitStreamExtractorStatic output\fm.264
REM Layer   Resolution   Framerate   Bitrate MinBitrate      DTQ
REM   0     176x144       3.7500      45.00       45.00   (0,0,0)
REM   1     176x144       7.5000      62.00       62.00   (0,1,0)
REM   2     176x144      15.0000      80.00       80.00   (0,2,0)
REM   3     176x144      30.0000      97.40       97.40   (0,3,0)
REM   4     352x288       3.7500     164.40      164.40   (1,0,0)
REM   5     352x288       7.5000     208.00      208.00   (1,1,0)
REM   6     352x288      15.0000     253.70      253.70   (1,2,0)
REM   7     352x288      30.0000     302.70      302.70   (1,3,0)

REM Extract layers (Peng-Jung Wu)
BitStreamExtractorStatic output\fm.264 output\L00.264 -sl 0
BitStreamExtractorStatic output\fm.264 output\L01.264 -sl 1
BitStreamExtractorStatic output\fm.264 output\L02.264 -sl 2
BitStreamExtractorStatic output\fm.264 output\L03.264 -sl 3
BitStreamExtractorStatic output\fm.264 output\L04.264 -sl 4
BitStreamExtractorStatic output\fm.264 output\L05.264 -sl 5
BitStreamExtractorStatic output\fm.264 output\L06.264 -sl 6
BitStreamExtractorStatic output\fm.264 output\L07.264 -sl 7
REM BitStreamExtractorStatic output\fm.264 output\L092.264 -l 1 -t 4 -f 0 (DTQ)

REM Decode (Peng-Jung Wu)
H264AVCDecoderLibTestStatic output\L00.264 output\L00.yuv
H264AVCDecoderLibTestStatic output\L01.264 output\L01.yuv
H264AVCDecoderLibTestStatic output\L02.264 output\L02.yuv
H264AVCDecoderLibTestStatic output\L03.264 output\L03.yuv
H264AVCDecoderLibTestStatic output\L04.264 output\L04.yuv
H264AVCDecoderLibTestStatic output\L05.264 output\L05.yuv
H264AVCDecoderLibTestStatic output\L06.264 output\L06.yuv
H264AVCDecoderLibTestStatic output\L07.264 output\L07.yuv

REM Upsampling
DownConvertStatic 176 144 output\L00.yuv 352 288 output\temp00.yuv 1 0
DownConvertStatic 176 144 output\L01.yuv 352 288 output\temp01.yuv 1 0
DownConvertStatic 176 144 output\L02.yuv 352 288 output\temp02.yuv 1 0
DownConvertStatic 176 144 output\L03.yuv 352 288 output\temp03.yuv 1 0

java Upsampling output\temp00.yuv output\stream00.yuv 352 288 7
java Upsampling output\temp01.yuv output\stream01.yuv 352 288 3
java Upsampling output\temp02.yuv output\stream02.yuv 352 288 1
java Upsampling output\L04.yuv output\stream04.yuv 352 288 7
java Upsampling output\L05.yuv output\stream05.yuv 352 288 3
java Upsampling output\L06.yuv output\stream06.yuv 352 288 1


REM Calculate PSNR
PSNRStatic 352 288 src\fm352288.yuv output\stream00.yuv > output\PSNR00.txt
PSNRStatic 352 288 src\fm352288.yuv output\stream01.yuv > output\PSNR01.txt
PSNRStatic 352 288 src\fm352288.yuv output\stream02.yuv > output\PSNR02.txt
PSNRStatic 352 288 src\fm352288.yuv output\temp03.yuv > output\PSNR03.txt
PSNRStatic 352 288 src\fm352288.yuv output\stream04.yuv > output\PSNR04.txt
PSNRStatic 352 288 src\fm352288.yuv output\stream05.yuv > output\PSNR05.txt
PSNRStatic 352 288 src\fm352288.yuv output\stream06.yuv > output\PSNR06.txt
PSNRStatic 352 288 src\fm352288.yuv output\L07.yuv > output\PSNR07.txt


Comments