Bash, ffmpeg, more files to 1 file by date YYYYMMDD

System

Linux vm16745 3.13.0-77-generic #121-Ubuntu SMP Wed Jan 20 10:50:42 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux 

Issue

I have this input.

VID_20190407_160033.3gp VID_20190407_161444.3gp VID_20190407_161609.3gp VID_20190415_183315.3gp VID_20190415_183411.3gp VID_20190415_192712.3gp VID_20190420_124435.3gp VID_20190420_125755.3gp VID_20190420_130214.3gp VID_20190420_141700.3gp 

And I wanna this, join 3gp files (with ffmpeg?) to 1 file by date.

VID_20190407.3gp VID_20190415.3gp VID_20190420.3gp 

What is the best way to do that? Thank you.

Why does ffmpeg stop recording at midnight?

I have a shellscript like this under Kubuntu 19.10,

#!/bin/bash  while true do     FILE=/media/petermc/Security5/Camera2/Camera2_.mp4       FILE=$  {FILE%.*}`date +%Y-%m-%d_%H-%M-%S-%N`.$  {FILE#*.}     echo $  FILE      ffmpeg -rtsp_transport tcp -t 00:15:00 -i rtsp://*user*:*password*@192.168.1.60:554/ch02/0 -c copy -map 0 $  FILE done 

It records files like this,

Camera2_2019-09-21_23-36-57-874602376.mp4 Camera2_2019-09-21_23-51-57-876639147.mp4 

Basically recording 15 minutes at a time from the RTSP feed, then starting a new file.

However it stops working at midnight, the last few lines from the log file are this,

frame= 3987 fps= 13 q=-1.0 size=  117760kB time=00:05:06.51 bitrate=3147.3kbits/s speed=1.01x     frame= 3994 fps= 13 q=-1.0 size=  118016kB time=00:05:07.07 bitrate=3148.4kbits/s speed=1.01x     frame= 4001 fps= 13 q=-1.0 size=  118016kB time=00:05:07.59 bitrate=3143.1kbits/s speed=1.01x     frame= 4008 fps= 13 q=-1.0 size=  118272kB time=00:05:08.11 bitrate=3144.6kbits/s speed=1.01x  

So there doesn’t seem to be any error, it stops recording at 5 minutes into the last file with no error.

Another piece of information is that I have 6 cameras, and 4 stopped recording, the ones connected to a DVR. I have a couple of IP cameras and they kept recording.

What could be the cause of this? Plus, what else could I do to work around this or diagnose this?

How enable HW accelerated video encoders in FFMPEG, Ubuntu 19.04?

How enable HW accelrated encoding in FFMPEG, Ubuntu 19.04 ? (at least _nvenc variants of h.264/h.265 encoders)

Do you know simplified user friendly way, how to do that ? Thank you for any advice.

(my configuration: GeForce GTX 1060 6GB/PCIe/SSE2 / nVidia binary drivers version 418.56, nvidia-cuda-toolkit installed)


$   ffmpeg -h encoder=hevc_nvenc 
ffmpeg version 4.1.3-0ubuntu1 Codec 'hevc_nvenc' is not recognized by FFmpeg. 

btw, my cuda acceleration works perfectly in BLENDER CYCLES … so it works in general, but not in FFMPEG

ffmpeg spacial cropping troubleshooting

ffmpeg is invoked to crop a .mp4 video of resolution 720X1366. Specifically the goal is crop out the first 212 rows of the video’s pixels:

ffmpeg -i Dwell-2019-09-19_13.23.14.mp4 -filter:v "crop=1366:556:1:213" Dwell_out.mp4 

An .mp4 file of zero bytes is returned along with

