FFMPEG 로딩 속도 개선 방법

kkokkokim14의 이미지

안녕하세요

IOS 에서 RTSP영상을 스트리밍하기위해서 FFMPEG라는 오픈라이브러리를 이용하는데요.

재생은 잘됩니다. 그런데 영상을 가져오는데 초반에 로딩하는곳에서 시간을 잡아먹어서 그런데.

이것을 해결하기위해서 찾아보니까 정보로는 아래와 같은 내용이 있습니다.
================================================================================================
1. 동영상 포멧이 정해져 있을 경우 컨테이너 형식을 명시적으로 줘서 재생을 시도하면 컨테이너 형식을 판단하는 시간이
없어지기 때문에 다소 시작 속도가 증가 됩니다.

2. 컨테이너 형식을 명시적으로 주더라도 해당 형식에 대해 파싱을 수행할 때 시간이 걸릴 수 있습니다.
이 부분에 대한 코드 수정은 힘듭니다만 만약 컨테이너 형식을 결정하실 수 있으면,
TS 형식으로 정해서 재생을 시작하면 다소 빨라 질 수 있습니다.

3 FFMPEG의 경우 버퍼링을 2M 정도 한 후 재생을 시작하게 되어 있는데
FFMPEG 소스를 수정하여 버퍼링 할 사이즈를 줄일 경우 약간 시작 시간이 빨라질 수 도 있습니다.

4. 시작 시간과는 크게 상관이 없지만 가이드 드린 방식의 경우
sws_scale을 사용하여 YUV420->RGB565 영상으로 변경 후 그리고 있는데. 출력 사이즈가 커지면 커질 수록 연상량이 많아져 한장 그리는데 시간이 더 많이 걸리며
최악의 경우 칼라변환하는데 33ms가 넘어 30fps 가 안 나올 수 있습니다. 이 부분을 openGL을 이용하여 그리면 빠르게 됩니다.
=====================================================================================================

소스코드입니다.
아래에서
avformat_open_input
avformat_find_stream_info
이둘을 완전히 뜯어고쳐야된다고 하던데 FFMPEG 고수님들 도와주세요. ㅜㅜ

if (!(self=[super init])) return nil;


AVCodec *pCodec;
// Register all formats and codecs
avcodec_register_all();
av_register_all();
//avformat_network_init();

// Set the RTSP Options
AVDictionary *opts = 0;
if (usesTcp)
av_dict_set(&opts, "rtsp_transport", "tcp", 0);

if (avformat_open_input(&pFormatCtx, [moviePath UTF8String], NULL, NULL) !=0 ) {
av_log(NULL, AV_LOG_ERROR, "Couldn't open file\n");
goto initError;
}


// Retrieve stream information
if (avformat_find_stream_info(pFormatCtx,NULL) < 0) {
av_log(NULL, AV_LOG_ERROR, "Couldn't find stream information\n");
goto initError;
}


// Find the first video stream
videoStream=-1;
audioStream=-1;

for (int i=0; inb_streams; i++) {
if (pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
NSLog(@"found video stream");
videoStream=i;
}

if (pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO) {
audioStream=i;
NSLog(@"found audio stream");
}
}

if (videoStream==-1 && audioStream==-1) {
goto initError;
}

// Get a pointer to the codec context for the video stream

pCodecCtx = pFormatCtx->streams[videoStream]->codec;


// Find the decoder for the video stream
//pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
pCodec = avcodec_find_decoder(CODEC_ID_H264);
if (pCodec == NULL) {
av_log(NULL, AV_LOG_ERROR, "Unsupported codec!\n");
goto initError;
}
// Open codec
if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) {
av_log(NULL, AV_LOG_ERROR, "Cannot open video decoder\n");
goto initError;
}

if (audioStream > -1 ) {
NSLog(@"set up audiodecoder");
[self setupAudioDecoder];
}
// Allocate video frame
pFrame = avcodec_alloc_frame();
outputWidth = pCodecCtx->width;
self.outputHeight = pCodecCtx->height;
return self;
initError:
[self release];
return nil;

shint의 이미지

opengl은 어떻게 구현되었을까요... 저는 항상 궁금하네요... ㅡ_ㅡ;;

그래픽 카드가 없이도.
매트릭스 조합이나.
팔레트 사용이나.
중복 연산을 줄이며.
알고리즘을 응용하면. 그 정도 성능이 나올거 같은 생각이 듭니다. ㅇ_ㅇ;;

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com

검색중에의 이미지

// 저의 경우는
// avformat_find_stream_info() 호출 전에
pFormatCtx->probesize = 4096; // 이 크기는 적당하게 테스트...
// 로 해결되었습니다.

소오름의 이미지

처음 연결이 오래걸려서 검색중인 내용인데 며칠안된 따끈한 정보를 보니 소름돋네요~~
와~~ 정말 감사합니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.