안녕하세요 ffmpeg 코드 구동관련하여...

huss5210의 이미지

안녕하세요 .. ffmpeg 샘플을 통해 구동해 보려는데..안되어서...
여기까지 왔습니다.

ffmpeg 구동 버전은 ..

ffmpeg version N-56712-g07da085 Copyright (c) 2000-2013 the FFmpeg developers
built on Sep 29 2013 17:10:02 with gcc 4.6 (Debian 4.6.3-14+rpi1)
configuration: --enable-x11grab --enable-memalign-hack --enable-pthreads --enable-libmp3lame --enable-libx264 --enable-gpl --disable-shared --enable-static
libavutil 52. 46.100 / 52. 46.100
libavcodec 55. 33.101 / 55. 33.101
libavformat 55. 18.104 / 55. 18.104
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 88.100 / 3. 88.100
libswscale 2. 5.100 / 2. 5.100
libswresample 0. 17.103 / 0. 17.103
libpostproc 52. 3.100 / 52. 3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

api 샘플구동을 하는데..

$ ./tutorial01 구동시...
Video encoding
Check OK1
Segmentation fault

소스는... 밑에 부분 ...

/*
* Copyright (c) 2001 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

/**
* @file
* libavcodec API use example.
*
* Note that libavcodec only handles codecs (mpeg, mpeg4, etc...),
* not file formats (avi, vob, mp4, mov, mkv, mxf, flv, mpegts, mpegps, etc...). See library 'libavformat' for the
* format handling
* @example doc/examples/decoding_encoding.c
*/

#include
#include
#include
#include
#include
//#include

#include

#ifdef HAVE_AV_CONFIG_H
#undef HAVE_AV_CONFIG_H
#endif

#ifdef HAVE_AV_CONFIG_H
#undef HAVE_AV_CONFIG_H
#endif
extern "C" {
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

# include
# include
# include

}

#define INBUF_SIZE 4096
#define AUDIO_INBUF_SIZE 20480
#define AUDIO_REFILL_THRESH 4096


using namespace std;

/*
* Video encoding example
*/
static void video_encode_example(const char *filename)
{
AVCodec *codec;
AVCodecContext *c= NULL;
int i, out_size, size, x, y, outbuf_size;
FILE *f;
AVFrame *picture;
uint8_t *outbuf, *picture_buf;

printf("Video encoding\n");

/* find the mpeg1 video encoder */
codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
if (!codec) {
fprintf(stderr, "codec not found\n");
exit(1);
}

c = avcodec_alloc_context3(codec);
picture= avcodec_alloc_frame();

/* put sample parameters */
c->bit_rate = 400000;
/* resolution must be a multiple of two */
c->width = 352;
c->height = 288;
/* frames per second */
c->time_base= (AVRational){1,25};
c->gop_size = 10; /* emit one intra frame every ten frames */
c->max_b_frames=1;
c->pix_fmt = PIX_FMT_YUV420P;

c->codec_id = codec->id;
c->codec_type = AVMEDIA_TYPE_VIDEO ;

cout << "Check OK1" << endl; //여기는 무난히 넘어가는데..
/* open it */
if (avcodec_open2(c, codec, NULL) < 0) { //여기를 넘어가지 못하더라고요...
fprintf(stderr, "could not open codec\n");
exit(1);
}
cout << "Check OK2" << endl;
f = fopen(filename, "wb");
if (!f) {
fprintf(stderr, "could not open %s\n", filename);
exit(1);
}

/* alloc image and output buffer */
outbuf_size = 100000;

outbuf_size = avpicture_get_size(codecCtxOut->pix_fmt, codecCtxOut->width, codecCtxOut->height);

outbuf =(uint8_t*)malloc(outbuf_size);

picture_buf =(uint8_t*)malloc((size * 3) / 2); /* size for YUV 420 */

picture->data[0] = picture_buf;
picture->data[1] = picture->data[0] + size;
picture->data[2] = picture->data[1] + size / 4;
picture->linesize[0] = c->width;
picture->linesize[1] = c->width / 2;
picture->linesize[2] = c->width / 2;

/* encode 1 second of video */
for(i=0;i<25;i++) {
fflush(stdout);
/* prepare a dummy image */
/* Y */
for(y=0;yheight;y++) {
for(x=0;xwidth;x++) {
picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3;
}
}

/* Cb and Cr */
for(y=0;yheight/2;y++) {
for(x=0;xwidth/2;x++) {
picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2;
picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5;
}
}

/* encode the image */
out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
printf("encoding frame %3d (size=%5d)\n", i, out_size);
fwrite(outbuf, 1, out_size, f);
}

/* get the delayed frames */
for(; out_size; i++) {
fflush(stdout);

out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);
printf("write frame %3d (size=%5d)\n", i, out_size);
fwrite(outbuf, 1, out_size, f);
}

