Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
c++ - using FFmpeg encode and UDP with a Webcam
14 mars, par RendresI'm trying to get frames from a Webcam using OpenCV, encode them with FFmpeg and send them using UDP.
I did before a similar project that instead of sending the packets with UDP, it saved them in a video file.
My code is.
#include #include #include #include extern "C" { #include
avcodec.h> #include avformat.h> #include opt.h> #include imgutils.h> #include mathematics.h> #include swscale.h> #include swresample.h> } #include opencv.hpp> using namespace std; using namespace cv; #define WIDTH 640 #define HEIGHT 480 #define CODEC_ID AV_CODEC_ID_H264 #define STREAM_PIX_FMT AV_PIX_FMT_YUV420P static AVFrame *frame, *pFrameBGR; int main(int argc, char **argv) { VideoCapture cap(0); const char *url = "udp://127.0.0.1:8080"; AVFormatContext *formatContext; AVStream *stream; AVCodec *codec; AVCodecContext *c; AVDictionary *opts = NULL; int ret, got_packet; if (!cap.isOpened()) { return -1; } av_log_set_level(AV_LOG_TRACE); av_register_all(); avformat_network_init(); avformat_alloc_output_context2(&formatContext, NULL, "h264", url); if (!formatContext) { av_log(NULL, AV_LOG_FATAL, "Could not allocate an output context for '%s'.\n", url); } codec = avcodec_find_encoder(CODEC_ID); if (!codec) { av_log(NULL, AV_LOG_ERROR, "Could not find encoder.\n"); } stream = avformat_new_stream(formatContext, codec); c = avcodec_alloc_context3(codec); stream->id = formatContext->nb_streams - 1; stream->time_base = (AVRational){1, 25}; c->codec_id = CODEC_ID; c->bit_rate = 400000; c->width = WIDTH; c->height = HEIGHT; c->time_base = stream->time_base; c->gop_size = 12; c->pix_fmt = STREAM_PIX_FMT; if (formatContext->flags & AVFMT_GLOBALHEADER) c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; av_dict_set(&opts, "preset", "fast", 0); av_dict_set(&opts, "tune", "zerolatency", 0); ret = avcodec_open2(c, codec, NULL); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Could not open video codec.\n"); } pFrameBGR = av_frame_alloc(); if (!pFrameBGR) { av_log(NULL, AV_LOG_ERROR, "Could not allocate video frame.\n"); } frame = av_frame_alloc(); if (!frame) { av_log(NULL, AV_LOG_ERROR, "Could not allocate video frame.\n"); } frame->format = c->pix_fmt; frame->width = c->width; frame->height = c->height; ret = avcodec_parameters_from_context(stream->codecpar, c); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Could not open video codec.\n"); } av_dump_format(formatContext, 0, url, 1); ret = avformat_write_header(formatContext, NULL); if (ret != 0) { av_log(NULL, AV_LOG_ERROR, "Failed to connect to '%s'.\n", url); } Mat image(Size(HEIGHT, WIDTH), CV_8UC3); SwsContext *swsctx = sws_getContext(WIDTH, HEIGHT, AV_PIX_FMT_BGR24, WIDTH, HEIGHT, AV_PIX_FMT_YUV420P, SWS_BILINEAR, NULL, NULL, NULL); int frame_pts = 0; while (1) { cap >> image; int numBytesYUV = av_image_get_buffer_size(STREAM_PIX_FMT, WIDTH, HEIGHT, 1); uint8_t *bufferYUV = (uint8_t *)av_malloc(numBytesYUV * sizeof(uint8_t)); avpicture_fill((AVPicture *)pFrameBGR, image.data, AV_PIX_FMT_BGR24, WIDTH, HEIGHT); avpicture_fill((AVPicture *)frame, bufferYUV, STREAM_PIX_FMT, WIDTH, HEIGHT); sws_scale(swsctx, (uint8_t const *const *)pFrameBGR->data, pFrameBGR->linesize, 0, HEIGHT, frame->data, frame->linesize); AVPacket pkt = {0}; av_init_packet(&pkt); frame->pts = frame_pts; ret = avcodec_encode_video2(c, &pkt, frame, &got_packet); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error encoding frame\n"); } if (got_packet) { pkt.pts = av_rescale_q_rnd(pkt.pts, c->time_base, stream->time_base, AVRounding(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX)); pkt.dts = av_rescale_q_rnd(pkt.dts, c->time_base, stream->time_base, AVRounding(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX)); pkt.duration = av_rescale_q(pkt.duration, c->time_base, stream->time_base); pkt.stream_index = stream->index; return av_interleaved_write_frame(formatContext, &pkt); cout << "Seguro que si" << endl; } frame_pts++; } avcodec_free_context(&c); av_frame_free(&frame); avformat_free_context(formatContext); return 0; } The code compiles but it returns Segmentation fault in the function av_interleaved_write_frame(). I've tried several implementations or several codecs (in this case I'm using libopenh264, but using mpeg2video returns the same segmentation fault). I tried also with av_write_frame() but it returns the same error.
As I told before, I only want to grab frames from a webcam connected via USB, encode them to H264 and send the packets through UDP to another PC.
My console log when I run the executable is.
[100%] Built target display [OpenH264] this = 0x0x244b4f0, Info:CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_TRACE_CALLBACK callback = 0x7f0c302a87c0. [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Info:CWelsH264SVCEncoder::InitEncoder(), openh264 codec version = 5a5c4f1 [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Info:iUsageType = 0,iPicWidth= 640;iPicHeight= 480;iTargetBitrate= 400000;iMaxBitrate= 400000;iRCMode= 0;iPaddingFlag= 0;iTemporalLayerNum= 1;iSpatialLayerNum= 1;fFrameRate= 25.000000f;uiIntraPeriod= 12;eSpsPpsIdStrategy = 0;bPrefixNalAddingCtrl = 0;bSimulcastAVC=0;bEnableDenoise= 0;bEnableBackgroundDetection= 1;bEnableSceneChangeDetect = 1;bEnableAdaptiveQuant= 1;bEnableFrameSkip= 0;bEnableLongTermReference= 0;iLtrMarkPeriod= 30, bIsLosslessLink=0;iComplexityMode = 0;iNumRefFrame = 1;iEntropyCodingModeFlag = 0;uiMaxNalSize = 0;iLTRRefNum = 0;iMultipleThreadIdc = 1;iLoopFilterDisableIdc = 0 (offset(alpha/beta): 0,0;iComplexityMode = 0,iMaxQp = 51;iMinQp = 0) [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Info:sSpatialLayers[0]: .iVideoWidth= 640; .iVideoHeight= 480; .fFrameRate= 25.000000f; .iSpatialBitrate= 400000; .iMaxSpatialBitrate= 400000; .sSliceArgument.uiSliceMode= 1; .sSliceArgument.iSliceNum= 0; .sSliceArgument.uiSliceSizeConstraint= 1500;uiProfileIdc = 66;uiLevelIdc = 41 [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Warning:SliceArgumentValidationFixedSliceMode(), unsupported setting with Resolution and uiSliceNum combination under RC on! So uiSliceNum is changed to 6! [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Info:Setting MaxSpatialBitrate (400000) the same at SpatialBitrate (400000) will make the actual bit rate lower than SpatialBitrate [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Warning:bEnableFrameSkip = 0,bitrate can't be controlled for RC_QUALITY_MODE,RC_BITRATE_MODE and RC_TIMESTAMP_MODE without enabling skip frame. [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Warning:Change QP Range from(0,51) to (12,42) [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Info:WELS CPU features/capacities (0x4007fe3f) detected: HTT: Y, MMX: Y, MMXEX: Y, SSE: Y, SSE2: Y, SSE3: Y, SSSE3: Y, SSE4.1: Y, SSE4.2: Y, AVX: Y, FMA: Y, X87-FPU: Y, 3DNOW: N, 3DNOWEX: N, ALTIVEC: N, CMOV: Y, MOVBE: Y, AES: Y, NUMBER OF LOGIC PROCESSORS ON CHIP: 8, CPU CACHE LINE SIZE (BYTES): 64 [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Info:WelsInitEncoderExt() exit, overall memory usage: 4542878 bytes [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Info:WelsInitEncoderExt(), pCtx= 0x0x245a400. Output #0, h264, to 'udp://192.168.100.39:8080': Stream #0:0, 0, 1/25: Video: h264 (libopenh264), 1 reference frame, yuv420p, 640x480 (0x0), 0/1, q=2-31, 400 kb/s, 25 tbn [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Debug:RcUpdateIntraComplexity iFrameDqBits = 385808,iQStep= 2016,iIntraCmplx = 777788928 [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Debug:[Rc]Layer 0: Frame timestamp = 0, Frame type = 2, encoding_qp = 30, average qp = 30, max qp = 33, min qp = 27, index = 0, iTid = 0, used = 385808, bitsperframe = 16000, target = 64000, remainingbits = -257808, skipbuffersize = 200000 [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Debug:WelsEncoderEncodeExt() OutputInfo iLayerNum = 2,iFrameSize = 48252 [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Debug:WelsEncoderEncodeExt() OutputInfo iLayerId = 0,iNalType = 0,iNalCount = 2, first Nal Length=18,uiSpatialId = 0,uiTemporalId = 0,iSubSeqId = 0 [libopenh264 @ 0x244aa00] [OpenH264] this = 0x0x244b4f0, Debug:WelsEncoderEncodeExt() OutputInfo iLayerId = 1,iNalType = 1,iNalCount = 6, first Nal Length=6057,uiSpatialId = 0,uiTemporalId = 0,iSubSeqId = 0 [libopenh264 @ 0x244aa00] 6 slices ./scriptBuild.sh: line 20: 10625 Segmentation fault (core dumped) ./display
As you can see, FFmpeg uses libopenh264 and configures it correctly. However, no matter what. It always returns the same Segmentation fault error...
I've used commands like this.
ffmpeg -s 640x480 -f video4linux2 -i /dev/video0 -r 30 -vcodec libopenh264 -an -f h264 udp://127.0.0.1:8080
And it works perfectly, but I need to process the frames before sending them. Thats why I'm trying to use the libs.
My FFmpeg version is.
ffmpeg version 3.3.6 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3) configuration: --disable-yasm --enable-shared --enable-libopenh264 --cc='gcc -fPIC' libavutil 55. 58.100 / 55. 58.100 libavcodec 57. 89.100 / 57. 89.100 libavformat 57. 71.100 / 57. 71.100 libavdevice 57. 6.100 / 57. 6.100 libavfilter 6. 82.100 / 6. 82.100 libswscale 4. 6.100 / 4. 6.100 libswresample 2. 7.100 / 2. 7.100
I tried to get more information of the error using gbd, but it didn't give me debugging info.
How can I solve this problem? I don't know what else can I try...
Thank you!
-
Discord bot : Fix ‘FFMPEG not found’
14 mars, par Travis SovaI want to make my Discord bot join voice chat, but every time I run the command, I get an error message in the log(cmd) saying,
FFMPEG not found.
Picture of the error:
This is the code:
client.on('message', message => { // Voice only works in guilds, if the message does not come from a guild, // we ignore it if (!message.guild) return; if (message.content === '/join') { // Only try to join the sender's voice channel if they are in one themselves if (message.member.voiceChannel) { message.member.voiceChannel.join() .then(connection => { // Connection is an instance of VoiceConnection message.reply('I have successfully connected to the channel!'); }) .catch(console.log); } else { message.reply('You need to join a voice channel first!'); } } });
this is my package.json file:
{ "name": "x", "version": "1.0.0", "main": "index.js", "scripts": { "start": "node index.js", "dev": "nodemon index.js" }, "dependencies": { "discord.js": "^11.4.2", "dotenv": "^6.2.0", "ffmpeg": "0.0.4", "opusscript": "0.0.6" }, "devDependencies": { "nodemon": "^1.18.9" } }
-
How to combine multiple images and multiple audio files into one video with ffmpeg ?
14 mars, par nachocabI have two images
image1.png
andimage2.png
, they both have the same dimensions. I also have two audio filesaudio1.wav
andaudio2.wav
they each have different lengths. I want to make a video that showsimage1.png
duringaudio1.wav
and thenimage2.png
overaudio2.wav
.I've tried two methods, but they don't work. The images show correctly, but the durations are not synced with the audio.
Method 1: create videos separately and combine them:
image1 => video1
ffmpeg -loop 1 \ -y \ -i "image1.png" \ -i "audio1.wav" \ -c:v libx264 -tune stillimage -pix_fmt yuv420p \ -c:a aac -b:a 192k \ -shortest \ "video1.mp4" ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers built with Apple LLVM version 8.0.0 (clang-800.0.38) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.2.0/include/openjpeg-2.2 --enable-nonfree --enable-vda libavutil 55. 58.100 / 55. 58.100 libavcodec 57. 89.100 / 57. 89.100 libavformat 57. 71.100 / 57. 71.100 libavdevice 57. 6.100 / 57. 6.100 libavfilter 6. 82.100 / 6. 82.100 libavresample 3. 5. 0 / 3. 5. 0 libswscale 4. 6.100 / 4. 6.100 libswresample 2. 7.100 / 2. 7.100 libpostproc 54. 5.100 / 54. 5.100 Input #0, png_pipe, from 'image1.png': Duration: N/A, bitrate: N/A Stream #0:0: Video: png, rgba(pc), 800x800, 25 fps, 25 tbr, 25 tbn, 25 tbc Guessed Channel Layout for Input Stream #1.0 : stereo Input #1, wav, from 'audio1.wav': Metadata: title : untitled track : 1 Duration: 00:00:03.70, bitrate: 1411 kb/s Stream #1:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s Stream mapping: Stream #0:0 -> #0:0 (png (native) -> h264 (libx264)) Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native)) Press [q] to stop, [?] for help [libx264 @ 0x7fead980bc00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2 [libx264 @ 0x7fead980bc00] profile High, level 3.1 [libx264 @ 0x7fead980bc00] 264 - core 148 r2795 aaa9aa8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:-3:-3 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=2.00:0.70 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-4 threads=12 lookahead_threads=2 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=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.20 Output #0, mp4, to 'video1.mp4': Metadata: encoder : Lavf57.71.100 Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p(progressive), 800x800, q=-1--1, 25 fps, 12800 tbn, 25 tbc Metadata: encoder : Lavc57.89.100 libx264 Side data: cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1 Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 192 kb/s Metadata: encoder : Lavc57.89.100 aac frame= 151 fps=0.0 q=-1.0 Lsize= 106kB time=00:00:05.92 bitrate= 146.6kbits/s speed=6.73x video:13kB audio:87kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 5.016360% [libx264 @ 0x7fead980bc00] frame I:1 Avg QP:14.87 size: 5746 [libx264 @ 0x7fead980bc00] frame P:38 Avg QP:12.15 size: 51 [libx264 @ 0x7fead980bc00] frame B:112 Avg QP:16.81 size: 48 [libx264 @ 0x7fead980bc00] consecutive B-frames: 0.7% 1.3% 0.0% 98.0% [libx264 @ 0x7fead980bc00] mb I I16..4: 46.9% 44.7% 8.4% [libx264 @ 0x7fead980bc00] mb P I16..4: 0.0% 0.0% 0.0% P16..4: 0.0% 0.0% 0.0% 0.0% 0.0% skip:99.9% [libx264 @ 0x7fead980bc00] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.2% 0.0% 0.0% direct: 0.0% skip:99.7% L0:63.5% L1:36.5% BI: 0.0% [libx264 @ 0x7fead980bc00] 8x8 transform intra:40.7% inter:20.0% [libx264 @ 0x7fead980bc00] coded y,uvDC,uvAC intra: 4.9% 0.0% 0.0% inter: 0.0% 0.0% 0.0% [libx264 @ 0x7fead980bc00] i16 v,h,dc,p: 82% 13% 4% 0% [libx264 @ 0x7fead980bc00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 74% 2% 24% 0% 0% 0% 0% 0% 0% [libx264 @ 0x7fead980bc00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 24% 32% 2% 2% 2% 2% 1% 2% [libx264 @ 0x7fead980bc00] i8c dc,h,v,p: 100% 0% 0% 0% [libx264 @ 0x7fead980bc00] Weighted P-Frames: Y:0.0% UV:0.0% [libx264 @ 0x7fead980bc00] ref B L0: 48.0% 52.0% [libx264 @ 0x7fead980bc00] ref B L1: 99.5% 0.5% [libx264 @ 0x7fead980bc00] kb/s:17.36 [aac @ 0x7fead981b400] Qavg: 535.938
image2 => video2
ffmpeg -loop 1 \ -y \ -i "image2.png" \ -i "audio2.wav" \ -c:v libx264 -tune stillimage -pix_fmt yuv420p \ -c:a aac -b:a 192k \ -shortest \ "video2.mp4" ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers built with Apple LLVM version 8.0.0 (clang-800.0.38) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.2.0/include/openjpeg-2.2 --enable-nonfree --enable-vda libavutil 55. 58.100 / 55. 58.100 libavcodec 57. 89.100 / 57. 89.100 libavformat 57. 71.100 / 57. 71.100 libavdevice 57. 6.100 / 57. 6.100 libavfilter 6. 82.100 / 6. 82.100 libavresample 3. 5. 0 / 3. 5. 0 libswscale 4. 6.100 / 4. 6.100 libswresample 2. 7.100 / 2. 7.100 libpostproc 54. 5.100 / 54. 5.100 Input #0, png_pipe, from 'image2.png': Duration: N/A, bitrate: N/A Stream #0:0: Video: png, rgba(pc), 800x800, 25 fps, 25 tbr, 25 tbn, 25 tbc Guessed Channel Layout for Input Stream #1.0 : stereo Input #1, wav, from 'audio2.wav': Metadata: title : untitled track : 2 Duration: 00:00:05.49, bitrate: 1411 kb/s Stream #1:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s Stream mapping: Stream #0:0 -> #0:0 (png (native) -> h264 (libx264)) Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native)) Press [q] to stop, [?] for help [libx264 @ 0x7fa0e201ce00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2 [libx264 @ 0x7fa0e201ce00] profile High, level 3.1 [libx264 @ 0x7fa0e201ce00] 264 - core 148 r2795 aaa9aa8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:-3:-3 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=2.00:0.70 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-4 threads=12 lookahead_threads=2 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=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.20 Output #0, mp4, to 'video2.mp4': Metadata: encoder : Lavf57.71.100 Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p(progressive), 800x800, q=-1--1, 25 fps, 12800 tbn, 25 tbc Metadata: encoder : Lavc57.89.100 libx264 Side data: cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1 Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 192 kb/s Metadata: encoder : Lavc57.89.100 aac frame= 195 fps=177 q=-1.0 Lsize= 150kB time=00:00:07.68 bitrate= 160.2kbits/s speed=6.96x video:14kB audio:129kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 4.516541% [libx264 @ 0x7fa0e201ce00] frame I:1 Avg QP: 9.03 size: 6402 [libx264 @ 0x7fa0e201ce00] frame P:49 Avg QP: 6.59 size: 41 [libx264 @ 0x7fa0e201ce00] frame B:145 Avg QP: 9.67 size: 39 [libx264 @ 0x7fa0e201ce00] consecutive B-frames: 0.5% 1.0% 0.0% 98.5% [libx264 @ 0x7fa0e201ce00] mb I I16..4: 54.7% 36.0% 9.3% [libx264 @ 0x7fa0e201ce00] mb P I16..4: 0.0% 0.0% 0.0% P16..4: 0.0% 0.0% 0.0% 0.0% 0.0% skip:100.0% [libx264 @ 0x7fa0e201ce00] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.2% 0.0% 0.0% direct: 0.0% skip:99.8% L0:70.1% L1:29.9% BI: 0.0% [libx264 @ 0x7fa0e201ce00] 8x8 transform intra:36.0% inter:14.3% [libx264 @ 0x7fa0e201ce00] coded y,uvDC,uvAC intra: 4.3% 0.0% 0.0% inter: 0.0% 0.0% 0.0% [libx264 @ 0x7fa0e201ce00] i16 v,h,dc,p: 91% 5% 4% 0% [libx264 @ 0x7fa0e201ce00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 72% 8% 20% 0% 0% 0% 0% 0% 0% [libx264 @ 0x7fa0e201ce00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 36% 23% 25% 4% 3% 3% 3% 2% 2% [libx264 @ 0x7fa0e201ce00] i8c dc,h,v,p: 100% 0% 0% 0% [libx264 @ 0x7fa0e201ce00] Weighted P-Frames: Y:0.0% UV:0.0% [libx264 @ 0x7fa0e201ce00] ref P L0: 83.3% 8.3% 8.3% [libx264 @ 0x7fa0e201ce00] ref B L0: 40.1% 59.9% [libx264 @ 0x7fa0e201ce00] kb/s:14.38 [aac @ 0x7fa0e201e600] Qavg: 595.040
When I import these into Final Cut I can see that both videos get around 2:30 seconds of added silence (not present in the audio):
concatenating video1 and video2
ffmpeg -i "video1.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts ffmpeg -i "video2.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc "video_combined.mp4" ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers built with Apple LLVM version 8.0.0 (clang-800.0.38) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.2.0/include/openjpeg-2.2 --enable-nonfree --enable-vda libavutil 55. 58.100 / 55. 58.100 libavcodec 57. 89.100 / 57. 89.100 libavformat 57. 71.100 / 57. 71.100 libavdevice 57. 6.100 / 57. 6.100 libavfilter 6. 82.100 / 6. 82.100 libavresample 3. 5. 0 / 3. 5. 0 libswscale 4. 6.100 / 4. 6.100 libswresample 2. 7.100 / 2. 7.100 libpostproc 54. 5.100 / 54. 5.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video1.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.71.100 Duration: 00:00:06.04, start: 0.000000, bitrate: 143 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 800x800, 18 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 192 kb/s (default) Metadata: handler_name : SoundHandler Output #0, mpegts, to 'intermediate1.ts': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.71.100 Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 800x800, q=2-31, 18 kb/s, 25 fps, 25 tbr, 90k tbn, 12800 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 192 kb/s (default) Metadata: handler_name : SoundHandler Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help frame= 151 fps=0.0 q=-1.0 Lsize= 135kB time=00:00:05.92 bitrate= 187.5kbits/s speed=2.43e+03x video:14kB audio:87kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 34.259724% ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers built with Apple LLVM version 8.0.0 (clang-800.0.38) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.2.0/include/openjpeg-2.2 --enable-nonfree --enable-vda libavutil 55. 58.100 / 55. 58.100 libavcodec 57. 89.100 / 57. 89.100 libavformat 57. 71.100 / 57. 71.100 libavdevice 57. 6.100 / 57. 6.100 libavfilter 6. 82.100 / 6. 82.100 libavresample 3. 5. 0 / 3. 5. 0 libswscale 4. 6.100 / 4. 6.100 libswresample 2. 7.100 / 2. 7.100 libpostproc 54. 5.100 / 54. 5.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video2.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.71.100 Duration: 00:00:07.80, start: 0.000000, bitrate: 157 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 800x800, 15 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 192 kb/s (default) Metadata: handler_name : SoundHandler Output #0, mpegts, to 'intermediate2.ts': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.71.100 Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 800x800, q=2-31, 15 kb/s, 25 fps, 25 tbr, 90k tbn, 12800 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 192 kb/s (default) Metadata: handler_name : SoundHandler Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help frame= 195 fps=0.0 q=-1.0 Lsize= 192kB time=00:00:07.68 bitrate= 204.8kbits/s speed=2.6e+03x video:14kB audio:129kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 33.605099% ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers built with Apple LLVM version 8.0.0 (clang-800.0.38) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.2.0/include/openjpeg-2.2 --enable-nonfree --enable-vda libavutil 55. 58.100 / 55. 58.100 libavcodec 57. 89.100 / 57. 89.100 libavformat 57. 71.100 / 57. 71.100 libavdevice 57. 6.100 / 57. 6.100 libavfilter 6. 82.100 / 6. 82.100 libavresample 3. 5. 0 / 3. 5. 0 libswscale 4. 6.100 / 4. 6.100 libswresample 2. 7.100 / 2. 7.100 libpostproc 54. 5.100 / 54. 5.100 Input #0, mpegts, from 'concat:intermediate1.ts|intermediate2.ts': Duration: 00:00:07.82, start: 1.456778, bitrate: 342 kb/s Program 1 Metadata: service_name : Service01 service_provider: FFmpeg Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 800x800, 25 fps, 25 tbr, 90k tbn, 50 tbc Stream #0:1[0x101](und): Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 169 kb/s Output #0, mp4, to 'video_combined.mp4': Metadata: encoder : Lavf57.71.100 Stream #0:0: Video: h264 (High) ([33][0][0][0] / 0x0021), yuv420p(progressive), 800x800, q=2-31, 25 fps, 25 tbr, 90k tbn, 90k tbc Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 169 kb/s Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help frame= 346 fps=0.0 q=-1.0 Lsize= 257kB time=00:00:13.74 bitrate= 153.3kbits/s speed=1.54e+03x video:30kB audio:217kB subtitle:0kB other streams:0kB global headers:1kB muxing overhead: 4.243830%
The output of the combined video contains the extra silences, but the second audio doesn't combine properly:
Method 2: Create combined video directly
ffmpeg -f concat -i input.txt -map 0 \ -vcodec libx264 \ -aprofile aac_low -acodec aac -strict experimental -cutoff 15000 -b:a 32k "video_combined.mp4"
Any ideas?
-
ffmpeg + docker : make install not installing libx265 when building the image, but works inside container
14 mars, par Alexander SantosI have this
Dockerfile
FROM ubuntu:22.04 WORKDIR /usr/local/src ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig RUN apt update && apt install -y \ build-essential cmake git pkg-config \ libxml2-dev yasm nasm libtool autoconf automake \ libx264-dev libx265-dev libnuma-dev libvpx-dev \ libfdk-aac-dev libmp3lame-dev libopus-dev \ libass-dev libfreetype6-dev libvorbis-dev RUN apt-get install libx265-dev RUN git clone --depth 1 https://github.com/fraunhoferhhi/vvenc.git && \ cd vvenc && \ mkdir build && cd build && \ cmake .. -DCMAKE_BUILD_TYPE=Release && \ make -j$(nproc) RUN cd vvenc && \ make install install-prefix=/usr/local RUN git clone --depth 1 https://github.com/FFmpeg/FFmpeg.git ffmpeg RUN cd ffmpeg && \ ./configure --enable-libx265 --enable-gpl --enable-nonfree --enable-pthreads --enable-pic --enable-shared \ --enable-rpath --enable-demuxer=dash \ --enable-libxml2 --enable-libvvenc --extra-libs=-lpthread && \ make -j$(nproc) RUN cd ffmpeg && make install RUN rm -rf /var/lib/apt/lists/* # Some other irrelevant commands
It works for
VVenC
. As for works, i mean that i can enter the container with/bin/bash
, executeffmpeg -codecs | grep vvc
and this is the response:DEV.L. vvc H.266 / VVC (Versatile Video Coding) (encoders: libvvenc)
But for libx265 it's not working.
ffmpeg -codecs | grep x265 In another try: ffmpeg -codecs | grep 265 DEV.L. hevc H.265 / HEVC (High Efficiency Video Coding) (decoders: hevc hevc_v4l2m2m) (encoders: hevc_v4l2m2m)
After i enter the ffmpeg directory again and execute
make install
it works.root@0a2ad1086abd:/usr/local/src# cd ffmpeg root@0a2ad1086abd:/usr/local/src/ffmpeg# make install ... installation logs ... root@0a2ad1086abd:/usr/local/src/ffmpeg# ffmpeg -codecs | grep x265 DEV.L. hevc H.265 / HEVC (High Efficiency Video Coding) (decoders: hevc hevc_v4l2m2m) (encoders: libx265 hevc_v4l2m2m)
Is there anything i can do here? I tried separating layers, unifying... I really don't know what else should i do.
-
How can I crop and encode a video using flutter natively, now that flutter_ffmpeg is discontinued with no alternatives ? [closed]
13 mars, par Rageh AzzazyAs of January 6, 2025, FFmpegKit is officially retired (Taner's article).
This also affects the
flutter_ffmpeg
andffmpeg_kit_flutter
packages.Most packages for executing video editing commands were built depending on them and so won't work after April 1, 2025 as mentioned in the package documentation and Taner's article. Some packages that depend on
flutter_ffmpeg
orffmpeg_kit_flutter
are:video_trimmer
zero_video_trimmer
flutter_video_trimmer
video_trim
bemeli_compress
video_trimmer_pro
- ... others
Editing video using
video_editor
orvideo_editor_2
orvideo_editor_pits
has become a problem.I believe downloading the binaries and doing the whole thing locally is not just tedious but illegal as well.
I broke down exactly what I need to edit videos in my flutter app and I found those package but have not yet tested them.
✅ Trimming:
flutter_native_video_trimmer
✅ Compression:
video_compress
orvideo_compress_plus
✅ Muting:
video_compress
handles this❌ Encoding: Not sure, I just need a simple MP4 video files
❌ Cropping: I can't find a solution for video cropping
I don't need to rotate, reverse or do any fancy stuff to the videos, just those five functions.
Now the only way forward is to find a simple video cropping function and an encoder that work on flutter IOS & Android
My question is not looking for external library recommendations but:
Do you have any ideas how to crop a video in flutter natively?