从网络上过来的数据流,如何能使用ffmpeg来做转码?

37 views
Skip to first unread message

Lee

unread,
Jan 4, 2007, 1:04:01 AM1/4/07
to smartAV
从网络上过来的数据流,如何能使用ffmpeg来做转码?

假设数据流已经可以实事获取到内存中.

Smart Song

unread,
Jan 4, 2007, 2:17:16 AM1/4/07
to sma...@googlegroups.com
Sure!
 
Just create a AVCodecContext, and then call avcodec_decode_video/avcodec_decode_audio.....
 
You can ref the following samples
 

//XXX: MUST init priv_data_len and priv_data for wmv9 sequence header
int wmv9_init_decoder(VideoContext **vc,
    HWND disp_hwnd, HDC hdc,
    void *priv_data, int priv_data_len,
    int framewidth, int frameheight,
    int dispwidth, int dispheight,
    int frame_rate,int frame_rate_base)
{
    VideoContext *pvc = NULL;
    AVStream *st;
    AVCodec *codec;
    uint8_t *buf = NULL;
    int size;

    *vc = NULL;

    pvc = av_mallocz(sizeof(VideoContext));
    if(!pvc)return -1;

    if(dispwidth < 16)
        dispwidth = 16;
    if(dispheight < 16)
        dispheight = 16;
    pvc->m_display_hwnd = disp_hwnd;
    pvc->m_hDC = hdc;
    pvc->width = framewidth;
    pvc->height = frameheight;
    pvc->dispwidth = dispwidth;
    pvc->dispheight = dispheight;
    pvc->frame_rate = frame_rate;
    pvc->frame_rate_base = frame_rate_base;

    size = avpicture_get_size(PIX_FMT_YUV420P,pvc->width,pvc->height);
    buf = (uint8_t*)av_mallocz(size);
    if (!buf)
        return -1;
    avpicture_fill(&pvc->m_current_frame,buf,PIX_FMT_YUV420P,pvc->width,pvc->height);
    memset(pvc->m_current_frame.data[0],16,pvc->width*pvc->height);
    memset(pvc->m_current_frame.data[1],128,pvc->width*pvc->height/2);
    if(wmv9_create_preview_context(pvc,dispwidth,dispheight) < 0)
        return -1;

    st = av_new_stream(&pvc->stubAVFmtCtx,0);
    if(!st){
        av_freep(&pvc->m_picture_bmp.data[0]);
        av_free(&pvc);
        return -1;
    }
    av_set_pts_info(st, 32, 1, 1000);
    pvc->avctx = st->codec;
    pvc->avctx->width = framewidth;
    pvc->avctx->height = frameheight;
    pvc->avctx->codec_id = CODEC_ID_WMV3;
    pvc->avctx->thread_count = 2;
    pvc->avctx->extradata_size = priv_data_len;
    pvc->avctx->extradata = av_mallocz(priv_data_len + FF_INPUT_BUFFER_PADDING_SIZE);
    memcpy(pvc->avctx->extradata,priv_data,priv_data_len);
    codec = avcodec_find_decoder(pvc->avctx->codec_id);
    if(avcodec_open(pvc->avctx,codec) < 0)
        return -1;//fixme
    pvc->m_WriteSemaphore = CreateSemaphore(0,1,1,NULL);
    *vc = pvc;

    return 0;
}

Please contact me if you need more detail information
 
On 1/4/07, Lee <lee...@gmail.com> wrote:
, ffmpeg ?

.


http://www.fastreaming.com
Reply all
Reply to author
Forward
0 new messages