1

如题,

我正在使用 ffmpeg 在 Mac 上开发一个项目。它在我的 Mac 上运行,将帧编码为 vp9 和 vp8。但是当我在 ubuntu 中的 docker 映像上运行它时,函数avcodec_open2()返回-22错误。(仅适用于 vp9&vp8,h264 有效)。

我想知道错误是否来自设置参数部分?但是让它在mac上运行但在ubuntu中运行仍然很奇怪。

有没有人有类似的经历?

bool open_video(AVFormatContext * oc,AVCodec * codec,OutputStream * ost,AVDictionary * opt_arg, bool reduceQuality) {
    int ret;
    AVCodecContext * c = ost->st->codec;
    AVDictionary * opt = NULL;
    av_dict_copy(&opt,opt_arg,0);

    if(codec264){
      // http://arstechnica.com/civis/viewtopic.php?f=6&t=1239375
      av_dict_set(&opt,"refs",    "3",          0);
      av_dict_set(&opt,"vprofile","main",       0);  // 2 versions to support differents libav/ffmpeg
      av_dict_set(&opt,"profile", "main",       0);
      
      //av_dict_set(&opt,"preset","superfast",0);
      //av_dict_set(&opt,"preset","ultrafast",0);
      av_dict_set(&opt,"preset","superfast",0);
      //av_dict_set(&opt,"preset","slow",0);
      
      //https://mattgadient.com/2013/06/12/a-best-settings-guide-for-handbrake-0-9-9/
      //av_dict_set(&opt, "tune", "zerolatency", 0); //bluerry but very small size
      //av_dict_set(&opt, "tune", "fastdecode", 0); // hd but large size
      // 23 300k, 29 150k, 35 75k
      if(reduceQuality)
        av_dict_set(&opt, "crf", "35", 0); //35 +-6 decrease/increase bitrate half/twice
      else
        av_dict_set(&opt, "crf", "29", 0); //29 +-6 decrease/increase bitrate half/twice
    
    }
    else if (codecVP9)
    { 
        // Setting explanation:
        // http://wiki.webmproject.org/ffmpeg/vp9-encoding-guide
        // https://developers.google.com/media/vp9/live-encoding/
        // https://developers.google.com/media/vp9/settings/vod/
        // https://developers.google.com/media/vp9/bitrate-modes/

        if(reduceQuality) //crf is the quality value for VP9 (0-63), lower the better quality youll get 
          av_dict_set(&opt, "crf"    ,      "40",         0); 
        else
          av_dict_set(&opt, "crf"    ,      "45",         0);
        av_dict_set(&opt, "speed"  ,        "8" ,         0);
        av_dict_set(&opt, "quality",        "realtime",   0); //realtime is recommended
        //av_dict_set(&opt, "threads",        "4" ,         0);
        //av_dict_set(&opt, "tile-columns",   "2",          0);
        //av_dict_set(&opt, "frame-parallel", "1",          0);
        //av_dict_set(&opt, "row-mt",         "1",          0);
        av_dict_set(&opt, "b:v",            "1",         0);
        av_dict_set(&opt, "g",              "400",        0); //key frame interval (big difference in vid size)

        //av_dict_set(&opt, "maxrate",        "3k",         0);
        //av_dict_set(&opt, "minrate",        "1k",         0);
        //av_dict_set(&opt, "hwaccel",        "vaapi",      0);
        //av_dict_set(&opt, "c:v",            "libvpx-vp9", 0);
        
    }
    else if (codecVP8)
    {
        // https://trac.ffmpeg.org/wiki/Encode/VP8 
        av_dict_set(&opt, "passes"    ,        "1" ,         0);   
        av_dict_set(&opt, "cpu-used"  ,        "15" ,         0); 
        av_dict_set(&opt, "qmax"      ,        "63",         0);   
        av_dict_set(&opt, "rt"        ,          "",         0); // realtime setting
        //av_dict_set(&opt, "crf"       ,        "10",         0);   

        if(reduceQuality)
          av_dict_set(&opt, "qmin"     ,        "40",        0); // Lower quality, smaller sizes
        else
          av_dict_set(&opt, "qmin"     ,        "35",        0); // Higher quality, larger sizes
    }
    else 
    {
        if(reduceQuality)
            av_dict_set(&opt, "x265-params", "crf=29", 0);
        else
            av_dict_set(&opt, "x265-params", "crf=23", 0);
        
        av_dict_set(&opt, "preset", "ultrafast", 0);
        av_dict_set(&opt, "tune", "zerolatency", 0);
//        av_dict_set(&opt, "profile", "main", 0);
    }
      
    // Open the codec
    ret = avcodec_open2(c,codec,&opt);
    av_dict_free(&opt);
    if (ret < 0) {
        cout << "Could not open video codec. (error code:" << ret << ")\n";
        return false;
    } // if

编辑:有谁知道ffmpeg-linux是否使用不同的参数名称从其他平台(如Mac)进行设置?

Eidt2:似乎即使我没有设置任何选项参数,它仍然给我-22错误。前任:ret = avcodec_open2(c, codec, NULL)

4

1 回答 1

0

据我所知,错误-22EINVAL. 这意味着其中一个参数可能是原因。

于 2018-12-04T07:52:28.913 回答