/* add sequence end code to have a real mpeg file */
outbuf[0] = 0x00;
outbuf[1] = 0x00;
outbuf[2] = 0x01;
outbuf[3] = 0xb7;
fwrite(outbuf, 1, 4, f);
fclose(f);
free(picture_buf);
free(outbuf);

avcodec_close(c);
av_free(c);
av_free(picture);
printf("\n");
}

int main(int argc, char **argv)
{

/* register all the codecs */

avcodec_register_all();

av_register_all();

video_encode_example("test.avi");

return 0;
}

도대체 왜

Video encoding
Check OK1
Segmentation fault <<<<이게 걸리는지 알수가 없습니다. 아시는분?????

컴파일이 되지나 말지... 아우.....

답변좀 달여주시면 정말 감사드리겠습니다.

shint의 이미지

1. 해보니까. size가 잘못됐습니다.
size를 width * height 로 했더니 잘 되나 싶었는데.

2. 다음 부분에서 또 문제가 생겼습니다.
picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3;

그래서. 관련된 소스를 찾아보니.
그것과 똑같은 예제가 있어서 해보고 있습니다.
http://ffmpeg.org/doxygen/trunk/api-example_8c-source.html

mp4 를 해보니까. 잘 안되는거 같아서.
여기서 http://hubblesource.stsci.edu/sources/video/clips/
mp2 를 다운 받아서 실행 해보니. 이렇게 실행된 화면이 보입니다.

ac-tex damaged at 29 1
http://ligel.tistory.com/32

errors in B frame saving frame 4802 라고 보이네요.

pgm 파일이 저장은 되는데. 잘못 저장 됩니다. ㅇ_ㅇ;;

[mpeg1video @ 00424200] ac-tex damaged at 30 6
[mpeg1video @ 00424200] concealing 1080 DC, 1080 AC, 1080 MV errors in B frame
saving frame 4802
[mpeg1video @ 00424200] concealing 1080 DC, 1080 AC, 1080 MV errors in ? frame
saving frame 4803
[mpeg1video @ 00424200] concealing 1080 DC, 1080 AC, 1080 MV errors in ? frame
saving frame 4804
[mpeg1video @ 00424200] concealing 1080 DC, 1080 AC, 1080 MV errors in ? frame
saving frame 4805
[mpeg1video @ 00424200] concealing 1080 DC, 1080 AC, 1080 MV errors in ? frame
saving frame 4806
[mpeg1video @ 00424200] concealing 1080 DC, 1080 AC, 1080 MV errors in ? frame
saving frame 4807
saving last frame 4808

그래서. 혹시나 코덱이 문젠가 확인해보니.
CODEC_ID_MPEG1VIDEO 이것이 있었네요.

MPEG1 으로 다운 받아서 .mp1 으로 사용해보니.
조금 일그러진 이미지가 보입니다. ㅇ_ㅇ;;
가짜로 성공은 했지만... 마치 도스박스에 게임 처럼 영상이 휘어지네요.

댓글 첨부 파일: 
첨부파일 크기
Image icon MP1 PGM 변환.PNG290.77 KB

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

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

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

huss5210의 이미지

ㅋㅋㅋ 감사드립니다.

shint의 이미지

1. MPEG1을 PPM 으로 저장하는것은 됐습니다.

2. 그렇지만. MPEG1을 YUV에 PGM으로 저장하는것은 잘 안되네요. ㅇ_ㅇ;;
아마도. http://ianccani.tistory.com/27 여기에서 말하는것 처럼
sws_getContext(), sws_scale()으로 화면 설정을 하면 될거 같습니다.

제가 착각한것인지 모르지만. RGB로 저장하면 PGM에 저장하면 될줄 알았는데.
그건 아니네요.

그냥. YUV를 scale()만 변경해서 PGM으로 저장하는것이 맞는거 같습니다.
지금 해봤는데. 그렇게 해도 되지는 않네요. ㅡ_ㅡ;;

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

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

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

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.