JavaRunner
JavaRunner

Reputation: 2545

Why does FFMPEG work with 1080p but doesn't work with 720p size… (code included)

I've uploaded my fully compiled code with its Makefile here:

https://pastebin.com/xtCTj06F

If I set 1280x720 I get the segmentation fault:

[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

There's some problem with this line:

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";

but if I set the size of a video to 1920x1080 or to 320x240 - all works fine.

Is that some sort of a magick?? Or a 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

Upvotes: 1

Views: 452

Answers (1)

dodo951
dodo951

Reputation: 454

Your code has numerous issues. For instance

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

Upvotes: 1

Related Questions