ffmpeg version 2.8.15-0ubuntu0.16.04.1 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609 configuration: –prefix=/usr –extra-version=0ubuntu0.16.04.1 –build-suffix=-ffmpeg –toolchain=hardened –libdir=/usr/lib/x86_64-linux-gnu –incdir=/usr/include/x86_64-linux-gnu –cc=cc –cxx=g++ –enable-gpl –enable-shared –disable-stripping –disable-decoder=libopenjpeg –disable-decoder=libschroedinger –enable-avresample –enable-avisynth –enable-gnutls –enable-ladspa –enable-libass –enable-libbluray –enable-libbs2b –enable-libcaca –enable-libcdio –enable-libflite –enable-libfontconfig –enable-libfreetype –enable-libfribidi –enable-libgme –enable-libgsm –enable-libmodplug –enable-libmp3lame –enable-libopenjpeg –enable-libopus –enable-libpulse –enable-librtmp –enable-libschroedinger –enable-libshine –enable-libsnappy –enable-libsoxr –enable-libspeex –enable-libssh –enable-libtheora –enable-libtwolame –enable-libvorbis –enable-libvpx –enable-libwavpack –enable-libwebp –enable-libx265 –enable-libxvid –enable-libzvbi –enable-openal –enable-opengl –enable-x11grab –enable-libdc1394 –enable-libiec61883 –enable-libzmq –enable-frei0r –enable-libx264 –enable-libopencv libavutil 54. 31.100 / 54. 31.100 libavcodec 56. 60.100 / 56. 60.100 libavformat 56. 40.101 / 56. 40.101 libavdevice 56. 4.100 / 56. 4.100 libavfilter 5. 40.101 / 5. 40.101 libavresample 2. 1. 0 / 2. 1. 0 libswscale 3. 1.101 / 3. 1.101 libswresample 1. 2.101 / 1. 2.101 libpostproc 53. 3.100 / 53. 3.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ‘Dwell-2019-09-19_13.23.14.mp4’: Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf56.40.101 Duration: 00:00:33.94, start: 0.001333, bitrate: 526 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1366×768 [SAR 1:1 DAR 683:384], 518 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: vorbis (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 0 kb/s (default) Metadata: handler_name : SoundHandler File ‘Dwell_out.mp4’ already exists. Overwrite ? [y/N] y [libx264 @ 0x1cd1600] using SAR=1/1 [libx264 @ 0x1cd1600] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 [libx264 @ 0x1cd1600] profile High, level 3.1 [libx264 @ 0x1cd1600] 264 – core 148 r2643 5c65704 – H.264/MPEG-4 AVC codec – Copyleft 2003-2015 – 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=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.00 [aac @ 0x1cd2560] The encoder ‘aac’ is experimental but experimental codecs are not enabled, add ‘-strict -2’ if you want to use it.

Where to begin troubleshooting?

Batch Compress Videos with ffmpeg

I have many videos in a folder, and I want to compress them all with one command.

To compress one video I use:

sudo apt-get install ffmpeg ffmpeg -i input.mp4 output.mp4 

But what if I have many videos I want to compress? I’ve tried the following:

ffmpeg -i ./videos ./compressed-videos 

But then I get this error:

./videos: Is a directory 

What’s the difference between ffmpeg static libraries form ubuntu and from mine that I compiled?

I tried ffmpeg from ubuntu repositories and linking them was as easy as just doing -lavcodec -lavuitl .... I then compiled mine with these configurations:

    ./configure \     --prefix=$  {BUILD_DIR}/desktop/x86_64 \     --extra-cflags="-I$  HOME/ffmpeg_build/include" \     --extra-ldflags="-L$  HOME/ffmpeg_build/lib" \     --enable-shared \     --arch=x86_64 \     --enable-vaapi \     --disable-vaapi \     --enable-opencl \     --disable-debug \     --enable-nvenc \     --enable-cuda \     --enable-cuvid \     --enable-libvpx \     --enable-libdrm \     --enable-gpl \     --enable-runtime-cpudetect \     --enable-libfdk-aac \     --enable-libx264 \     --enable-openssl \     --enable-pic \     --extra-libs="-lpthread -lm -lz -ldl" \     --enable-nonfree  

And it generated static libraries just like those provided by ubuntu repositories. However, I cannot simply link them with -lavcodec -lavuitl ... because I get lots of undefined references, like

../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libfdk-aacdec.o): In function `fdk_aac_decode_frame': libfdk-aacdec.c:(.text+0x4f): undefined reference to `aacDecoder_Fill' libfdk-aacdec.c:(.text+0x6d): undefined reference to `aacDecoder_DecodeFrame' libfdk-aacdec.c:(.text+0x8d): undefined reference to `aacDecoder_GetStreamInfo' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libfdk-aacdec.o): In function `fdk_aac_decode_close': libfdk-aacdec.c:(.text.unlikely+0xf): undefined reference to `aacDecoder_Close' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libfdk-aacdec.o): In function `fdk_aac_decode_init': libfdk-aacdec.c:(.text.unlikely+0x45): undefined reference to `aacDecoder_Open' libfdk-aacdec.c:(.text.unlikely+0x82): undefined reference to `aacDecoder_ConfigRaw' libfdk-aacdec.c:(.text.unlikely+0xb7): undefined reference to `aacDecoder_SetParam' libfdk-aacdec.c:(.text.unlikely+0x129): undefined reference to `aacDecoder_SetParam' libfdk-aacdec.c:(.text.unlikely+0x187): undefined reference to `aacDecoder_AncDataInit' libfdk-aacdec.c:(.text.unlikely+0x1ac): undefined reference to `aacDecoder_SetParam' libfdk-aacdec.c:(.text.unlikely+0x1d1): undefined reference to `aacDecoder_SetParam' libfdk-aacdec.c:(.text.unlikely+0x1f2): undefined reference to `aacDecoder_SetParam' libfdk-aacdec.c:(.text.unlikely+0x213): undefined reference to `aacDecoder_SetParam' libfdk-aacdec.c:(.text.unlikely+0x22f): undefined reference to `aacDecoder_SetParam' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libfdk-aacdec.o):libfdk-aacdec.c:(.text.unlikely+0x250): more undefined references to `aacDecoder_SetParam' follow ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libfdk-aacenc.o): In function `aac_encode_close': libfdk-aacenc.c:(.text+0xf9): undefined reference to `aacEncClose' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libfdk-aacenc.o): In function `aac_encode_frame': libfdk-aacenc.c:(.text+0x2c1): undefined reference to `aacEncEncode' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libfdk-aacenc.o): In function `aac_encode_init': libfdk-aacenc.c:(.text.unlikely+0x3c): undefined reference to `aacEncOpen' libfdk-aacenc.c:(.text.unlikely+0x7c): undefined reference to `aacEncoder_SetParam' libfdk-aacenc.c:(.text.unlikely+0xb8): undefined reference to `aacEncoder_SetParam' libfdk-aacenc.c:(.text.unlikely+0xfa): undefined reference to `aacEncoder_SetParam' libfdk-aacenc.c:(.text.unlikely+0x180): undefined reference to `aacEncoder_SetParam' libfdk-aacenc.c:(.text.unlikely+0x25d): undefined reference to `aacEncoder_SetParam' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libfdk-aacenc.o):libfdk-aacenc.c:(.text.unlikely+0x28d): more undefined references to `aacEncoder_SetParam' follow ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libfdk-aacenc.o): In function `aac_encode_init': libfdk-aacenc.c:(.text.unlikely+0x567): undefined reference to `aacEncEncode' libfdk-aacenc.c:(.text.unlikely+0x5a1): undefined reference to `aacEncInfo' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libvpxdec.o): In function `vpx_decode': libvpxdec.c:(.text+0x58): undefined reference to `vpx_codec_decode' libvpxdec.c:(.text+0xa2): undefined reference to `vpx_codec_get_frame' libvpxdec.c:(.text+0x10c): undefined reference to `vpx_codec_error' libvpxdec.c:(.text+0x117): undefined reference to `vpx_codec_error_detail' libvpxdec.c:(.text+0x19e): undefined reference to `vpx_codec_decode' libvpxdec.c:(.text+0x1ae): undefined reference to `vpx_codec_error' libvpxdec.c:(.text+0x1ca): undefined reference to `vpx_codec_get_frame' libvpxdec.c:(.text+0x560): undefined reference to `vpx_codec_vp9_dx_algo' libvpxdec.c:(.text+0x58f): undefined reference to `vpx_codec_vp8_dx_algo' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libvpxdec.o): In function `vpx_free': libvpxdec.c:(.text.unlikely+0x9): undefined reference to `vpx_codec_destroy' libvpxdec.c:(.text.unlikely+0x18): undefined reference to `vpx_codec_destroy' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libvpxdec.o): In function `vpx_init': libvpxdec.c:(.text.unlikely+0x87): undefined reference to `vpx_codec_version_str' libvpxdec.c:(.text.unlikely+0xa5): undefined reference to `vpx_codec_build_config' libvpxdec.c:(.text.unlikely+0xdf): undefined reference to `vpx_codec_dec_init_ver' libvpxdec.c:(.text.unlikely+0xed): undefined reference to `vpx_codec_error' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libvpxdec.o): In function `vp8_init': libvpxdec.c:(.text.unlikely+0x134): undefined reference to `vpx_codec_vp8_dx_algo' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libvpxdec.o): In function `vp9_init': libvpxdec.c:(.text.unlikely+0x142): undefined reference to `vpx_codec_vp9_dx_algo' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libvpxenc.o): In function `vpx_encode': libvpxenc.c:(.text+0xda): undefined reference to `vpx_codec_encode' libvpxenc.c:(.text+0x2b3): undefined reference to `vpx_codec_encode' libvpxenc.c:(.text+0x33a): undefined reference to `vpx_codec_get_cx_data' libvpxenc.c:(.text+0x3cd): undefined reference to `vpx_codec_get_cx_data' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libvpxenc.o): In function `log_encoder_error': libvpxenc.c:(.text.unlikely+0x351): undefined reference to `vpx_codec_error' libvpxenc.c:(.text.unlikely+0x35c): undefined reference to `vpx_codec_error_detail' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libvpxenc.o): In function `codecctl_int': libvpxenc.c:(.text.unlikely+0x43a): undefined reference to `vpx_codec_control_' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libvpxenc.o): In function `vpx_init': libvpxenc.c:(.text.unlikely+0x4fb): undefined reference to `vpx_codec_get_caps' libvpxenc.c:(.text.unlikely+0x503): undefined reference to `vpx_codec_version_str' libvpxenc.c:(.text.unlikely+0x521): undefined reference to `vpx_codec_build_config' libvpxenc.c:(.text.unlikely+0x563): undefined reference to `vpx_codec_enc_config_default' libvpxenc.c:(.text.unlikely+0x573): undefined reference to `vpx_codec_err_to_string' libvpxenc.c:(.text.unlikely+0xc2c): undefined reference to `vpx_codec_enc_init_ver' libvpxenc.c:(.text.unlikely+0xc86): undefined reference to `vpx_codec_enc_init_ver' libvpxenc.c:(.text.unlikely+0xffb): undefined reference to `vpx_img_wrap' libvpxenc.c:(.text.unlikely+0x1040): undefined reference to `vpx_img_wrap' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libvpxenc.o): In function `vp8_init': libvpxenc.c:(.text.unlikely+0x10be): undefined reference to `vpx_codec_vp8_cx' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libvpxenc.o): In function `vp9_init': libvpxenc.c:(.text.unlikely+0x10d3): undefined reference to `vpx_codec_vp9_cx' ../../../deps/ffmpeg/build/desktop/x86_64/lib/libavcodec.a(libvpxenc.o): In function `vpx_free': ... 

