H.264官方软件JM源代码分析

JM源码地址:

http://iphome.hhi.de/suehring/tml/download/

参考:

H.264官方软件JM源代码简单分析-编码器lencod

H.264官方软件JM源代码简单分析-解码器ldecod

HEVC官方软件HM源代码简单分析-编码器TAppEncoder

HEVC官方软件HM源代码简单分析-解码器TAppDecoder

我下载的经典版JM8.6

解压后,打开下面的文件

删除repdump项目

编码————————————————————————————

右击lencod,设置为启动项目

修改输出目录

点击编辑——》宏

设置调试的工作目录为刚才的目录

重新生成

道bin目录下生成了EXE文件

复制下面的文件,改名为encoder.cfg

                 

修改输入文件:

然后运行程序:

Parsing Configfile encoder.cfg...........................................................................................

-------------------------------------------------------------------------------
 Input YUV file                    : foreman_part_qcif.yuv
 Output H.264 bitstream            : test.264
 Output YUV file                   : test_rec.yuv
 Output log file                   : log.dat
 Output statistics file            : stat.dat
-------------------------------------------------------------------------------
  Frame  Bit/pic WP QP   SnrY    SnrU    SnrV    Time(ms) MET(ms) Frm/Fld   I D
-------------------------------------------------------------------------------
0000(NVB)     168
0000(IDR)   21960 0 28  37.387  41.260  42.850      274       0     FRM    99
0001(I)     21696 0 28  37.363  41.333  43.079      278       0     FRM    99
0002(I)     22240 0 28  37.399  41.280  42.818      285       0     FRM    99
--------------------------------------------------------------------------
 Total Frames:  3 (3)
 Leaky BucketRateFile does not have valid entries;
 using rate calculated from avg. rate
 Number Leaky Buckets: 8
     Rmin     Bmin     Fmin
   658950    22240    21966
   823680    22240    21960
   988410    22240    21960
  1153140    22240    21960
  1317870    22240    21960
  1482600    22240    21960
  1647330    22240    21960
  1812060    22240    21960
-------------------------------------------------------------------------------
 Freq. for encoded bitstream       : 30
 Hadamard transform                : Used
 Image format                      : 176x144
 Error robustness                  : Off
 Search range                      : 16
 No of ref. frames used in P pred  : 10
 Total encoding time for the seq.  : 0.837 sec
 Total ME time for sequence        : 0.000 sec
 Sequence type                     : IPPP (QP: I 28, P 28)
 Entropy coding method             : CAVLC
 Profile/Level IDC                 : (66,30)
 Search range restrictions         : none
 RD-optimized mode decision        : used
 Data Partitioning Mode            : 1 partition
 Output File Format                : H.264 Bit Stream File Format
------------------ Average data all frames  -----------------------------------
 SNR Y(dB)                         : 37.38
 SNR U(dB)                         : 41.29
 SNR V(dB)                         : 42.92
 Total bits                        : 66064 (I 21960, P 43936, NVB 168)
 Bit rate (kbit/s)  @ 30.00 Hz     : 660.64
 Bits to avoid Startcode Emulation : 0
 Bits for parameter sets           : 168
-------------------------------------------------------------------------------
Exit JM 8 encoder ver 8.6
请按任意键继续. . .

 

解码————————————————————————————

设置ldecod为启动项目

重新生成项目

如上修改工作目录和输出目录为  $(ProjectDir)bin

下面的配置文件decoder.cfg就可以用于解码

文件内容为

test.264                 ........H.264 coded bitstream
test_dec.yuv             ........Output file, YUV 4:2:0 format
test_rec.yuv             ........Ref sequence (for SNR)
10                       ........Decoded Picture Buffer size
0                        ........NAL mode (0=Annex B, 1: RTP packets)
0                        ........SNR computation offset
1                        ........Poc Scale (1 or 2)
500000                   ........Rate_Decoder
104000                   ........B_decoder
73000                    ........F_decoder
leakybucketparam.cfg     ........LeakyBucket Params

This is a file containing input parameters to the JVT H.264/AVC decoder.
The text line following each parameter is discarded by the decoder.

 

设置命令参数

