2012-01-02 72 views
1

我有一個C++庫,實時編碼視頻從網絡攝像頭到MP4文件(H264)。是我有設置如下:如何使用ffmpeg編碼視頻以在Android上播放?

codecContex->profile=FF_PROFILE_H264_BASELINE; //Baseline 
    codecContex->gop_size=250; 
    codecContex->max_b_frames=0; 
    codecContex->max_qdiff=4; 
    codecContex->me_method=libffmpeg::ME_HEX; 
    codecContex->me_range=16; 
    codecContex->qmin=10; 
    codecContex->qmax=51; 
    codecContex->qcompress=0.6; 
    codecContex->keyint_min=10; 
    codecContex->trellis=0; 
    codecContex->level=13; //Level 1.3 
    codecContex->weighted_p_pred = 2; 
    codecContex->flags2|=CODEC_FLAG2_WPRED+CODEC_FLAG2_8X8DCT; 

這將創建一個在iOS設備和Windows Phone 7個設備,但不會在Android設備上播放MP4文件。我讀過Android僅支持使用基準配置文件編碼的電影。這些設置應該會生成基準電影,但是當我使用MediaInfo查看生成的MP4文件時,它會顯示它是AVC([email protected])。這也許就是爲什麼它不工作,但我似乎無法得到它的產生與AVC([email protected])的東西......

如果我刪除最後一行:

codecContex->flags2|=CODEC_FLAG2_WPRED+CODEC_FLAG2_8X8DCT; 

然後MediaInfo將文件報告爲「AVC([email protected])」 - 但這些標誌是基線配置文件的一部分!

回答

2

我得到了它與下列選項基準編碼:

codecContex->coder_type = 0; 
    codecContex->flags|=CODEC_FLAG_LOOP_FILTER; 
    codecContex->profile=FF_PROFILE_H264_BASELINE; //Baseline 
    codecContex->scenechange_threshold = 40; 
    codecContex->gop_size=250; 
    codecContex->max_b_frames=0; 
    codecContex->max_qdiff=4; 
    codecContex->me_method=7; 
    codecContex->me_range=16; 
    codecContex->me_cmp|= 1; 
    codecContex->me_subpel_quality = 6; 
    codecContex->qmin=10; 
    codecContex->qmax=51; 
    codecContex->qcompress=0.6; 
    codecContex->keyint_min=25; 
    codecContex->trellis=0; 
    codecContex->level=13; //Level 1.3 
    codecContex->refs = 1; 
    codecContex->weighted_p_pred = 0; 
    codecContex->crf = 20.0f; 
    codecContex->flags2|=CODEC_FLAG2_BPYRAMID-CODEC_FLAG2_WPRED-CODEC_FLAG2_8X8DCT; 

...視頻不會在HTML5視頻播放元素但如果你在瀏覽器中直接加載MP4文件。該電影的寬度也必須爲480像素或更少。

相關問題