我在这里用Makefile上传了完整编译的代码:
如果我设置1280x720,我会遇到分段错误:
[libx264 @ 0x7fdf4d25a600] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x7fdf4d25a600] profile High, level 3.1
[libx264 @ 0x7fdf4d25a600] 264 - core 148 r2748 97eaef2 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=12 keyint_min=1 scenecut=40 intra_refresh=0 rc_lookahead=12 rc=abr mbtree=1 bitrate=3400 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '1.mp4':
Stream #0:0: Video: h264, yuv420p, 1280x720, q=2-31, 3400 kb/s, 20 tbn
Stream #0:1: Audio: aac (LC), 44100 Hz, stereo, fltp, 64 kb/s
sws_scale BEGIN
./MakeVideo.sh: line 2: 26422 Segmentation fault: 11 ./MakeVideo 1.mp4
这一行存在一些问题:
std::cout << "sws_scale BEGIN\n";
sws_scale( sws_context, ( const uint8_t * const * ) &rgb, inLinesize, 0, frame->height, frame->data, frame->linesize );
std::cout << "sws_scale END\n";
但如果我将视频大小设置为1920x1080或320x240 - 一切正常。
这是某种魔力吗?还是个bug?
OS X 10.12.3 ffmpeg / 3.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc = clang --host-cflags = - host-ldflags = --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
答案 0 :(得分:1)
您的代码存在很多问题。例如
void ffmpeg_encoder_set_frame_yuv_from_rgb( AVFrame *frame ) {
// frame pointer may be NULL, but is later used without check
uint8_t *rgb = (uint8_t *) malloc( 3 * sizeof( uint8_t ) * frame->width * frame->height );
// malloc may return NULL, but rgb is later used without check
// also rgb is never freed so memory leaks
sws_context = sws_getCachedContext(...
// sws_getCachedContext may return NULL, but sws_context is later used without check