How it it possible for ubuntu to not have to rely on x264, libfdk-aacdec, libvpxdec, etc but when I use my compiled libraries I have to provide them?

Compiling ffmpeg for android

I am trying to compile ffmpeg for android. I have followed the steps in the tutorial. Here’s the link to the same https://yesimroy.gitbooks.io/android-note/content/compile_ffmpeg_for_android.html

What i have tried

  1. Downloaded ffmpeg source.
  2. Downloaded NDK for android.
  3. Downloaded the build scripts and added appropriate paths by edit the script using text editor.

Example My bash script. I have changed to appropriate path on my system when running.

#!/bin/bash NDK=/Users/yesimroy/Library/Android/sdk/ndk-bundle  PLATFORM=$  NDK/platforms/android-21/arch-arm64/  TOOLCHAIN=$  NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64 PREFIX=./android/arm64  function build_one {   ./configure \   --prefix=$  PREFIX \   --enable-static \   --enable-pic \   --host=aarch64-linux \   --cross-prefix=$  TOOLCHAIN/bin/aarch64-linux-android- \   --sysroot=$  PLATFORM    make clean   make   make install }  build_one  echo Android ARM64 builds finished 

Running the same in terminal

/Desktop/x264$   ./build_android_arm.sh No working C compiler found. Makefile:3: config.mak: No such file or directory ./configure Found no assembler Minimum version is nasm-2.13 If you really want to compile without asm, configure with --disable-asm. Makefile:337: recipe for target 'config.mak' failed make: *** [config.mak] Error 1 Makefile:3: config.mak: No such file or directory ./configure Found no assembler Minimum version is nasm-2.13 If you really want to compile without asm, configure with --disable-asm. Makefile:337: recipe for target 'config.mak' failed make: *** [config.mak] Error 1 Makefile:3: config.mak: No such file or directory ./configure Found no assembler Minimum version is nasm-2.13 If you really want to compile without asm, configure with --disable-asm. Makefile:337: recipe for target 'config.mak' failed make: *** [config.mak] Error 1 Android ARM builds finished 

