264 编码,写了个脚本,实现批量编码

本文介绍了一种通过解析YUV视频文件名提取视频参数,并使用JM编码器将YUV视频转换为H.264格式的方法。通过对配置文件的修改,实现了自动化的视频编码过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# -*- coding: cp936 -*-

import os  
import sys
import re

pattern = re.compile(r'[0-9]{2,4}')# find the successive 2~4 num.

DataSet_264='C:/Users/Dell/Desktop/264DataSet/'  #destination folder for saving output .264 files.
YUV_VIDEO_FOLDER='C:/Users/Dell/Desktop/YUVDataSet/'  #source folder containing YUV videos
for YUV_video in os.listdir(YUV_VIDEO_FOLDER): #yuv video的名字里面包含了高度,宽度,视频长度等信息。所以只需要在名字中提取。
    #print YUV_video
    video_inf=pattern.findall(YUV_video)
    
    video_width=int(video_inf[0])
    video_height=int(video_inf[1])
    video_frame=int(video_inf[2])

    inputfile=YUV_VIDEO_FOLDER+YUV_video
    outputfile=DataSet_264+YUV_video+'.264'
    




    fin=open('C:/Users/Dell/Desktop/jm_16.1_xmltrace_v1.5/jm_16.1/bin/encoder_baseline.cfg',"rb")
    fout= open('C:/Users/Dell/Desktop/jm_16.1_xmltrace_v1.5/jm_16.1/bin/encoder_baseline_new.cfg', "w")
    for index, line in enumerate(fin):  #枚举出所打开文件的行数和改行的内容。
    
        if index==12:
            line=" InputFile        = %s  " % inputfile   
        if index==15:
            line="FramesToBeEncoded     = %d " % video_frame
        if index==17:
           line=" SourceWidth           = %d " % video_width
        if index==18:
            line="SourceHeight          = %d " % video_height
        if index==20:
            line="OutputWidth           = %d " % video_width
        if index==21:
            line="OutputHeight          = %d " % video_height
        if index==25:
            line="OutputFile            = %s " % outputfile
    
        fout.write(line+'\n')# 将修改写入新文件。
    fin.close()
    fout.close()

    os.system('C:/Users/Dell/Desktop/jm_16.1_xmltrace_v1.5/jm_16.1/bin/lencod.exe  -d  C:/Users/Dell/Desktop/jm_16.1_xmltrace_v1.5/jm_16.1/bin/encoder_baseline_new.cfg')   #利用CMD运行lencod.exe 执行编码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值