2013-10-18 2 views
4

카메라 출력을 캡처하고 libavcodec을 사용하여 비디오를 만들려고합니다. 이 작업을 수행하는 방법에 대한 예로서 ffmpeg muxing example을 사용했습니다.libavcodec으로 비디오를 인코딩 할 때 비트율이 매우 높습니다.

문제는 AVCodecContext에서 비트율을 400000으로 설정 했는데도 4 초 비디오의 크기는 ~ 15MB이며 비트 전송률은 ~ 30000kb/s입니다 (이 값은 초당 비트 수로 간주됩니다. kb/s).

나는 또한 명령 줄에서 ffmpeg를 사용하여 비디오를 녹화하려고 시도했으며 ~ 700kb/s의 비트 전송률을 가지고 있습니다.

아무도 왜 비트율이 보존되지 않고 결과 파일이 매우 큰지 알 수 있습니까? 내가 코덱 컨텍스트를 초기화하는 데 사용한 코드는 다음과 같습니다 :

초기화 부분 :

avformat_alloc_output_context2(&m_formatContext, NULL, NULL, filename); 
outputFormat = m_formatContext->oformat; 

codec = avcodec_find_encoder(outputFormat->video_codec); 

m_videoStream = avformat_new_stream(m_formatContext, codec); 

m_videoStream->id = m_formatContext->nb_streams - 1; 

codecContext = m_videoStream->codec; 

codecContext->codec_id = outputFormat->video_codec; 

codecContext->width = m_videoResolution.width(); 
codecContext->height = m_videoResolution.height(); 

int m_bitRate = 400000; 
codecContext->bit_rate = m_bitRate; 
codecContext->rc_min_rate = m_bitRate; 
codecContext->rc_max_rate = m_bitRate; 
codecContext->bit_rate_tolerance = 0; 

codecContext->time_base.den = 20; 
codecContext->time_base.num = 1; 

codecContext->pix_fmt = AV_PIX_FMT_YUV422P; 

if (m_formatContext->oformat->flags & AVFMT_GLOBALHEADER) 
    codecContext->flags |= CODEC_FLAG_GLOBAL_HEADER; 
/* open it */ 
ret = avcodec_open2(codecContext, codec, NULL); 

avFrame = avcodec_alloc_frame(); 

ret = avpicture_alloc(&avPicture, codecContext->pix_fmt, codecContext->width, codecContext->height); 

*((AVPicture *)avFrame) = avPicture; 

av_dump_format(m_formatContext, 0, filename, 1); 

if (!(outputFormat->flags & AVFMT_NOFILE)) { 
    ret = avio_open(&m_formatContext->pb, filename, AVIO_FLAG_WRITE); 
} 

ret = avformat_write_header(m_formatContext, NULL); 

if (avFrame) 
    avFrame->pts = 0; 

답변

2

각 인코더는 자신의 프로필을 가지고 있으며, 사용자가 제공 한 비트 레이트가 힌트이기 때문입니다. 비트율이 너무 작지도 크지도 않은 유효한 값인 경우 코덱은 프로필 목록에서 지원되는 비트 전송률을 선택합니다.

코덱 "기능"도 비트 전송률에 영향을 줄 수 있지만 그 정도는 알고 있습니다.

  • 프레임 크기 (폭, heigth)
  • 비트율
  • 픽셀 포맷
  • 프레임 레이트

I 여전히 투쟁 :

코덱 정보는 최소한의 상관 관계를 정의한 api를 사용하여 코덱에서 비트 전송률을 얻을 수있는 방법을 찾으십시오.하지만 이전에 비트 전송률을 낮추면 해당 프로파일을 찾을 수 있습니다. 코덱 실행 중. 코드와

codecContext->bit_rate = 1; 
avcodec_open2(codecContext, codec, NULL); 

는 FFmpeg 코덱 불만 위에 나열된 상 허용 튜플들의리스트를 기록한다.

참고 : 만 외부 라이브러리

필요하지 않는 코덱으로 시도