2013-03-27 34 views
10

Tôi đang sử dụng OpenCV với ffmpeg trên máy mac để viết video. Tôi đã có thể ghi thành công các tệp .avi bằng mã codec/bốncc, FMP4. Tuy nhiên, tôi muốn viết các tệp .mp4. Khi tôi cố gắng viết một file .mp4 sử dụng fourcc FMP4 tôi nhận được lỗi này:Viết một tệp MP4 trên máy Mac với OpenCV ffmpeg

[mp4 @ 0x100b4ec00] Tag FMP4/0x34504d46 incompatible with output codec id '13' ([0][0][0]) 

Khi tôi sử dụng AVC1 tôi nhận được lỗi sau:

[libx264 @ 0x104003000] broken ffmpeg default settings detected 
[libx264 @ 0x104003000] use an encoding preset (e.g. -vpre medium) 
[libx264 @ 0x104003000] preset usage: -vpre <speed> -vpre <profile> 
[libx264 @ 0x104003000] speed presets are listed in x264 --help 
[libx264 @ 0x104003000] profile is optional; x264 defaults to high 
Could not open codec 'libx264': Unspecified error 

Có ai ở đây biết codec quyền sử dụng với OpenCV và ffmpeg để ghi vào một vùng chứa MP4 trên máy Mac?

Nếu AVC1 là codec đúng, làm cách nào để cài đặt ffmpeg + OpenCV chính xác? Tôi đã làm

brew install gpac 
brew install ffmpeg 
brew install opencv 

Cuộc gọi tôi đang sử dụng để mở videowriter:

fourcc = cv2.cv.CV_FOURCC('A', 'V', 'C', '1') 
video_out = cv2.VideoWriter(
    filename=output_filename, 
    fourcc=fourcc, 
    fps=video_fps, 
    frameSize=(video_width,video_height), 
    isColor=1) 

Khi tôi chạy x264 --help tôi nhận được

% x264 --help 
x264 core:125 
Syntax: x264 [options] -o outfile infile 

Infile can be raw (in which case resolution is required), 
    or YUV4MPEG (*.y4m), 
    or Avisynth if compiled with support (no). 
    or libav* formats if compiled with lavf support (no) or ffms support (no). 
Outfile type is selected by filename: 
.264 -> Raw bytestream 
.mkv -> Matroska 
.flv -> Flash Video 
.mp4 -> MP4 if compiled with GPAC support (no) 
Output bit depth: 8 (configured at compile time) 

Options: 

    -h, --help     List basic options 
     --longhelp    List more options 
     --fullhelp    List all options 

Example usage: 

     Constant quality mode: 
      x264 --crf 24 -o <output> <input> 

     Two-pass with a bitrate of 1000kbps: 
      x264 --pass 1 --bitrate 1000 -o <output> <input> 
      x264 --pass 2 --bitrate 1000 -o <output> <input> 

     Lossless: 
      x264 --qp 0 -o <output> <input> 

     Maximum PSNR at the cost of speed and visual quality: 
      x264 --preset placebo --tune psnr -o <output> <input> 

     Constant bitrate at 1000kbps with a 2 second-buffer: 
      x264 --vbv-bufsize 2000 --bitrate 1000 -o <output> <input> 

Presets: 

     --profile <string>  Force the limits of an H.264 profile 
            Overrides all settings. 
            - baseline,main,high,high10,high422,high444 
     --preset <string>  Use a preset to select encoding settings [medium] 
            Overridden by user settings. 
            - ultrafast,superfast,veryfast,faster,fast 
            - medium,slow,slower,veryslow,placebo 
     --tune <string>   Tune the settings for a particular type of source 
           or situation 
            Overridden by user settings. 
            Multiple tunings are separated by commas. 
            Only one psy tuning can be used at a time. 
            - psy tunings: film,animation,grain, 
               stillimage,psnr,ssim 
            - other tunings: fastdecode,zerolatency 

Frame-type options: 

    -I, --keyint <integer or "infinite"> Maximum GOP size [250] 
     --tff     Enable interlaced mode (top field first) 
     --bff     Enable interlaced mode (bottom field first) 
     --pulldown <string>  Use soft pulldown to change frame rate 
            - none, 22, 32, 64, double, triple, euro (requires cfr input) 

Ratecontrol: 

    -B, --bitrate <integer>  Set bitrate (kbit/s) 
     --crf <float>   Quality-based VBR (0-51) [23.0] 
     --vbv-maxrate <integer> Max local bitrate (kbit/s) [0] 
     --vbv-bufsize <integer> Set size of the VBV buffer (kbit) [0] 
    -p, --pass <integer>  Enable multipass ratecontrol 
            - 1: First pass, creates stats file 
            - 2: Last pass, does not overwrite stats file 

Input/Output: 

    -o, --output <string>  Specify output file 
     --sar width:height  Specify Sample Aspect Ratio 
     --fps <float|rational> Specify framerate 
     --seek <integer>  First frame to encode 
     --frames <integer>  Maximum number of frames to encode 
     --level <string>  Specify level (as defined by Annex A) 
     --quiet     Quiet Mode 

Filtering: 

     --vf, --video-filter <filter0>/<filter1>/... Apply video filtering to the input file 

     Filter options may be specified in <filter>:<option>=<value> format. 

     Available filters: 
     crop:left,top,right,bottom 
     select_every:step,offset1[,...] 

Cảm ơn, -s

+0

Containers không có FOURCCs - chỉ codec và các định dạng pixel để. 'FMP4' là video MPEG-4 (Phần 2). Bạn đang sử dụng codec video nào? H.264/MPEG-4 AVC sẽ là 'AVC1' hoặc những người khác (xem http://www.fourcc.org/codecs.php) – slhck

+0

Xin chào, @slhck, đó là câu hỏi của tôi. Tôi nên sử dụng codec video nào khi ghi vào vùng chứa MP4. Tôi đã cập nhật câu hỏi để rõ ràng hơn về điểm đó. Cảm ơn. –

+0

Vui lòng cung cấp đầy đủ dòng lệnh chưa được xử lý mà bạn đang sử dụng, bao gồm cả đầu ra hoàn chỉnh. Bạn đã chắc chắn rằng bạn đã cài đặt x264 chưa? ('brew install x264; brew uninstall ffmpeg; brew install ffmpeg') – slhck

Trả lời

7

Điều này có vẻ một câu hỏi cũ nhưng tôi sẽ trả lời nó vì lợi ích của những người vấp ngã nó. Bạn không thể nhận được ffmpeg làm việc với x264 trừ khi bạn cài đặt ffmpeg từ nguồn. Vì vậy, cài đặt nhị phân từ trình quản lý gói sẽ không bật gói x264. Bạn có thể cài đặt nhị phân x264 (nhưng có thể bạn muốn sử dụng nguồn để kiểm soát phiên bản x264 nào bạn muốn tương thích với phiên bản ffmpeg phù hợp).

Vì vậy, để trả lời câu hỏi này: Cài đặt của bạn cần cài đặt x264 trước và sau đó biên dịch ffmpeg bằng --enable-libx264.

Hiện có rất nhiều hướng dẫn về cách biên dịch ffmpeg từ nguồn. Một tìm kiếm google nhanh chóng ném lên này: http://www.martinlos.com/?p=41 cho mac và https://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide cho ubuntu. Tôi thường xuyên biên dịch từ nguồn trên ubuntu và biết những hướng dẫn làm việc và những mac có vẻ tốt là tốt.

Các vấn đề liên quan