티스토리 뷰

728x90

출처 : UltraStar Deluxe
Flamefire / Usdx
Re: XE3 + FireMonkeyでScanlineプロパティが消えた?
Bitmap의 Pixel에 접근(TBitmap.Map, TBitmapData)
FFmpeg으로 미디어 스트림 열기 (ver 0.1)
千 Line 으로 비디오플레이어 만들기 1
네이버 건강 서비스 - hello world NHN 개발자 블로그
FMX.Types.TBitmap.Unmap

FireMonkey에서 FFMpeg를 이용해서 이미지 챕쳐 하는 부분을 구현했습니다.
기존에 데이터는 Bitmap의 픽셀단위로 복사해서 구현했는데,
TImageControl 컴포넌트의 Bitamp.TBitmapData에 바로 데이터를 쓰도록 하는 방법을 찾아서,
기존 코드에 불필요한 부분을 제거하고 다시 구현했습니다.

FireMonkey에서 FFMpeg 사용하는 부분도 간단하게 정리했습니다..

파일 포맷과 코덱을 라이브러리 등록

av_register_all();

동영상 파일 읽기

errnum := avformat_open_input(@fFormatContext, Edit1.Text, nil, nil);

스트림 정보 조회

errnum := avformat_find_stream_info(fFormatContext, nil);

비디오, 오디오 스트림 Index 찾기

  for i := 0 to fFormatContext.nb_streams-1 do
  begin
    Stream := PPAVStream(PtrUInt(fFormatContext.streams) + i * Sizeof(pointer))^;

    if (Stream.codec.codec_type = CODEC_TYPE_VIDEO) and
       (FirstVideoStream < 0) then
    begin
      FirstVideoStream := i;
    end;

    if (Stream.codec.codec_type = CODEC_TYPE_AUDIO) and
       (FirstAudioStream < 0) then
    begin
      FirstAudioStream := i;
    end;
  end;

Codec 찾기

fCodec := avcodec_find_decoder(fCodecContext^.codec_id);

Codec 열기

errnum := avcodec_open2(fCodecContext, fCodec, nil);

동영상 정보 출력

  Memo1.Lines.Add('Found a matching Codec: '+ fCodecContext^.Codec.Name + sLineBreak +
    sLineBreak +
    '  Width = '+inttostr(fCodecContext^.width) +
    ', Height='+inttostr(fCodecContext^.height) + sLineBreak +
    '  Aspect    : '+inttostr(fCodecContext^.sample_aspect_ratio.num) + '/' +
                     inttostr(fCodecContext^.sample_aspect_ratio.den) + sLineBreak +
    '  Framerate : '+inttostr(fCodecContext^.time_base.num) + '/' +
                     inttostr(fCodecContext^.time_base.den));

Bitmap 객체 생성, TBitmapData

    ImageControl1.Bitmap := TBitmap.Create(fCodecContext^.width, fCodecContext^.Height);
    ImageControl1.Bitmap.Map(TMapAccess.maWrite, FBmpData);

AVPicture 구조체에 TImageControl.Bitmap의 버퍼와 연결

  errnum := avpicture_fill(PAVPicture(fAVFrameRGB), FBmpData.Data, PIXEL_FMT_FFMPEG,
      fCodecContext^.width, fCodecContext^.height);

파일에서 데이터를 읽기

errnum := av_read_frame(fFormatContext, AVPacket);

디코딩된 YUV 데이터 얻기

avcodec_decode_video2(fCodecContext, fAVFrame, frameFinished, @AVPacket);

색상 공간 변환

errnum := sws_scale(fSwScaleContext, @fAVFrame.data, @fAVFrame.linesize,
                0, fCodecContext^.Height,
                @fAVFrameRGB.data, @fAVFrameRGB.linesize);

Finalizes the customizing session of the current bitmap.

ImageControl1.Bitmap.Unmap(FBmpData);

Mac

Windows

Android

 

댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함