The path for a particular architecture under NDK is `/home/raghu/Android-SDK/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android’

Am in missing anything?.

I found some tutorials https://medium.com/@ilja.kosynkin/building-ffmpeg-4-0-for-android-with-clang-642e4911c31e

My target for android is minimum android 21 which is lollipop i guess.

But i am not sure if i am missing anything. Let me know if there is anything else needs to be added in the questions.

How to run this complex ffmpeg command in python?

I’m working on a python script to automate sound and video clip processing. So far I’ve been able to run ffmpeg commands in python using subprocess, e.g:

#extract video audio subprocess.call(['ffmpeg', '-i', 'video.mp4', 'vid_audio.mp3']) 

However, I can’t seem to get the following command split into a list that works with subprocess.

#merge two audio tracks with scaled volume ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex "[0:a]volume=.3[A];[1:a] [A]amerge[out]" -map [out] -c:a libmp3lame -q:a 4 audiofinal.mp3 

Any help on how to split the above command into a list that works with subprocess would be greatly appreciated!

Ffmpeg Audio Out of Sync on Raspberry Pi Live Streaming

I have written a code that is live streaming a nature camera from my Raspberry Pi using a Pi Camera v2 to Facebook Live/YouTube.

I have ran into a couple of problems with the code that I can’t solve and require some expert support.

This is the code:

raspivid -o - -t 0 -w 1440 -h 1080 -fps 30 -b 8000000 -g 50 | ffmpeg -r 30 -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -r 30 -i - -vcodec copy -acodec aac -ab 128k -g 10 -f flv rtmp://192.168.1.1/nestbox1/**streamkey**  

The code streams fine but there are two problems:

Firstly, the audio is delayed by around 4 seconds. I have tried to solve this by using -itsoffset however this makes the audio track silent. I have tried using a negative value for e.g. -itsoffset -4 and this creates a negative audio result, which is the opposite of what I am trying to do.

-itsoffset 4 

Secondly, the audio drops out for a very short time every 5 seconds and then starts again. I suspect this is the aac driver included with ffmpeg. I have tried replacing -acodec aac with pcm_s16le and this works fine however, facebook live requires aac audio so I need to use this some how. I have looked into the FDK aac codec and this does the same.

-acodec pcm_16le 

I know there is some issue with raspivid not creating timestamps and therefore not passing them to ffmpeg and this might be part of the problem. I am continually getting a timestamp error from ffmpeg but this has not caused any problems with live streaming before