运行结果:

--------------------------------------------------------------------------
 Decoder config file                    : decoder.cfg
--------------------------------------------------------------------------
 Input H.264 bitstream                  : test.264
 Output decoded YUV 4:2:0               : test_dec.yuv
 Output status file                     : log.dec
 Input reference file                   : test_rec.yuv
--------------------------------------------------------------------------
POC must = frame# or field# for SNRs to be correct
Frame    POC   QP  SnrY    SnrU    SnrV   Time(ms)
  0(I)    0    28  0.0000  0.0000  0.0000    27
  1(I)    2    28  0.0000  0.0000  0.0000    25
  2(I)    4    28  0.0000  0.0000  0.0000    22
-------------------- Average SNR all frames ------------------------------
 SNR Y(dB)           :  0.00
 SNR U(dB)           :  0.00
 SNR V(dB)           :  0.00
 Total decoding time : 0.074 sec
--------------------------------------------------------------------------
 Exit JM 8 decoder, ver 8.6
请按任意键继续. . .

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 2
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
H.264是一种视频编码标准,其中的帧内预测是其中一种压缩技术。在MATLAB中实现H.264编码可以使用一些开源库和工具,例如JM、x264等。以下是一个示例代码,实现了H.264帧内预测编码: ```matlab % Read input video vidObj = VideoReader('input_video.mp4'); % Create output video object outputVideo = VideoWriter('output_video.mp4','MPEG-4'); outputVideo.FrameRate = vidObj.FrameRate; open(outputVideo); % Set H.264 encoder parameters params = struct('Profile','High','Level','4.0','BitRate',5000000,'FrameRate',vidObj.FrameRate); % Loop through each video frame while hasFrame(vidObj) % Read current frame frame = readFrame(vidObj); % Convert to YCbCr color space YCbCr = rgb2ycbcr(frame); % Split YCbCr into separate components Y = YCbCr(:,:,1); Cb = YCbCr(:,:,2); Cr = YCbCr(:,:,3); % Perform frame intra prediction on Y component Y_pred = intra_prediction(Y); % Combine YCbCr components YCbCr_pred = cat(3,Y_pred,Cb,Cr); % Convert back to RGB color space frame_pred = ycbcr2rgb(YCbCr_pred); % Write encoded frame to output video writeVideo(outputVideo,frame_pred); end % Close output video object close(outputVideo); function Y_pred = intra_prediction(Y) % Block size (8x8) block_size = 8; % Pad input image [rows,cols] = size(Y); Y_pad = padarray(Y,[block_size-1 block_size-1],'replicate','post'); % Perform intra prediction on each block for r = 1:block_size:rows for c = 1:block_size:cols % Get current block block = Y_pad(r:r+block_size-1,c:c+block_size-1); % Calculate prediction mode mode = calculate_mode(block); % Perform prediction switch mode case 0 % DC mode pred = mean(block(:)); case 1 % Horizontal mode pred = repmat(block(1,:),[block_size 1]); case 2 % Vertical mode pred = repmat(block(:,1),[1 block_size]); case 3 % Diagonal mode pred = diag(block); pred = repmat(pred(:),[1 block_size]) + repmat(pred(:)',[block_size 1]); pred = pred/(block_size+1); otherwise error('Invalid prediction mode'); end % Subtract prediction from current block Y_pred(r:r+block_size-1,c:c+block_size-1) = block - pred; end end end function mode = calculate_mode(block) % Calculate sum of absolute differences (SAD) for each mode SAD = zeros(4,1); SAD(1) = sum(abs(block(:)-mean(block(:)))); SAD(2) = sum(abs(block(1,:)-mean(block(:)))); SAD(3) = sum(abs(block(:,1)-mean(block(:)))); SAD(4) = sum(abs(diag(block)-mean(block(:)))); % Find mode with minimum SAD [~,mode] = min(SAD); mode = mode-1; end ``` 这段代码实现了一个简单的帧内预测编码器,基于直接模式选择方法(mode selection),并且使用直流、水平、垂直和对角线预测模式进行预测。在实际应用中,需要使用更复杂的编码器和预测算法,以达到更好的压缩效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值