【问题标题】:Why does FFMPEG work with 1080p but doesn't work with 720p size… (code included)为什么 FFMPEG 适用于 1080p 但不适用于 720p 大小...(包含代码)
【发布时间】:2017-04-02 18:52:35
【问题描述】:

我已在此处上传了完整编译的代码及其 Makefile:

https://pastebin.com/xtCTj06F

如果我设置为 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 - 一切正常。

这是某种魔法吗?还是错误?

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

【问题讨论】:

    标签: c++ ffmpeg


    【解决方案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
    

    【讨论】:

    • 也许吧。那只是为了测试。但这并不能解决问题。问题仍然重复。我刚刚检查了 sws_context - 它永远不会等于 NULL。
    • 您是否有来自崩溃的实际堆栈跟踪?您可能还想使用调试信息构建 libav,以便检查 sws_scale() 调用内部发生的任何事情。
    • 我需要用 --enable-debug 重建整个 ffmpeg 库吗?崩溃后在哪里可以找到来自 libav 的日志?我是否应该简单地使用 gdb 并使用“-Wall -g”编译崩溃的 cpp 文件并读取 gdb 输出?
    • 您可以尝试先调试您的应用程序,因为它会检查崩溃调用堆栈,如果没有帮助,则更深入并使用调试信息重建 libav。我不认为 libav 有任何类型的日志,但是如果您的系统配置为生成它们,则可能在某处存在核心转储。你应该用 -g3 编译它。打开包括 -Wextra -Wconversion -pedantic 在内的警告(并修复它们)是个好主意。从命令行使用 gdb 也是有争议的,安装一些 IDE 会节省很多时间。
    猜你喜欢
    • 2013-10-08
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 2022-01-11
    • 2011-10-26
    相关资源
    最近更新 更多