zoukankan      html  css  js  c++  java
  • ffmpeg脚本

    1、当前目录生成txt

    bat:   dir /on/b >0.txt

    当前文件+子文件bat dir/s/on/b >0.txt

    2、批量文件夹下图片生成视频

    for /f "delims=[" %i in (input.txt) do D:\Software\ffmpeg-20191026-1054752-win64-static\bin\ffmpeg.exe -f image2 -i F:\cqVideo\19-10-24\19-10-24_16\%i\%d.jpg -vcodec libx264 -r 25 -b 700000 F:\%i.h264

    3、批量视频格式转换

    for %a in ("F:\cqVideo\19-10-26\19-10-26_00\*.h264") do D:\software\ffmpeg-20191028-68f623d-win64-static\bin\ffmpeg.exe -i "%a" -threads 2 -vcodec libx264 -preset slow -crf 20 -y "F:\00result\%~na.mp4"

    4、视频保存为图片,新建文件夹和子文件夹,子文件夹图片用于制作视频

    int main()
    {
        std::ifstream fin("F:\cqVideo\19-10-26MP4\0.txt");//打开原始样本图片文件列表  
        string imgName;
        Mat colorImage;
    
        int videoCnt = 0;
        while (getline(fin, imgName)) //一行一行读取文件列表  
        {
            videoCnt++;
            string videoPath = imgName;
            VideoCapture capture(videoPath);//读入视频
    
            if (!capture.isOpened())//判断是否打开视频文件  
            {
                cout << videoPath << "video not open..." << endl;
                continue;
            }
            string dirName = videoPath.substr(videoPath.find_last_of("\") + 1);
            string saveImageName = dirName.substr(0, dirName.find_first_of("."));//图片文件夹,需要新建
            string hourDirName = videoPath.substr(26, 11);//小时文件夹,需要新建
                                                          //cout << saveDirName << endl;
    
                                                          //保存图片
            string hourDir = "F:\cqVideo\19-10-25\" + hourDirName + "\";
            if (_mkdir(hourDir.c_str()) == -1)
            {
                _mkdir(hourDir.c_str());   // 返回 0 表示创建成功,-1 表示失败
            }
    
            string imageDir = hourDir + saveImageName + "\";
            if (_mkdir(imageDir.c_str()) == -1)
            {
                _mkdir(imageDir.c_str());   // 返回 0 表示创建成功,-1 表示失败
            }
    
            int count = 0;
            while (true)
            {
                count++;
    
                capture >> colorImage;//读入图片
                if (colorImage.empty())
                {
                    cout << "no image..." << endl;
                    break;
                }
    
                if (colorImage.channels() != 3)
                {
                    cout << "not three..." << endl;
                    cvtColor(colorImage, colorImage, CV_GRAY2BGR);
                }
                if (colorImage.rows != 640)
                {
                    cout << videoPath << ", row error" << endl;
                }
                
                Rect roi(297, 623, 7, 8);
                //rectangle(colorImage, roi , Scalar(0, 255, 255),1);
                for (int i = 623; i < 632; i++)
                {
                    for (int j = 297; j < 305; j++)
                    {
                        //cout << (int)colorImage.at<Vec3b>(i, j)[0] << endl;
                        //cout << (int)colorImage.at<Vec3b>(i, j)[1] << endl;
                        //cout << (int)colorImage.at<Vec3b>(i, j)[2] << endl;
                        //操作每一个像素值
                        //蓝色通道
                        colorImage.at<Vec3b>(i, j)[0] = 20;
                        //绿色通道
                        colorImage.at<Vec3b>(i, j)[1] = 20;
                        //红色通道
                        colorImage.at<Vec3b>(i, j)[2] = 20;
                    }
                }
                putText(colorImage, "5", cv::Point(297, 630), CV_FONT_HERSHEY_COMPLEX_SMALL, 0.5, Scalar(255, 255, 255), 1);
    
                string name = imageDir + to_string(count) + ".jpg";
                imwrite(name, colorImage);
    
    
                //imshow("colorImage", colorImage);
                //waitKey(0);
            }
        }
    
        return 0;
    }

    5、单个视频格式转换

    ffmpeg -i input.avi output.mp4
  • 相关阅读:
    Yarn的运行原理(执行流程)
    Hive 表类型简述
    hive 表类型
    Hadoop小知识点总结1
    电商交易项目案例
    乘用车辆和商用车辆销售数据分析
    搜狗搜索日志分析系统
    mysql group by 对多个字段进行分组
    group by
    输出GPLT
  • 原文地址:https://www.cnblogs.com/crazybird123/p/11785239.html
Copyright © 2011-2022 走看看