text:
ffmpeg cannot load an installed library - libavdevice.so.60
Environment: WSL Ubuntu 22.04. ([interop] appendWindowsPath = false)
Ran git clone https://git.ffmpeg.org/ffmpeg.git
Installed bunch of dependencies
The command
./configure --enable-nonfree --enable-cuda-nvcc --enable-libnpp --enable-vulkan \
        --enable-pic --enable-bzlib --enable-gpl --enable-libgsm --enable-cuda \
        --enable-cuvid --enable-iconv --enable-lzma --enable-nvenc --enable-zlib \
        --enable-sdl2 --enable-ffnvcodec --enable-nvdec --enable-libmp3lame \
        --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 \
        --enable-libx265 --enable-libaom --enable-debug --enable-libfdk-aac \
        --enable-libfreetype --enable-libvpl --enable-libmysofa --enable-libopencore-amrwb \
        --enable-libopenjpeg --enable-libsnappy --enable-libsoxr --enable-frei0r \
        --enable-libspeex --enable-libvmaf --enable-libtheora --enable-libtwolame \
        --enable-libvidstab --enable-libvo-amrwbenc --enable-libwebp --enable-libxml2 \
        --enable-libzimg --enable-libshine --enable-libxvid --enable-libopenmpt \
        --enable-version3 --enable-libsrt --enable-libsvtav1 --enable-libcaca \
        --enable-libcdio --enable-libilbc --enable-libkvazaar --enable-libmodplug \
        --enable-librist --enable-librtmp --enable-librubberband --enable-libtesseract \
        --enable-libzmq --enable-libzvbi --enable-openal --enable-ladspa --enable-libglslang \
        --enable-libxavs2 --enable-libplacebo --enable-libjxl --enable-opencl --enable-opengl \
        --enable-libopenh264 --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 --disable-static --enable-shared

runs without complaint. Maybe worth noting that, even though I changed configuration, the last configure run generated:
License: nonfree and unredistributable
libavutil/avconfig.h is unchanged
libavcodec/parser_list.c is unchanged
libavcodec/bsf_list.c is unchanged
libavformat/demuxer_list.c is unchanged
libavformat/muxer_list.c is unchanged
libavdevice/indev_list.c is unchanged
libavdevice/outdev_list.c is unchanged

make -j$(nproc) generates lots of (e.g.) CC      libavfilter/* lines
libavdevice lines look clean:
CC      libavdevice/alldevices.o
CC      libavdevice/alsa.o
CC      libavdevice/alsa_dec.o
CC      libavdevice/alsa_enc.o
CC      libavdevice/avdevice.o
CC      libavdevice/caca.o
CC      libavdevice/fbdev_common.o
CC      libavdevice/fbdev_dec.o
CC      libavdevice/fbdev_enc.o
CC      libavdevice/kmsgrab.o
CC      libavdevice/lavfi.o
CC      libavdevice/libcdio.o
CC      libavdevice/openal-dec.o
CC      libavdevice/opengl_enc.o
CC      libavdevice/oss.o
CC      libavdevice/oss_dec.o
CC      libavdevice/oss_enc.o
CC      libavdevice/sdl2.o
CC      libavdevice/sndio.o
CC      libavdevice/sndio_dec.o
CC      libavdevice/sndio_enc.o
CC      libavdevice/utils.o
CC      libavdevice/v4l2-common.o
CC      libavdevice/v4l2.o
CC      libavdevice/v4l2enc.o
CC      libavdevice/version.o
CC      libavdevice/xcbgrab.o
CC      libavdevice/xv.o

There are instances of output like this: (e.g.):
In file included from ./libavutil/common.h:48,
                 from ./libavutil/avutil.h:301,
                 from ./libavutil/opt.h:31,
                 from libavdevice/sdl2.c:31:
./config.h:338: warning: "HAVE_PTHREAD_SETNAME_NP" redefined

sudo make install outputs mostly "INSTALL"s and some "STRIP"s
Running ffmpeg gives:
ffmpeg: error while loading shared libraries: libavdevice.so.61: cannot open shared object file: No such file or directory

which ffmpeg gives /usr/local/bin/ffmpeg
The content of /etc/lib/x86_64-linux-gnu.conf is
# Multiarch support
/usr/local/lib/x86_64-linux-gnu
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu

dpkg -l | grep libavdevice gives:
ii  libavdevice-dev:amd64                 7:6.1-1build2~22.04                     amd64        FFmpeg library for handling input and output devices - development files
ii  libavdevice58:amd64                   7:4.4.2-0ubuntu0.22.04.1                amd64        FFmpeg library for handling input and output devices - runtime files
ii  libavdevice60:amd64                   7:6.1-1build2~22.04                     amd64        FFmpeg library for handling input and output devices - runtime files

dpkg -L libavdevice-dev gives:
/.
/usr
/usr/include
/usr/include/x86_64-linux-gnu
/usr/include/x86_64-linux-gnu/libavdevice
/usr/include/x86_64-linux-gnu/libavdevice/avdevice.h
/usr/include/x86_64-linux-gnu/libavdevice/version.h
/usr/include/x86_64-linux-gnu/libavdevice/version_major.h
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libavdevice.a
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/libavdevice.pc
/usr/share
/usr/share/doc
/usr/share/doc/libavdevice-dev
/usr/share/doc/libavdevice-dev/changelog.Debian.gz
/usr/share/doc/libavdevice-dev/copyright
/usr/lib/x86_64-linux-gnu/libavdevice.so

sudo find / -name libavdevice.so.61 gives:
/home/<my-home>/git/ffmpeg/libavdevice/libavdevice.so.61
Note: I have run numerous makes. I've also installed vulkan SDK, and a bunch of cuda packages (following Nvidia's instructions/wikis.) I might have done other things I've forgotten.
How do I resolve this ffmpeg runtime error?
Do I have conflicts in libraries? I am mostly interested in using GPU features/HW, especially shaders. I've just started and kinda feeling my way around.
Thank you.

Restarting the PC next day solved the problem!


text:
ffmpeg amerge/amix with itsoffset into single audio stream
I have video.mkv with 1 video and 1 audio stream. 34 minutes long.
I have 3 audio files: 0-new.wav (10 mins), 1200-new.wav (10 mins), 1800-new.wav (4 mins)
I want to discard the video's audio and replace it with 1 audio stream from combining the new audio files such that each audio file falls in the right segment on the timeline.

0-new.wav: 0 to 600 seconds
1200-new.wav: 1200 to 1800 seconds
1800-new.wav: 1800 to end of timeline

I tried:
ffmpeg \
    -i video.mkv \
    -itsoffset 0 -i 0-new.wav \
    -itsoffset 1200 -i 1200-new.wav \
    -itsoffset 1800 -i 1800-new.wav \
    -map 0:0 -map 1:a -map 2:a -map 3:a \
    -filter_complex "[1:a:0][2:a:0][3:a:0] amerge=inputs=3 [a]" \
    -map "[a]" -c:a libmp3lame -c:v copy test.mkv

I end up with 1 video stream and 4 audio streams. The first 3 audio streams occupy the correct segment on the timeline, alas in separate streams (audio tracks)
The fourth audio track is the 3 combined and occupies the first ~ 5 minutes of the timeline (the rest is silent)
I used 'amix' with the same result. I am fine with gaps in audio in the result (above, there'd be no audio from 600 to 1200 seconds)
How do I tell ffmpeg to collapse all the audio inputs into one stream output?
How do I tell it to drop the fourth stream?
As a bonus how do I tell it to keep the original video's audio for segments that would not be overwritten (e.g. 600 to 1200 in timeline)
Thank you.
(ffmpeg version 6.1-1build2~22.04 Copyright (c) 2000-2023 the FFmpeg developers)

You can use amix for this.
ffmpeg \
-i video.mkv \
-i 0-new.wav \
-i 1200-new.wav \
-i 1800-new.wav \
-filter_complex "[1:a]adelay=0:all=1[a1];
                 [2:a]adelay=1200s:all=1[a2];
                 [3:a]adelay=1800s:all=1[a3];
                 [0:a]volume=0:enable='between(t,0,600)+gte(t,1200)'[a0];
                 [a0][a1][a2][a3]amix=inputs=4:duration=first:dropout_transition=0:normalize=0[a]" \
-map 0:v -map "[a]" -c:v copy -c:a aac test.mkv

The volume filter mutes the original audio from 0 to 600s and after 1200s. To mute throughout, change enable value to simply 1.

+1. Cannot upvote yet. Thank you.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Possible dropped frames after trimming a video
I have a 30-fps video just downloaded by youtube-dl, and it seems to have black frames in the beginning of it.
Part of the result of ffprobe youtube-dl.mp4:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'youtube-dl.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.43.100
  Duration: 00:04:53.69, start: 0.000000, bitrate: 1250 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 1115 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.

Then I tried to trim the video using ffmpeg -i youtube-dl.mp4 -ss 0:0:0 -to 0:4:37 -vcodec copy -acodec copy youtube-dl-trimmed.mp4. Part of the result is below:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'youtube-dl.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.43.100
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 1115 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
Output #0, mp4, to 'youtube-dl-trimmed.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.43.100
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 1115 kb/s, 30 fps, 30 tbr, 15360 tbn, 15360 tbc (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 8288 fps=0.0 q=-1.0 Lsize=   43944kB time=00:04:36.99 bitrate=1299.6kbits/s speed= 382x
video:39364kB audio:4329kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.575328%

And use ffprobe to probe it:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'youtube-dl-trimmed.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.43.100
  Duration: 00:04:37.02, start: 0.000000, bitrate: 1299 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 1167 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.

What I wonder is that the playback results of some applications and video processing libraries vary. In some of them the video still remains the black frames, but in the others the first 22 frames disappear and certainly the total number of frames is decreased. The test result about the black frames is below:

Applications or Libraries
youtube-dl.mp4
youtube-dl-trimmed.mp4

ffplay
remained
disappeared

PotPlayer
remained
remained

VLC Player
remained
remained

Aegisub
remained
disappeared

Adobe Premiere
remained
remained

OpenCV library
remained
disappeared

It bothers me a lot because I use Aegisub to create ASS subtitles but I use FFmpeg to burn a subtitle into youtube-dl-trimmed.mp4, the black frames remain and thus the showing time of every line isn't fit with the speakers' words. Also the black frames still here when using ffplay to play the hard-subtitled video. What's wrong with these videos? Does youtube-dl-trimmed.mp4 have dropped frames? Any reply is appreciated.

EDIT:
Version string and configuration options of my ffmpeg:
ffmpeg version git-2020-05-15-b18fd2b Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9.3.1 (GCC) 20200513
configuration: --enable-gpl --enable-version3 --enable-sdl2
--enable-fontconfig --enable-gnutls --enable-iconv --enable-libass
--enable-libdav1d --enable-libbluray --enable-libfreetype
--enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb
--enable-libopenjpeg --enable-libopus --enable-libshine
--enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora
--enable-libtwolame --enable-libvpx --enable-libwavpack
--enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2
--enable-libzimg --enable-lzma --enable-zlib --enable-gmp
--enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc
--enable-libmysofa --enable-libspeex --enable-libxvid
--enable-libaom --disable-w32threads --enable-libmfx --enable-ffnvcodec
--enable-cuda-llvm --enable-cuvid --enable-d3d11va
--enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
--enable-libopenmpt --enable-amf
libavutil      56. 45.100 / 56. 45.100
libavcodec     58. 84.100 / 58. 84.100
libavformat    58. 43.100 / 58. 43.100
libavdevice    58.  9.103 / 58.  9.103
libavfilter     7. 81.100 /  7. 81.100
libswscale      5.  6.101 /  5.  6.101
libswresample   3.  6.100 /  3.  6.100
libpostproc    55.  6.100 / 55.  6.100

EDIT 2:
@slhck provided a workaround in the comments. Re-encoding the video can  keep all players behaving well.

Why do you expect -ss 0:0:0 -to 0:4:37 to trim off frames in the beginning? You start at 0; there is nothing before 0. If you wanted to trim off some frames, ss should be a positive number. Please always show the complete uncut command line output.

@slhck I used -ss 0:0:0 because I didn't want to calculate how long the black frames lasted and they just lasted less than a second in fact, then I decided to keep the frames. And the command line output is full actually. As for the uncut output, I have just added the configuration options and version string to the post. These things and the part of the result makes up the full output.

So basically when you remux the file without actually trimming anything (-ss 0), the players show different behavior? What if you re-encode with -c:v libx264 -crf 18 instead of -vcodec copy, what happens?

@slhck The black frames are still here but all the players behave the same.

Then I would recommend doing the re-encoding, but specifying a different, positive offset for -ss so that the black frames disappear. I am quite sure there's no easy way around this, in particular if you want all players behaving the same.

@slhck You are right. I just found other videos had similar problems like this one and some of them even had a long period black frames. After re-encoding them the problem was solved. Thank you a lot.

To get the correct behavior on all players, you have to re-encode the video, i.e. remove the -c:v copy/-vcodec copy part and replace it with, for example:
-c:v libx264 -crf 23

Pair it with a positive specification for -ss, e.g. -ss 0.2, to get rid of whatever black frames there were in the beginning.
This will ensure that all frames get re-encoded.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Add video in front of image (background) using ffmpeg?
I have a png and would like to add there video, so png is my case is something like a border.
I trying :
ffmpeg -i cat.mp4 -framerate 30 -i dem.png -filter_complex "[0]pad=1920:1080:500:0[vid];[vid][1]overlay" -c:a copy -movflags +faststart out2.mp4

But png is not a transparent and video hiding behind the picture. How can i set order or "z-index" position of the video to see it OVER the image?

Change [vid][1] to [1][vid]

@Gyan, in this case - png is not shown : https://c2n.me/4gfPjBc.png

Likely because your png is smaller than the video. Pad the image, not the video, OR downscale the video.

@Gyan, png size is 600x554, mp4 is 148x114. I uploaded my files in case you would like to check them... https://drive.google.com/drive/folders/1gKJCyVU0IgJ8g3zWFhCA-L93lDOWyOS-?usp=sharing

-i cat.mp4 -framerate 30 -i dem.png -filter_complex "[1][0]overlay=x=W*.27:y=H*.58" -c:a copy -movflags +faststart out2.mp4

@Gyan oh, man! thank you a lot! so magic :)


text:
How to fix a file using ffmpeg so that VLC detects Aspect ratio automatically
I have a video, where the video resolution is 852x480.
When I open it up in VLC, "the Video Aspect" ratio defaults to *Default
However, all I see is a black screen with a thin line as the video!
If I manually change the Aspect ratio to a something other than Default (e.g. 16:9) the video  displays normally.
I've never seen this happen before, why is VLC not detecting the video properly, and why do I  have to change the aspect ratio manually?
What command should I use with ffmpeg to fix it ?
Output of ffmpeg:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'SomeLesboMovie (852x480).mp4':   Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
    creation_time   : 2015-08-02T16:17:23.000000Z   Duration: 01:36:06.23, start: 0.000000, bitrate: 2163 kb/s   Stream
#0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 852x480 [SAR 1:270 DAR 71:10800], 1996 kb/s,
29.97 fps, 29.97 tbr, 30k tbn (default)
    Metadata:
      creation_time   : 2015-08-02T16:17:23.000000Z
      handler_name    : 264#video:fps=29.97:par=1:270@GPAC0.5.2-DEV-rev387-g3102094-master
      vendor_id       : [0][0][0][0]   Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 162 kb/s (default)
    Metadata:
      creation_time   : 2015-08-02T16:05:42.000000Z
      handler_name    : Sound Media Handler
      vendor_id       : [0][0][0][0] At least one output file must be specified

Paste the output of ffmpeg -i FILE

@Gyan Thank you for responding, edited to include output of ffmpeg as requested. It seems just by doing the following ffmpeg -i "MyBadMovie(852x480).mp4" -aspect 852:480  -c copy MyFixedMovie.mp4 has fixed it, can you please confirm or put the correct answer.

That's right. Your video was originally tagged as having a display aspect ratio of 71:10800.

Thank you Gyan.

I fixed my video by trying the following command:
ffmpeg -i "MyBadMovie(852x480).mp4" -aspect 852:480 -c copy MyFixedMovie.mp4

NB: user @Gyan has confirmed that my display aspect ratio was 71:10800, and I can see this now in the line below, so credit to him for also sharing his expert knowledge.

#0:00x1: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 852x480 [SAR 1:270 DAR 71:10800], 1996 kb/s,

Thank you NB.  I was able to take a video which always displayed as 4:3 to correctly display in VLC as 16:9 with
ffmpeg -i "1440x1080_video.wmv" -aspect 1920:1080 -c copy 1920x1080_video_fixed.wmv
The file properties still show as 1440x1080, but now plays in VLC with the correct aspect ratio without manually forcing VLC to play it with an AR of 16:9


text:
Hardsubbing ASS onto MPEG4
I have an ASS as the subtitle stream (with these fonts: - Orotund, jagb_.tff, jagw_.ttf, JUST.ttf, Gabrielle.ttf) in an MKV.
What technique should I use to hardsub this subtitle stream onto the MPEG4 (ISO/AVC) without losing quality?
Thanks for all suggestions

ffmpeg has an amazing article on burning the subs into the videos.
I trust ffmpeg to be very careful with (the lack of) quality loss.
Given you are dealing with ASS, here are the important bits,

You can burn text subtitles (hardsubs) with one of two filters: subtitles or ass.
ass filter
Same as the subtitles filter, except that it doesn’t require libavcodec and libavformat to work. This filter requires ffmpeg to be compiled with --enable-libass. On the other hand, it is limited to ASS (Advanced Substation Alpha) subtitles files. See the ass video filter documentation for more details.
ffmpeg -i video.avi -vf "ass=subtitle.ass" out.avi

If your subtitle is in SubRip, MicroDVD or any other supported text subtitles, you have to convert it to ASS before using this filter:
ffmpeg -i subtitle.srt subtitle.ass

Windows users will have to setup font paths to get libass to work

~10 years later! - Ah but that looks right (obviously I don't have the files anymore to test, but your syntax seems likely to work)

I'm pretty sure it's impossible to hardcode subs without quality loss.
Unless there's a new technique developed in the last 4 years, the file needs to be converted to a lossless type then the subs need to be coded frame by frame and then compress again.
So: There is no technique that may be used to hardsub onto a compressed video without losing [more] quality.

Well which technique has the least amount of quality loss?

I can point the way, but I can't explain the technique - I used to do this a looooooooooooooong time ago.
Try checking this out. The concept is taking the video OUT from the MKV conteiner and then hardcode it.

I cannot downvote yet, but this is a bad suggestion. ffmpeg has native support for hardcoding subs, and given ffmpeg is very careful with the losses, it's very much possible to burn in subs without overall quality loss

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Lossless convert 3gp video to mp4 using ffmpeg
I'm trying to get lossless conversion of 3gp to mp4 using ffmpeg.
I tried
ffmpeg -i input.3gp -vcodec h264 -c:a aac output.mp4

I tried with "libx264" for the video codec, I tried just a simple
ffmpeg -i input.3gp output.mp4

No matter what I try, for a 10 MB 3gp video I am getting a 5 MB mp4 video that doesn't seem to have the same quality.
Any suggestions are welcome.
Thank you.
EDIT
Here's what I get if I try to copy the Video and Audio codecs:
ffmpeg -i  VIDEO0004.3gp  -c:v copy -c:a copy VIDEO0004.mp4
ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.29)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.4 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'VIDEO0004.3gp':
  Metadata:
    major_brand     : 3gp4
    minor_version   : 768
    compatible_brands: 3gp4mp413gp6
    creation_time   : 2011-02-06T16:39:49.000000Z
    copyright       :
    copyright-eng   :
    rating          : 0
    location-eng    : +00.0000+000.0000/??
    location        : +00.0000+000.0000/??
  Duration: 00:01:00.20, start: 0.000000, bitrate: 1369 kb/s
  Stream #0:0(eng): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 1355 kb/s, 9.90 fps, 9.92 tbr, 1k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2011-02-06T16:39:49.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1(eng): Audio: amr_nb (samr / 0x726D6173), 8000 Hz, mono, flt, 12 kb/s (default)
    Metadata:
      creation_time   : 2011-02-06T16:39:49.000000Z
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
[mp4 @ 0x7fbaf5009600] Could not find tag for codec amr_nb in stream #1, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:1 --

If the codecs of your input file are already h264 and aac for video and audio, respectively, you can just copy without decoding and encoding again.
ffmpeg -i input.3gp -c:v copy -c:a copy output.mp4

The options -c:v copy and -c:a copy indicate video and audio won't be encoded again, respectively. If audio format in the input cannot be embedded to the output, you need to omit -c:a copy from above command.
If you need to encode again, an option -qscale 0 will result similar quality (but not lossless).
below is an example.
You might combine with -c:v copy or -c:a copy if you don't need to encode video or audio again.
ffmpeg -i input.3gp -qscale 0 output.mp4

Please check my edited question to see what I get if I try to copy video and audio.

According to your error message, the audio need to be encoded again. Fortunately, video does not need to be encoded.
This command should work ffmpeg -i input.3gp -c:v copy output.mp4, which will encode audio but won't encode video.


text:
Is CABAC encoding lossy or lossless in ffmpeg?
I've been looking into how to compress a video using ffmpeg when I stumbled across CABAC encoding which I could specify by using the libx264 for the video codec and pairing it with the proper arguments (-x264opts cabac=1), however I know that libx264 is usually used for lossy compression. However, CABAC encoding is listed as a lossless compression technique on Wikipedia. I know I can control the quality of the file by using the -crf tag but I wanted to know if I specified ffmpeg to use cabac, would the output video be compressed lossless or lossy?

Cabac is lossless, but h264 is lossy. The part you are missing is that cabac is not THE compression algorithm. It is just the final step out of hundreds of steps in video compression. By the time you get to cabac, all the lossy steps have already been performed, and a final lossless step is added to squeeze a few more bits out.

CABAC will give a small compression but increases the encoding time a bit.


text:
Convert variable framerate ~60 FPS to constant 60 FPS losslessly
I have gameplay footage recorded with ShadowPlay (“GeForce Experience”) at 60 FPS, which as I understand results in variable frame rate, because the game drops frames sometimes. However, trying to use this video in Adobe Premiere results in the game audio severely falling behind the visuals, because Premiere treats it as if every frame was the same length.
I have tried HandBrake with these settings:
Quality: constant, RF 0 (lossless)
FPS: 60, constant
Detelecine: Off
Decomb: Off
Denoise: Off
Deblock: Off
But the output video is not only much smaller than the source video, but it's massively worse in terms of visual quality. Why isn't it lossless when I've set it to what it claims is lossless?
Input video info: http://pastebin.com/7Tss4brj
Output video info: http://pastebin.com/DKFEzDKk
(from Mediainfo)
How can I convert a variable framerate video to a constant framerate video losslessly?

If you have mediainfo, can you post the readout for your output. Use View->Text mode.

Hope this helps:
Input video info: http://pastebin.com/7Tss4brj
Output video info: http://pastebin.com/DKFEzDKk

Technically, not lossless as RF is recorded as 1 not 0. Still, it shouldn't be "massively worse in terms of visual quality". How are you testing playback?

Playing it in VLC or previewing in Premiere. It has huge compression artifacts all over the place, especially with rapid movement.

Hm, just compared screenshots from the two videos in VLC and it seems about equal. The preview in Premiere is far worse. Let me investigate. It might be an issue with Premiere. Still, why is it RF 1 when I've set it as 0 and why is the output file so much smaller?

Alright, compared a different video in VLC and the quality is definitely worse. Input: http://imgur.com/AKYhyuC http://pastebin.com/4vwJi8Vj Output: http://imgur.com/m5TKr0L http://pastebin.com/49knbRiH

Try with ffmpeg. ffmpeg -i in.mp4 -r 60 -crf 0 -profile:v main -c:a copy out.mp4

Says: x264 [error]: main profile doesn't support lossless
[libx264 @ 00000000031c3280] Error setting profile main.
The only profile that accepted lossless was high444, which produced a 43.2 GB file from the 7.17 GB, which doesn't seem to be playable in VLC or Premiere (getting weird colours). http://pastebin.com/MwtMPj8Q

Oops. Skip the profile but add -pix_fmt yuv420p

That seems to have worked, but the resulting file is so huge, neither VLC nor Premiere can play it correctly. (Extremely low framerate and artifacts in VLC, weird colours in Premiere) Premiere seems to be able to export it, but it's useless for editing. :-( http://pastebin.com/7U60c0GU
Would it be possible to copy the stream data instead of losslessly copy the pixel data?

To start with: your version of Handbrake is old. Version 1.0.3 came out very recently, it's got some improvements over that older version.
Second, CQ0 is not actually "lossless." It's aiming for "lossless" quality, but it's going to bump up against the data rate limitations of the H.264 Level, so while it might need, say, 100MbPS at a given point to achieve "lossless" compression, Level 4.0 might be capping it at 20MbPS or something like that. Note in the Encoding Settings readout on your export file it lists "vbv_maxrate=20000," that's where your bitrate is capped. So to get as close to lossless as possible you'd need something like Level 5.2.
So ratcheting up your H.264 level will improve quality, but Premiere may end up chugging very hard on it. H.264 is really bad for editing. It's very computationally complex, largely because it doesn't store each frame separately (called Intraframe compression) but it takes batches of frames (called a Group of Pictures, or GOP) and compresses them together, in such a way that any one frame within a GOP will depend on the surrounding frames in order to reproduce a complete image. This is called Interframe compression, and the number of frames in a GOP depends on the parameters set at encode time, and may even be variable (not typical), but you can see what those parameters in MediaInfo by noting the line that says "Format settings, GOP" ("N=30" means 30 frames per GOP), or looking at the encoding settings where it notes "keyint" (Keyframe Interval). So needing to decode all 30 frames to show you any one frame is very CPU and RAM intensive.
If you've got the storage I'd recommend considering using DNxHD, which is a "mezzanine" (editing friendly) codec that preserves quality, considered "virtually lossless," but has low CPU/RAM impact. The catch is very high bitrates. So we're talking ~130-200GB/hr at 1080p59.94. The other catch is that DNxHD has very limited supported resolutions and frame rates. There's also CineForm which is just as high a quality, but far more flexible, and both CineForm and DNxHD are natively supported by Premiere (CineForm in 2015 and later) but last I checked CineForm support in other tools, like ffmpeg, is lacking.
So are more editing-friendly solution would be to use ffmpeg to make DNxHD with a command line the following:
ffmpeg -i (input file).mp4 -c:v dnxhd -b:v 290M -c:a pcm_s16le -r 60 (output).mxf

That would make DNxHD with uncompressed audio in an MXF Op1a file. You could also whack .mov on the end there and make a Quicktime file instead just as easily. Note that -r sets the output frame rate. You could try using H.264 in ffmpeg by changing the video codec (-c:v), but you'll run into the same limitations as you would working with Handbrake, so I don't know if it's really worth it to go into that here.

CQ0 is actually lossless. If you do a SSIM compare with the source, the metric result will be 1.0 i.e. perfect fidelity. H.264 levels are meant for hardware decoders, so they can gracefully decline to decode a stream beyond their capabilities, instead of rendering a stuttering playback. But they don't constrain x264. It will complain if your resolution/bitrate exceeds an explicitly set level but proceed nonetheless.

To reduce decoding burden, you can always set a low GOP size and disable B-frames. I don't use Handbrake, but it's easily done with ffmpeg. DNxHD will use more bandwidth than necessary.

I'm not sure if h264 cq0 is lossless in terms of bit depth.. i mean.. if you go from 8 bit to 8 bit is ok.. if 10 or 12 to 8 you will have a loss unless a 16 bit version of h264 crf 0 is available.. @Mulvya do a 16 bit per component + alpha option exists ?

Alpha is not available, and x264 does 8 and 10 bit only.

I record my Shadowplay content with the following settings:

1440p
50MBps
60 FPS
Microphone and Desktop Audio on seperate channels

So it's not compatible with the mentioned DNxHD. The audio channels are are also in variable framerates and must be synced.
The following will re-encode the video and audio in 60 FPS CFR and will not have audio sync issues in Adobe Premier. You save it to a batch file (.bat) and then run it via the command line with the video file as the first argument.
@echo off
set inputFile=%1
set outputFile=%inputFile:.mp4=_cbr.mp4%
ffmpeg  ^
-i %inputFile% ^
-vsync 1 -async 1 ^
-map 0:v:0 ^
    -c:v libx264 ^
    -preset veryfast ^
    -x264-params "nal-hrd=cbr" ^
    -b:v 50M ^
    -framerate 60 ^
-map 0:a:0 ^
    -c:a:0 aac ^
    -b:a 384k ^
-map 0:a:1  ^
    -c:a:1 aac ^
    -b:a 384k ^
%outputFile%

When comparing individual frames, I did not notice a difference in quality between this and the original recording. You can change some of the options like the framerate to match your content, or increase the bitrate if you think there is some loss.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Lossless screen-recording software
For a small project of mine I want to record short screen-casts which show features of my program. Currently, I'm using a small app on my Ubuntu box which creates directly animated gif output. The drawback is, that gif has some limitations in the number of colors. If you inspect some of the gifs you may note that although it looks great, it's not perfect, especially when you look at the aliased fonts

There are some handmade solutions, for instance the demonstration on the sublime-text site. To have something that nice, you first need to record your screen completely lossless. Most screen-casting programs I know unfortunately do compress the video.
Question: I have Ubuntu and OSX at my disposal, what (if possible free) screen-casting solutions exists which let me create lossless videos?
Extra credit for programs where I can select the region or window to record and turn off audio.
Update
To make it clear what I mean with lossless: Usually, videos are compressed with a method which is perfect for natural images/videos but horrible for images/videos having sharp edges and one-colored structures. I made two screen-casts and zoomed a small part so that those effects are visible. The first one is done with gtk-recordmydesktop with highest quality and the artifacts in the gray area are clearly visible

The second one is done with the small Record your Desktop tool which saves gif files directly and takes the exact pixels of the screen without compression.

What I want is a screen-caster which saves its videos in this raw format without the limitations of gif.
Possibly related questions:

How does Salman Khan make his screencasts?
creating a lossless mp4 screencast

I deleted my answer suggesting gtk-recordMyDesktop since it's full quality is not lossless.  I just wasn't sure if it did or not.  I don't have a Linux machine to test on unfortunately.  Now I know, thanks for letting me know it didn't fit your needs.

@AJHenderson I would be glad about any program either Linux or MacOSX. Especially for Mac there seem to exist a lot of small tools but I have to time to try them all and they kind of never advertise can record lossless.

FFmpeg with a lossless codec is one solution. I recall a comparison of different codecs which concluded that Apple Animation (known to ffmpeg as qtrle) gave the best quality for screen-recording.
ffmpeg -f x11grab -r 25 -s 1024x768 -i :0.0 -c:v qtrle output.mov

Stop it by opening its terminal while it is running and pressing q. Obviously change the resolution (1024x768 here) to match your own. For selecting a section of your screen, see how to grab the screen on the ffmpeg wiki.
It is possible that the ffmpeg which comes with your Linux distribution does not have the qtrle codec included. In this case you have to download and compile your own version.

I heard about Apple Animation as well. Let me try this.

+1 Works perfectly. Let's wait whether someone comes up with a non-commandline program. Otherwise, this will be my accepted answer.

If no-one suggests anything and you really want a GUI frontend, it seems to me that this would be a simple task for someone with GUI-making knowledge (i.e. not me :v), so you could probably find someone who would be willing to whip a simple frontend together in half an hour for a reasonable price, maybe even on chat.SE

This won't work on OS X, this is sad.

Well, just want to thank you again for this answer. I'm using OBS with the qtrle encoding to create a perfect .mov file. Then I extract the frames and use image magick to build a very small and incredibly nice animated gif. The advantage of OBS is, that you easily set output resolution and which window or part of the screen you want to record. It lets you combine several recorded regions and audio easily. Rarely seen something like that on Linux!

this will work on OS X as well, but it will need changes — they are described here https://trac.ffmpeg.org/wiki/Capture/Desktop. Also there's no need to use qtrle only, there are other lossless codecs, some of which are even better (faster and more compact).

Alternatively, pipe your screen output to a second computer to record, using a device like a Blackmagic Intensity. It supports capturing to a totally uncompressed format (make sure you have an SSD or a RAID setup to record as the bitrate is very high).
So the computer you're doing the work on should have dual monitor output - mirror the display so one output goes to your monitor, the other to a PC with a BlackMagic PCIe (or USB 3.0) card in it, that records the output. Use DVI/HDMI, not VGA.
Note, the Intensity only supports video-type resolutions, so a res like 1024x768 or 1024x1024, etc. is no good - 480p, 720p, 1080p, etc. are what you'll need to mirror your display at (21" 1080p LCDs are $99 now anyways).
Then you can edit & compress the raw video any way you like.

Hehe, I thinkt this is way overkill but +1 for the answer. I need something quick which I can use when I have developed feature the make a screen cast.

I had very similar requirements and eventually found on Claquette.
It's an OS X app that uses a lossless codec. While it doesn't allow you to define a screen area before recording, it has a crop feature that allows you to select a region after the recording is finished. Audio can also be turned off. Movies can be exported in various formats (including h.264, ProRes and Animated GIF).

Seems like a good little program. Currently, I'm doing my small gifs with Kazam which comes with Ubuntu. Then I'm using a small script built from the accepted answer to create small and high-quality gifs. +1

On OS X, seems like ScreenFlow can record in lossless (not by default, but this can be enabled in settings). Unfortunately, this application is not free. Still looking for free alternatives…
Important update!
This applies only to Screenflow 4.5.3 (and maybe some earlier versions). In Screenflow 5 this feature is gone. They advertise like they can do lossless recording, but this is a blatant lie: the "lossless" mode is using Apple ProRes, which is not lossless (and I tested the output, it indeed has artifacts), and there's no way to select some other codec (in Screenflow 4.5.3 the lossless mode is achieved by using "Animation" codec, which is qtrle, in Screenflow 5 there's no way to do this)
So… good bye, sweet prince.
Update 2
ffmpeg also can record the screen, if you learn how to use it properly.

Btw, I bought ScreenFlow back when you posted you answer. Even if I'm not using it for creating the small animated gifs this question targeted, it is still a very nice screen-caster that has a lot of nice features.

^ btw, one can choose only one from "gif" and "small". gif is a very inefficient compression.

I would use Screenflow for this.  I've got version 8, and it exports ProRes 4444 at 100% size, which is effectively lossless for most purposes.

well, it's not really lossless, and the question is about lossless only

Here's a non-command-line option.
Try Collaaj (http://collaaj.com). Works on PC & Mac. It doesn't work on Ubuntu, but since you mentioned you have OSX, this should work just fine. I think it should do what you asked for and more. Such as region selection, selecting inputs etc.., and it also lets you upload and maintain your recordings on collaaj.com for anytime access. They have a nice set of videos here - http://collaaj.com/videos

Can you really record the windows of your screen with this tool? I only saw that they scroll through powerpoint or pdf files. Furthermore, I need to extract the frames of the video, which means I need to be able to store the videos locally. It seems this tools uploads it directly to share it, right?

Halirutan, 1. yes, on PC & Mac, you can record entire screen. You can even change settings between 720P and 1080P, you can also do screen+camera at the same time.

Halirutan, regarding your second question, Collaaj stores videos locally in mp4 format, in addition to giving you an option to upload to the cloud and share as a URL. Its very comprehensive.

This video explains clearly - https://collaaj.com/9rE17cT

Please excuse my tardiness to the party, this is something that I've been working with as of late lossless screen recording
Originally I was using OBS to record my screen throughout the year 2019 primarily for uploading screen recordings / cast to youtube, however I've recently began experimenting using ffmpeg to record my screen and mic have not tested recording desktop audio yet.
I started with vanilla ffmpeg settings for recording my screen, but the stock GOP setting of the recording makes it utterly painful when editing the recording in a NLE / NLA editor such as shotcut so I went back and reread the screen capture doc on the ffmpeg wiki, and noticed that screen recordings can be captured lossless using the x264 codec as long as -crf 0 the crf is set to 0 which I believe means ffmpeg will use the x264 codec will not apply any lossy compression to the recording.  Also the wiki suggests using -preset ultrafast in conjunction with the -crf 0 setting of the ffmpeg command.  I experimented with these settings last night and the picture quality / file size is great.
I recorded my screen 4K 3840 x 2160 monitor at 30 fps and the bitrate was totally manageable, ie. I don't think it ever went above 10MB/sec, and a one minute recording was ~ 48MB, which is totally acceptable file size for archiving recordings.
Caveats

obviously if you do not prefer using a command line then this will probably not be for you, as I've found relying a GUI to interface with ffmpeg is not a viable thing as most GUIs I experimented with are outdated.
also, presently I have issues with recording audio mic and screen at the same time under a single ffmpeg process / command, so I have to split the command into two separate commands / processed and start them simultaneously to keep the audio / video in sync.

I run macOS 10.13.6 and I'm using the Nvidia web driver so that may be the issue why I the single ffmpeg process / command of recording screen and mic at same time is failing.  Not entirely sure what the issue is. ♂

I have not come up with a solution for recording the audio in a lossless codec yet, but that will definitely be my next task to research
also, I'd like to convert all prior recordings ffmpeg & OBS using this new technique to preserve them for archival purposes.

You mention your converting your recordings to animated GIFs, I've used the following project to convert little screen recordings to GIFs will only work with terminal based recordings, and have had pleasant results using it.  It even has a docker container that makes using it rather simple for various OSes.
I did experiment with using ffmpeg to convert and iPhone recording to animated GIF a while back which was useful for uploading the GIF to github because I believe github does not support uploading video files such as mov mkv or mp4.
Also, I did a quick search on the QTRLE codec and it seems it is not compatible with the MP4 container format, so if using something other than MOV is required you might look at using a different codec.
⚠ the below command will require concurrently be installed.
concurrently --kill-others \
"ffmpeg -f avfoundation -capture_cursor 1 \
-capture_mouse_clicks 1 \
-framerate 30
-i "1:" -c:v libx264 -crf 0 -preset ultrafast \
lossless-screen-rec.mkv 2>/dev/null" \
"ffmpeg -f avfoundation -i ":3" \
-acodec alac \
lossless-mic-.m4a 2>/dev/null"

the above command will capture the computer screen losslessly using x264 and using alac to capture microphone input losslessly as well.  both formats work well for editing in a NLA/NLE editor such as shotcut.
⚠ ":3" and 1: will vary per system running macOS
To get a list of capture devices on macOS
ffmpeg -f avfoundation -list_devices true -i ""

Anyways I know this is a lot of information, but I thought I'd share this info for the fact that I have been using ffmpeg almost daily for the past couple of weeks now so I thought I'd share what I've learned, and leave this info for future me

Welcome! Can you share a complete ffmpeg command? That would make it a lot easier for future readers to be able to use your answer.

Wonderful! Thank you for working that out and sharing.  Also, since I don't need audio, I can just run the first ffmpeg command without concurrently.

If you need something less complicated try rec, which is mine :) https://sites.google.com/site/joopeter/
It is also free, lossless but more efficient and accurate!

As I wrote, I have OSX and Ubuntu at my disposal. Your program is for Windoze XP and above.

besides, the link is no longer active.


text:
x265: Is it possible to re-compress HEVC video without quality loss?
My situation:

Transcoding 1080p bluray videos to HEVC. Audio untouched;
My rig is old (pre-2012) and to speed up the process I'm using --preset ultrafast;
From x265 documentation, I understand that video quality is independent of the preset used. And the slower the preset, the better the compression ratio it seems;
I'm using FFmpeg.

My Reasoning:

I want to start converting to HEVC now because the codec is good enough for me and the space saving is phenomenal;
I've seen people reporting a 35GB video compressed to 1GB or so with crf=18 and --preset veryslow. It sounds ludicrous but an experiment of my own shows about 40% additional space saving between presets ultrafast and veryslow.

The Question:
When I get a new rig with a more capable CPU (Skylake or later, I hear), is it possible for me, to "re-compress" my HEVC videos using eg. --preset veryslow, without quality loss due to encoding a second time?

In strict mathematical terms, no.
In terms of maintaining an acceptable image quality, yes. If you use CRF 18 and a preset like ultrafast now, you should be able to get a smaller acceptable file with preset veryslow later on.

Ahh too bad. Upon testing a longer clip, the size reduction is around 20%. I can live with that I guess. Thanks for the quick answer!


text:
creating a lossless mp4 screencast
I'm trying to create a screencast for playback on the web. Would like to use h.264, webm, and ogg. The source files are in the Apple Animation codec, and they look perfectly accurate. However when I try to convert to mp4 using ffmpeg lossless settings, there is some definite degradation. It seems to be because the source is RGB and ffmpeg auto-selects yuv420p instead.
Incompatible pixel format 'rgb24' for codec 'libx264', auto-selecting format 'yuv420p'

Anyone know how to get the same color accuracy with mp4/h.264 as with Apple Animation?
Thanks

H.264 does support true lossless compression (see 'Lossless mode' on this page). It seems that to avoid chroma format conversion, you need to encode using the Hi444PP profile, which accepts RGB pixels. However, a cursory search indicates that x264 doesn't support Hi444PP (yet), whereas some commercial codecs like MainConcept do.

Seems like maybe a high bitrate would be a good alternative. Of course the OP has long since dealt with this problem one way or another by now.

That page you report says something different, h264 lossless exists using an option like -qp 0 and also h264rgb could be achieved for example in libx264rgb. A question could arise: Do this kind of video compatible everywhere and played correctly? Depends, often no unless they support all the range of possible decoding, all softwares based on ffmpeg and ffshow can however, including VLC.

If you need something less complicated try rec, which is mine :)
https://sites.google.com/site/joopeter/
It is also free, lossless but more efficient and accurate!

It works only on Windows

@Peter You could improve your answer by giving a little more detail about what rec is and how it works.

if you want yuv444p try something like this: "-vcodec libx264 -pix_fmt yuv444p"
LosslessH.264 seems to imply that lossless (or practically lossless) is available via -qp 0

You can also use -crf 0 with 8-bit builds of x264. The only reason -qp is used instead is because 10-bit builds of x264 uses different values for -crf (I believe -crf -12 for 10-bit would be lossless) to achieve a similar visual quality.

just a note about yuv444p, it's not as widely supported as yuv420 so depending on what you're doing with the video next, this can cause issues (e.g. Apple Quicktime, iMovie, and devices can't handle yuv444)


text:
Recording IP camera RTSP Stream with FFMPEG - append to file
I am recording an IP camera stream using ffmpeg.
Here are the goals that I want to achieve:

Record an entire day in a single file

In case of a disconnect be able to restart the process and continue recording to the same file (appending to the previous content, not overwriting)

Be able to view the recorded content as its being recorded (so the format and codec should not need finalization)

I've tried a few approaches. In the end I settled on recording in the TS format because it allows for easy appending. The issue is that those files end up being huge (cca 20-25 GB per day). I can have a follow up job that compresses them but I don't see any way to do this that isnt either CPU intensive or takes 5 times as long as the video duration to complete.
If I record using any other format like .mkv or .mp4 then appending to the file causes errors. Either not all of the content can be viewed or at the very least time seeking is broken.
I've also tried recording in smaller chunks and then appending them. That also works, producing files that are without errors and with a decent size. If all else fails I will return to this approach. I would like to avoid this if possible, though.
This breaks down into two questions:

If I stick to recording using the TS format: Is there any non-resource-intensive way to bring the file size down under 10 GB after the file has finished recording?

If I change the file format (and codec) to something that is more manageable from the start: Can I somehow append to the existing file without breaking it? Or can I fix those errors in a second run?

What did you settle on?

Still working on it. Based on the experience thus far, I would go for recording in 1-minute chunks. Easier for replay, you can save on space with a better format and easier for cloud backup. @SeaDude

What are you using for scripting the stream? Python?

Bash is the scripting language that i am using @SeaDude

https://github.com/isaric/recording-scripts @SeaDude this is basically it bu this approach is going for continuous one chunk recording in an appendable format


text:
Lost frames with ffmpeg
I'm having regularily issue with hvc1 videos getting an inconsistent number of frames between ffprobe info and ffmpeg info, and I would like to know what could be the reason of this issue and how if it's possible to solve it without re-encoding the video.
I wrote the following sample script with a test video I have
I split the video in 5 sec segments and I get ffprobe giving the expected video length but ffmpeg giving 3 frame less that expected on every segment but the first one.
The issue is exactly the same if I split by 10 seconds  or any split, I always lose 3 frames.
I noted that the first segment is always 3 frame smaller (on ffprobe) than the other ones and it's the only consistent one.
Here is an example script I wrote to test this issue :
# get total video frame number using ffprobe or ffmpeg
total_num_frames=$(ffprobe -v quiet -show_entries stream=nb_read_packets -count_packets -select_streams v:0 -print_format json test_video.mp4 | jq '.streams[0].nb_read_packets' | tr -d '"')
echo $total_num_frames
ffmpeg -hwaccel cuda -i test_video.mp4 -vsync 2 -f null -

# Check ffprobe of each segment is consistent
rm -rf clips && mkdir clips && \
ffmpeg -i test_video.mp4 -acodec copy -f segment -vcodec copy -reset_timestamps 1 -segment_time 5 -map 0 clips/part_%d.mp4
count_frames=0
for i in {0..5}
do
    num_packets=$(ffprobe -v quiet -show_entries stream=nb_read_packets -count_packets -select_streams v:0 -print_format json clips/part_$i.mp4 | jq '.streams[0].nb_read_packets' | tr -d '"')
    count_frames=$(($count_frames+$num_packets))
    echo $num_packets $count_frames $total_num_frames
done

Output is the following
3597
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
  configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.29.100
  Duration: 00:00:59.95, start: 0.035000, bitrate: 11797 kb/s
    Stream #0:0(und): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709), 1920x1080, 11692 kb/s, 60.01 fps, 60 tbr, 19200 tbn, 19200 tbc (default)
    Metadata:
      handler_name    : Core Media Video
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 91 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
Stream mapping:
  Stream #0:0 -> #0:0 (hevc (native) -> wrapped_avframe (native))
  Stream #0:1 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.29.100
    Stream #0:0(und): Video: wrapped_avframe, nv12, 1920x1080, q=2-31, 200 kb/s, 60 fps, 60 tbn, 60 tbc (default)
    Metadata:
      handler_name    : Core Media Video
      encoder         : Lavc58.54.100 wrapped_avframe
    Stream #0:1(und): Audio: pcm_s16le, 44100 Hz, mono, s16, 705 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
      encoder         : Lavc58.54.100 pcm_s16le
frame= 3597 fps=788 q=-0.0 Lsize=N/A time=00:00:59.95 bitrate=N/A speed=13.1x
video:1883kB audio:5162kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

then
297 297 3597
300 597 3597
300 897 3597
300 1197 3597
300 1497 3597
300 1797 3597 <--- output are consistent based on ffprobe

But then if i check segment size with ffmpeg with the following command
ffmpeg -hwaccel cuda -i clips/part_$i.mp4 -vsync 2 -f null -

for part 0 its ok
frame=  297 fps=0.0 q=-0.0 Lsize=N/A time=00:00:04.95 bitrate=N/A speed=12.5x
video:155kB audio:424kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

for all other parts it's inconsistent and should be 300
frame=  297 fps=0.0 q=-0.0 Lsize=N/A time=00:00:04.95 bitrate=N/A speed=12.3x
video:155kB audio:423kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

The issue is exactly the same with any other interval size, e.g with 10 seconds I would get the following video size:
ffprobe 597 - 600 ...
ffmpeg 597 597 ...
I thought it could be related to source vfr or cfr but I tried to convert the input to cfr and nothing changes.
Moreover I tried to force key frame at every second to check if it was a keyframe issue with the following arg :  -force_key_frames "expr:gte(t,n_forced*1)", but the problem is exactly the same.
What am I doing wrong ? it happens to me a lot with files in hvc1 and I really dont know how to deal with that.

from : https://stackoverflow.com/questions/70578206/inconsistent-frame-number-with-ffmpeg
The source of the differences is that FFprobe counts the discarded packets, and FFmpeg doesn't count the discarded packets as frames.

Your results are consistent with video stream that is created with 3 B-Frames (3 consecutive B-Frames for every P-Frame or I-Frame).
According to Wikipedia:

I‑frames are the least compressible but don't require other video frames to decode.
P‑frames can use data from previous frames to decompress and are more compressible than I‑frames.
B‑frames can use both previous and forward frames for data reference to get the highest amount of data compression.

When splitting a video with P-Frame and B-Frame into segments without re-encoding, the dependency chain breaks.

There are (almost) always frames that depends upon frames from the previous segment or the next segment.
The above frames are kept, but the matching packets are marked as "discarded" (marked with AV_PKT_FLAG_DISCARD flag).

For the purpose of working on the same dataset, we my build synthetic video (to be used as input).
Building synthetic video with the following command:
ffmpeg -y -r 60 -f lavfi -i testsrc=size=384x256:rate=1 -vf "setpts=N/60/TB" -g 60 -vcodec libx265 -x265-params crf=28:bframes=3:b-adapt=0 -tag:v hvc1 -pix_fmt yuv420p -t 20 test_video.mp4

-g 60 set GOP size to 60 frames (insert a key frame every 60 frames).
bframes=3:b-adapt=0 force 3 consecutive B-Frames.

For verifying the number of I/P/B frames, we may use FFprobe:
ffprobe -i test_video.mp4 -show_frames -show_entries frame=pict_type

The output is like:
pict_type=I
pict_type=B
pict_type=B
pict_type=B
pict_type=P
pict_type=B
pict_type=B
pict_type=B
...

Segment the video by time (5 seconds per segment):
ffmpeg -i test_video.mp4 -f segment -vcodec copy -reset_timestamps 1 -segment_time 5 clips/part_%d.mp4

FFprobe counting:
297 1497 1200
300 1797 1200
300 2097 1200
303 2400 1200
FFmpeg counting:
frame=  297
frame=  297
frame=  297
frame=  300
As you can see, the result is consistent with your output.

We may identify the "discarded" packets using FFprobe:
ffprobe -i part_1.mp4 -show_packets

Look for flags=_D.
Packet with flags=_D is marked as "discarded"
Note: In a video stream every packet matches a frame.
FFprobe output begins with:
flags=K_
flags=_D
flags=_D
flags=_D
flags=__
flags=__
flags=__
...
For every middle segment, 3 packets are marked as "discarded", and that is the reason for the 3 missing frames in FFmpeg compared to FFprobe.


text:
DaVinci Resolve Stabilize button not doing anything
I'm trying to stabilize a clip in DaVinci Resolve (18.0.1 (also updated to 18.0.2, same), M1 Mac, macOS 12.5.1). I've tried both Edit tab (Inspector / Stabilization) and Color tab (Tracker / Stabilization), but nothing happens when I click Stabilize button. Nothing happens as if I've not hit the button, and the clip is not stabilized. Changing mode (perspective/similarity/camera lock etc) doesn't do anything. Stabilization toggle is enabled in Edit/Inspect and bypass isn't checked in Color tab either.
I've also disabled proxies/optimized media/caches too, no luck.
From what I've seen in tutorials, it should start analyzing but nothing happens.
What am I doing wrong?

Okay, I've found the reason. For some reason, Stabilization only works on direct footage files, not timelines.
I was applying it to a timeline. I created a new timeline with the clip and applied stabilization on the clip, it worked.
Perhaps this could be improved. I had a timelapse with a drone that I wanted to stabilize, and there were two files as the file size grew > 4GB it was cut into two files.
I was unable to stabilize joining two clips as stabilize button wasn't working that way.
I was also unable to stabilize two clips individually first, as it was creating an incoherent jump in intersection point of the clips as it stabilized them individually without knowing the other.
I had to end up closing Resolve, use ffmpeg to concat two videos without re-encoding into a single large file, import that into Resolve as a single file and then continue my workflow.


text:
Which desktop recording software can be used to record also right click popups
Most of desktop recording software which I have tried - like sharex, obs studio - does not record everything - like right mouse click popup windows are missing from recording. At least for external applications, like Visual studio (For explorer right click popups are shown).
Do you know some desktop recording software, which can be used to do that one ? Or may be some driver/ option / etc...
Prefer open/ free software if possible.

After some struggling - I've used sharex - but before that one following thing needs to be done first.
Install TightVNC, register and start server.

From settings enable loopback connection.
Start TightVNC viewer
From options select 'View only (Inputs ignored)'.
Connect to localhost - resize to half of display on one side, on another side select application to record.

You can also disable jpg compression / improve image for quality from VNC viewer settings.
Record normally using shareX, from VNC viewer connection (not from desktop software).


text:
Frame-by-frame PSNR using ffmpeg
Is it possible to get a dump of the PSNR of every frame of a video using ffmpeg or ffprobe? So far all the options I've seen are for comparing two videos or getting the average across the whole video. If ffmpeg cannot do it, are there other softwares that can?
Edit: OK it seems like I misunderstood what PSNR is. I thought it was a measure of quality of an image, but it seems like it is a measure of quality between an original image and a compressed image.

Have you read the filter docs: http://www.ffmpeg.org/ffmpeg-filters.html#psnr

@Gyan I did, it says "Obtain the average, maximum and minimum PSNR (Peak Signal to Noise Ratio) between two input videos.", but I want to find it for a single video, and when I tried to input the same video twice as both inputs, the output stats file was just a bunch of zeros

ok it seems like I misunderstood what PSNR is, sorry


text:
What is the anatomy of a video file?
I am creating a software related to video editing.
So, I need to understand what is a video file, how is it created and how does it work?
One thing that I want to achieve is: I want to be able to add chapters to existing videos that can be used in vlc media players Chapters option in the Playback menu

This question may sound weird. But please consider that I am completely new to realm of video construction/editing/creating and I don't find any resource to start learning from
Any suggestion gratefully received. Thanks in advance.

Hi Dron - welcome. You have a few questions in there, and they can all be answered in different ways, so can you please edit it down to one question. Before doing that, please read other questions on video file structure as we have quite a few here and they may answer your needs.

@DrMayhem Can you mention some resource to to start learning how videos work... the mechanism behind videos -- any resource on this topic... excluding Wikipedia

@DrMayhem I can understand that this question is a mess. As I said I am just a newbie to this topic. You can edit this question if you can understand my intention behind this question.

Most of the common video files are containers (like *.mp4, *.mkv) - they can hold different type of streams (video, audio, subtitles, data) and some additional description of these streams (metadata). There are also some video files with a raw video data (like *.h264) - they are representing single video stream and they can also be used with some video players.
(more info about video files)


text:
How to stablize a movie that wobbles right and left about 3 pixles throughout the whole thing?
I have some copies of original theatrical films that came as bonus DVDs. These copies are in 4:3 aspect ratio but are widescreen. So playing the movies in a standard DVD player renders it in a small box with big black lines on all sides.
I have been able to fix that issue with ffmpeg.
The issue left now, is that while digitizing, it seems that whatever was used to playback the reel, wobbled in relation to whatever was capturing the image.
So throughout the whole movie, it shifts left and right a few pixels. It's not the most noticeable thing, but I feel like it is something that should be easily fixed.
I have tried a number of settings with the ffmpeg included filter 'deshake', but have no idea what I'm doing. It either moves things way too much, or it does nothing. It has the setting rx, that is supposed to limit the corrective movement left and right, but it gives an error when I enter a value that's not a multiple of 16. (The documentation says it can be 0-64)
Here's an example of the deshake section of the command I've been trying:
deshake=x=0:y=150:w=720:h=60:rx=16:ry=0:edge=3:blocksize=4:filename=loog.log"

All searches I have done come up with solutions for shaky footage from something like a GoPro.
How can I go about correcting the shifting with ffmpeg?

If deshake filter does not work for you then you can try to use libvidstab library.
The specific values of parameters can be hard to say without seeing your input video (you need to get them by testing) but the general workflow goes like this: first FFmpeg creates "the map of shakes" and then it will try to stabilize the video by using this info in its next pass.
Here are some examples of video and commands to use.

Okay. I can see that it make a sort of 'shake' map. Then I can apply the corrections using that map. There's no way to lock it to right and left though.

@ForSerious You said that movie shifts to left and to right all the time so what kind of lock do you need?

I need it to ignore any up and down motion. The trf file creates info about each frame that looks like: Frame 92 (List 7 [(LM 0 0 301 147 48 0.062305 0.045573)...
If I knew what those meant, I could probably make a script that would generate a trf file to my exact need.

@ForSerious Maybe this will help you: https://github.com/georgmartius/vid.stab/issues/62

You lead me to the answer. With that information I have been able to make a script that makes a transform file that libvidstab can read.
Manually entering the transform values from Blender will take awhile, but that's my problem.

@ForSerious I'm so glad to hear that! :D


text:
Extreme video stabilization in Linux, again
I have a 3840x2160 MOV file taken with my EM1.II Olympus camera. It is a videoclip of a tiny bird taken in the wild without any aids. Hence, despite the good stabilization feature of the camera, the bird moves quite a bit along the frame. I want to stabilize the video USING LINUX ONLY (Fedora 35 fully updated).
I can crop A LOT, since the bird is quite small in the frame. Yet, the bird moves quite a bit in the frame, in a circle of around 800 pixels in diameter. But the video is not "blurred": the bird is fixed and sharp most of the time, thanks to the stabilization of the camera.
I tried to install Blender, but it does not run complaining about my old video card. I then tried Kdenlive without luck: the motion tracker effect was removed last year. So the natural clues I found in Google do not apply anymore.
Anyway, there should be a good way to stabilize the video using ffmpeg and other software. ffmpeg comes with a stabilization feature, but it only works for small movements, and my movements are not small at all.

You could try older versions of Blender. https://download.blender.org/release/

DaVinci Resolve (free version) works on Linux and has good stabilization. I'm currently running Resolve 17 on Pop! OS 21.1 without a problem. To make a Debian type installer I used https://www.danieltufvesson.com/makeresolvedeb
Edit:
Somehow missed that you are on Fedora, however it does seem like some folks have it running on that distro.

Yes, thanks, I will try it. Here is a page for installing in Fedora: https://www.fosslinux.com/40081/how-to-install-davinci-resolve-on-fedora.htm

No luck. I installed it without problems, but when I run /opt/resolve/bin/resolve only a black window appears that I have to CNTR-C. Then it refuses to run again crashing.

@LuisA.Florit the comments on the link you posted suggest there are problems installing Resolve 17 on Fedora.

@LuisA.Florit You could try installing an older version like Resolve 16.1.1 Older versions are available here: https://www.blackmagicdesign.com/support/family/davinci-resolve-and-fusion

I tried 16.1.1. Exactly the same problem happens. It seems there's a problem with log4cxx: https://forums.centos.org/viewtopic.php?t=61600


text:
How do you automatically fix pan in Equirectangular 360 video?
I have used a GoPro Max to record a long video.

8 hours.
indoor.
well lit.
static on a monopod.
spherical (360).

Unfortunately, the "World Lock" pan stabilisation messed up (not sure why) so now the world slowly spins left, even though the camera did not physically move whatsoever. I have also tried turning off World Lock but the problem persists. Being well lit, indoor footage, there are plenty of clearly defined reference points that could be used for tracking.
I have seen that it is possible to do manual motion tracking using keyframes in Premiere Pro, and that the automatic tracking only works with masks. With so much footage, however, manual methods are not really feasible. Is there a way to automatically fix the pan using tracking points?
Tagged with Premiere Pro and Resolve as I have both. Don't mind which one I use. If you have a better suggestion than either of these, I'm all ears.
Apologies in advance if this is a bit of a newbie question!


text:
'Maintain Audio Pitch' in Speed/Duration causes Audio Glitch
When I change the Speed/Duration of an audio track and check Maintain Audio Pitch, I frequently get a moment of louder audio immediately following the edit point. This is very frustrating…
Here's a screen recording.
As a workaround I tried adding…

additional frames and…
fades at the beginning of the audio, but the problem remains.

What I also tried:

Updating from Premiere Pro version 15.4 to 22.2
Removing all attributes and effects from audio clips
Rendering and nest audio clips
Exporting everything
Deleting the Media Cache and Media Cache files
Resetting the preferences

I can reproduce the exact same problem with an entirely new project and different audio files (I tried MP3 and WAV). As soon as I change Speed/Duration and check Maintain Audio Pitch, the glitch appears.
What can I do to fix this?


text:
MP4 file has incorrect length (duration) and plays back 5x slower than it should
I have five GoToMeeting (GTM) .mp4 recordings that I saved and downloaded from a five-day class I was teaching. Each recording represents each day's appx. 8 hour class duration.  I am importing them into Camtasia to trim some parts from them and then exporting them back out. It's all going fine until I get to the Day 3 file. Day 1 and Day 2 are 716 MB and 867 MB respectively, and have played back correctly within Camtasia and allowing me to trim and edit just fine.
The Day 3 file is about 5x bigger than the other 4 files (5.7 GB vs ~1 GB). When I import the file into Camtasia it shows that it is 39:13:17 in duration.  This I know to be incorrect because I can see the computer's Windows system time in the video in my recording -- the first frame shows a Windows time of 8:00 AM in the recording and the last frame shows a Windows system time of 3:47 PM. So I know the true duration should be 07:47:00.
I suspect that something got messed up when the file downloaded from my GTM account.  But I don't know what is messed up or how to fix it.  Maybe the framerate is wrong?  The bitrate?  At any rate, some kind of metadata in the file is obviously wrong and causing Camtasia to load it as a 39 hour file and making it playback at about 5x slower than it should. I'm sure all of the content is there (I see all of the video that I am expecting to see and the audio playback is super slo-mo, but there).
I'm fairly inexperienced with ffmpeg so I'm unsure what settings and/or process I need to go through to fix the file.  Can someone kindly walk me through the steps/process?  I've been combing through the ffmpeg documentation and Googling from about 3 hours now and am very frustrated.
Edit #1:  As requested by @Gyan, output from ffmpeg -i day3.mp4 -report
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\ffmpeg\day3.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp41isom
    creation_time   : 2020-08-29T04:02:38.000000Z
  Duration: 39:13:17.43, start: 0.000000, bitrate: 331 kb/s
  Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 204 kb/s, 30 fps, 30 tbr, 30k tbn (default)
    Metadata:
      creation_time   : 2020-08-29T04:02:38.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : AVC Coding
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 121 kb/s (default)
    Metadata:
      creation_time   : 2020-08-29T04:02:38.000000Z
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
At least one output file must be specified

Run ffmpeg -i day3.mp4 -report. Upload the generated report and link it.

@Gyan updated post with output of report.  Currently trying ffmpeg -i "C:\ffmpeg\day3.mp4" -r 150 -filter:v "setpts=PTS/5" -an "C:\ffmpeg\out.mp4" to try to shorten the duration by 5x and without dropping frames (hopefully).  Beside it taking FOREVER to run, just based on the current file size (it's been running for 5 hours so far) I'm not holding out much hope that the result is going to be correct (07:47:00 duration with 1/5 file size) because it is processing up to 02:36:30 into the file so far and the output file size is 689.921 KB.

Try ffmpeg -itsscale 0.2 -an -i day3.mp4 -vn -i day3.mp4 -c copy newday3.mp4


text:
Why does setting a maximum bitrate in Constrained Quality mode sometimes increase file size?
Short version: Why did my total file size increase when I switched from constant quality to constrained quality at the same crf? Shouldn't this just set a maximum bitrate and thus only either do nothing or lower file size, depending on whether the maximum is hit?
Long version: I'm trying to maximise (subjective) overall quality in a library of video files given a fixed total file size limit for the entire library.
I started off with constant quality, and adjusting the crf until I hit my limit.
But I found a subset of scenes (usually simple but with a single moving object) looked particularly low quality/smeary. After watching the bitrate meter during encoding I concluded too much of the budget was spent in complex high-action scenes (where subjectively I think the extra quality is somewhat wasted), leaving not enough for "simpler" scenes, so, short of a more direct method to apply an adjustable bias towards simpler scenes (I don't want to just switch straight to constant quantization or constant bitrate or anything, I'm trying to find an optimal middle ground), I decided to try constrained quality, as described here: https://trac.ffmpeg.org/wiki/Encode/VP9, where I intended to slowly lower the maximum until I couldn't justify lower quality complex scenes, then use the freed space to boost the crf to the benefit of the simple scenes.
This seems to have sort of worked, but the behaviour I'm seeing is surprising, and I don't understand it.
I expected that setting a maximum bitrate with -b:v 1M (I'd seen quite a few complex scenes were exceeding that bitrate, pushing to around 1.5M) would reduce the total size of the entire library of video files (at the cost of reducing quality in complex scenes).
Instead, I found the total file size had increased after I applied this, meaning constrained quality mode does not behave the way I expected.
Theories:

My original expectation was that constrained quality meant "match constant quality but any scenes that exceed the maximum bitrate will use VBR/target bitrate rules to control their bitrate instead".
Now I wonder if perhaps another possibility is that the constraint only applies globally for the entire video, and once the constant quality goal tries to cross the bitrate constraint (momentarily?, or on average over a video?), the entire video stops trying to match constant quality, and instead follows the VBR rules, which forces the "simple" scenes to suddenly use vastly more bitrate than they needed in constant quality mode. That seems insane and pointless to me, constrained quality makes no claim about boosting the quality beyond that requested, so why waste bits giving higher quality that wasn't asked for?

Some videos use significantly less in constrained quality mode, as expected, and some videos use significantly more, which I didn't expect at all. On the other hand, without me having to change the crf at all, the "simple" scenes I originally wanted to boost the quality for have actually increased in quality, exactly as I originally wanted, I just don't know why it behaves this way!
I'm seeing a subset of longer videos reduce in size by 7% or so (276MB -> 257MB total for 17 files), but I'm seeing a subset of shorter videos increase in size by 40% or so (95MB -> 133MB total for 220 files).
Commands used look something like
Constant Quality:
ffmpeg -y -i in_file.mov -c:v libvpx-vp9 -crf 32 -b:v 0  -pass 1 -passlogfile in_file.webm.log -an -f null /dev/null && ffmpeg -i in_file.webm -c:v libvpx-vp9 -crf 32 -b:v 0  -pass 2 -passlogfile in_file.webm.log -an out_file.webm
Constrained Quality:
ffmpeg -y -i in_file.mov -c:v libvpx-vp9 -crf 32 -b:v 1M -pass 1 -passlogfile in_file.webm.log -an -f null /dev/null && ffmpeg -i in_file.webm -c:v libvpx-vp9 -crf 32 -b:v 1M -pass 2 -passlogfile in_file.webm.log -an out_file.webm
(so identical beyond the -b:v value)

You problem is easy: -b:v does not set the maximum bitrate, but the target bitrate. Set target bitrate first -b:v 1M, then maximum bitrate -maxrate 2M.


text:
How to record OBS Studio in full screen?
I'm new to OBS Studio and have just recorded a video.
Once the recording completed, I realized that the produced video was not in full screen.
There is a blank area mark with X as shown in the screenshot below.

I only noticed this issue when I replayed the recorded video with VLC.
How do I fix this problem?
I would like to record the video in full screen, not half of the screen size.


text:
Beginner looking to try a short CG film, any suggestions for software?
Sorry if I'm using the wrong terminology or anything, I've never done anything like this before.
I'd like to try my hand at making a short 2-3 min film in CG. What I'm kinda envisioning is something like the clone wars series on disney+, but I think that's probably a bit advanced. I checked around the site a it, and found these two(1 2) questions that were kinda helpful for transitions and storyboarding, but I still don't really know where I should be making the actual video. This question had some suggestions, but I'm still just a beginner and don't really know what I'm doing. Are these good suggestions, or do I need something else?
Since I've never done anything like this before and will probably be bad at it, I'm preferably looking for a free software, or a short subscription or cheap app. That way if I suck, its not that big of a loss. Any suggestions?

You could check out Blender. It's free and there are a lot of tutorials. I'm not doing much animations, so can't help you further.

Lower your expectations. 2 or 3 minutes of CG can take you MONTHS even when you know what you are doing.
Make a short clip of 10 seconds first.

Months ago, I'd done some researches on this topic; even i had CG background, i don't have much time on modeling. My suggestion for you is to do How to Create 2D Animations - Beginner Blender Tutorial firstly, then https://conceptartempire.com/blender-animation-tutorials/


text:
Video Editor that can import Photoshop PSD files and overlay them on video with transparent channel?
I am using Magix Movie Edit Pro for about 10 years because it has one feature that I use all the time: Being able to import Photoshop files (PSD) with transparent channels into the video and overlaying the video clip.
However, all versions of the software were buggy (video format could not be read anymore by an update, software often crashed while doing simple video cuts, even the 2020 version crashes when simply opening the MVP project file).
To get rid of this annoying and time-extensive instability, I would love to use an alternative video editing software.
I have seen that Adobe Premiere and After Effects have the feature of importing PSD files, but I have never worked with the programs because they looks complicated and seem pricy.
The video editing software should be simple to use. I don't need any effects. Just fade-in and fade-out, and PSD files with transparency. Multiple tracks and separate audio track.
Operating system: Windows 10.
Thanks for any tips.

Update: I have tried myself the following video editors, here are the results:
Cannot import PSD files:

DaVinci Resolve
HitFilm Express ("File not supported")
Lightworks
Olive
Power Director
Shotcut

Can import PSD files (but not handle them):

Blender (shows up in the tracks but not showing up as overlay)
KdenLive (shows up in the tracks but not showing up as overlay)

Can import and display PSD files:

Adobe After Effects
Adobe Premiere Pro
FilmoraPro
Magix Movie Edit Pro
Sony Vegas Pro (is Magix company)

.PSD is a proprietary image format, which Adobe owns.  If you want interoperability outside the Adobe suite, use a non-proprietary format, such as   OpenEXR (which supports transparency, layers, 8,16, 32 bits).  If you don't need multiple layers, .png's also support transparency.

Also, Davinci Resolve does support .psd.  I just tried it.  It works.

...and it does support transparency.  You might need to adjust the premultiplication of alpha channels, if you had troubles in the past, but that's the same for any software.


text:
Recorder for 2 HDMI Signals into MP4/MKV with 2 Video Tracks
Is there something like the Atomos Ninja V, but with two HDMI inputs and producing MP4 or MKV files with two video tracks? A combination of multiple devices (mixer, recorder) would also be fine.

What is your question? Please edit your post to clarify.

FFMPEG takes 2 -i input options (can a capture device) and uses -map to select the input streams then uses -program to define program name and -st to define output streams to a output file. i.e.
!ffmpeg -y -i https://mkvtoolnix.download/samples/vsshort-vorbis-subs.mkv \
-i https://github.com/Matroska-Org/matroska-test-files/raw/master/test_files/test5.mkv \
-map 0:0 -map 0:1 -map 0:2 -map 0:3 \
-map 1:0 -map 1:1 -map 1:2 -map 1:3 -map 1:4 -map 1:5 -map 1:6 -map 1:7 -map 1:8 \
-program title=vsshort-vorbis-subs:st=0:st=1:st=2:st=3 \
-program title=test5:st=4:st=5:st=6:st=7:st=8:st=9:st=10st=11:st=12 \
 -c:s copy mpts.mkv

Thanks for pointing me to ffmpeg. Originally, I wanted a hardware recorder. But now I think a computer with ffmpeg will be much more helpful for my application.


text:
compare two video then cut the different
I have 2 video files with the same content, but coming from a different source. They have a slight difference in 'cut' and language dubbing, meaning one can be missing a shot compared to the other.
I have a other language dubbed that is correctly timed for one file (call it A), and because of the different cut, a bit off for the other (call it B).
The thing is that “A” also has low quality, while “B” is of better quality, and original language dubbed.
I basically need to fix the timing of the dubbed to match B.
In order to do so, i need to locate the missing/additional shots between the 2 videos, so i know where to cut it..
This is realistic if i have only one pair of files, however i have 20 pair of files !
I would like to automate this search, and basically compare the 2 files at different points in time, and find where they diverge.
How can I do this?
Since file A has other dubbed language, the comparison method should be exact enough to detect content difference..

Does it need to be automated? Is it something you would be doing to many files, or are you asking how to do this in video editing software the conventional way.

I mean auto highlight the video that is not on video 1. then there is an option to delete all highlight scene. I do it in manual I compare two video if the video 2 has scene and no in video 1 I deleted it, but I almost consume 1 day to compare and cut the 1 hr video. I want is there a software to highlight then cut all scene that is not have on video 1 in one click. no need to search whole video and cut one by one.

anyone have an idea regarding this? another sample is 1 hr video with dubbing in another language but this video has low quality and cut some scene. and the original video with original language and high quality. what I want is it can compare this two videos then the all cut scene will highlight on another video then it can cut. after the cut, the audio of low quality video will replace the audio of the original video with high quality video.

I still don't understand what you are trying to do - your comments have made me understand it less.

I edited the my question to clear it.

A Clip(C) is a sequence of frames, each frame(f) consists of video and audio frames, the duration(t) of each frame is constant and is determined by the frame rate.
For the i th clip(Ci), it is defined as (fi_n) n∈ℕ
back to your question, the idea is to find the result of
⊕Cj , where j ∈ {0,…,19}
Since the sizes of all Cj are not the same, the elements or frames of ⊕Cj are not guaranteed to be monotonic increasing. Therefore, different frames, with expected sequence, cannot be identified in this problem.
=======
IF you can guarantee the sizes of all Cj to be the same,
a video frame can be extracted by ffmpeg to a png file and a audio frame can be extracted by the t second of wav file. The ⊕ operation can be handled by image diff and easily be found in Google.

what kind of software do I use?

My answer has included everything you need, good luck.

I think it is more complicated than my manual cut. I use techsmith camtasia studio, I compare the two videos then I cut manually the difference but it take me 3 to 6 hrs cuting the 1hr video. I have 20 videos, so in 1 day I only edited 2 to 3 videos a day. it takes me 6 to 10 days to complete all videos.

Downvoted as I'm not sure re-writing the problem into fancy (unformatted) mathematical notation and suggesting to just use ffmpeg, an image diff and googling is a helpful answer.


text:
Can I increase the scrolling speed of the showspectrum ffmpeg filter?
The way it is the spectrogram doesn't even reach through my screen after two minutes of playback. I want 30 seconds at most.

Welcome! It isn't entirely clear what you are asking. Are you saying that the generated spectrogram only fills part of the screen when you want it to fill your entire screen by 30 seconds in to a longer piece of audio? Please share the exact ffmpeg command you are using and the full console output.

Hi! I want it to scroll quicker, to fill the screen quicker and to show more detail.

I am not sure your difficulties , but do examples from this link help?

I'm ttrying to increase the speed it scrolls at.


text:
How to make a SMALL video from single still image + audio, one key frame and all the rest p frames or whatever
I have a WhatsApp message of 1 hour duration, it is an .ogg audio of less than 9 MB in size.
I want to upload it to YouTube, so I have to make it at least a single-frame video. So I made a JPEG cover picture of 1024 x 768 pixels. First I just used VLC and output a youtube SF or whatever output, but YouTube churns on that "processing 0%" for days on end now. So now I have to do something else. Using ffmpeg. Ideally I would just use the awesome ogg compression passing it through:
ffmpeg -loop 1 -y -i image.jpg -i audio.ogg -shortest -acodec copy -vcodec libx264 -crf 25  -pix_fmt yuv420p result.mp4

But that doesn't play in some players, so I won't even bother youtube with it.
ffmpeg -loop 1 -y -i image.jpg -i audio.ogg -shortest -acodec mp3 -vcodec libx264 -crf 25  -pix_fmt yuv420p result.mp4

That creates a huge file of over 120 MB in size! I have crappy internet, not going to blow a <9 MB file into >120 MB just to upload it you youtube.
So I thought if I could have only one i-frame and the rest p-frames which should be basically empty because the "video" has no changes to the picture over time. I read about the -g option:
ffmpeg -loop 1 -y -i image.jpg -i audio.ogg -shortest -acodec mp3 -vcodec libx264 -crf 25  -pix_fmt yuv420p -g 100000 result.mp4

The -g 100000 covers the 94,288 frames. But still with that I get >60 MB.
How can I make the most compact mostly-audio + still image video that youtube will actually finish processing?
Here is some more calculation to show just why anything above 20 MB should not be acceptable.
Audio in the ogg compression is 8.61 MB in size. That makes a bitrate of
  8.61 MB * 1024^2 [B/MB] / 8 [b/B] / 62 [min] / 60 [s/min]
= 303.368... b/s

That is 303 bits per second! That's pretty awesome encoding power of this one channel mono ogg audio. Imagine what a 300 bits per second teletype terminal feels as you type! And now imagine how you can talk faster through this sort of low bandwidth line than you can type and see a screen refresh!
But I'm perfectly OK with the MP3 audio perhaps being a little bigger. What I am not OK is the video encoding or something else giving this codec license to stream data out in ~200 kb/s, kilo-bit, even if that is at 4x the speed, 50 kb/s is still too much if the payload goes with less than 1 kb/s.
BTW, that Title image JPEG is 170 kB in size. If I just put a new full key i-frame copy of it every minute, then I'd get 10 MB for the "video" payload, not 60 MB. So something is very wrong with these codecs or the way they are parameterized.

A 120MB upload shouldn't be a problem in 2020.  Please tell me you're on a remote island or something.

I am in Brazil with super crappy Internet. And there is no reason that a "video" of a still image must be so big.

It should be.  Somebody here knows.  Unfortunately, not me.  I'll follow this question though, and see if I can help you get an answer.

I had a similar question before and found it answered here. The file size that I got after encoding was almost equal to the audio only file size. Hope it helps. https://video.stackexchange.com/questions/23061/adobe-premiere-video-size-with-static-image

There are a couple of things which you may still tune in the x264 encoder like listed here but also in the mp3 decoder like shown here if you are OK with a lower audio bitrate.My assumption is that not everything is eaten up by the video.
I have tried
ffmpeg -loop 1 -y -i image.jpg -i audio.ogg -shortest -acodec mp3 -qscale:a 7 -vcodec libx264 -preset ultrafast -tune stillimage -maxrate 5K -bufsize 100K -crf 25  -pix_fmt yuv420p -g 100000 result5.mp4

and got a video file that was half the size of the ogg file.
Here is what the parameters do and how to use them:
-maxrate 5K -bufsize 100K
this has a direct impact on the video bitrate. I lowered the values until I got VBV underflow messages then raised it back again. The quality of the jpeg was very low but got better when I increased bufsize.
-qscale:a 7
This produces a 100 kbit Audio stream which was more than OK for my sample.
In a nutshell, you may need to tweak these parameters a little bit in order to improve things. I suspect that it is actually the audio in your case consuming a large part.
Let me know if it works.

Thanks for the effort you put into this answer. To make sure it wasn't the audio, I just used the -acode copy form, and then the video still was 12 MB in size and it was terrible blocky even on that still image. You are certainly right that the re-coded audio in MP3 is going to take bandwidth. But the video part is still kind-a ridiculous. I remember many years ago I coded DVD rips into divx or so, and there was definition of the i-b-p frame sequences and also multi-pass so that I don't think it would have been so wasteful with still images.

True - I did that too at the time - thinking it over, is there a reason the picture needs to be 1024x768? If you reduce to SD (720x480 or 576) and maybe reduce the fps to 15 I am sure you could tweak another 30-40%.. Alternatively using another codec (Quicktime? Not sure it works with youtube) might be an option - have you seen https://learningsolutionsmag.com/articles/1203/video-compression-secrets-smaller-files-better-quality (something tells me you have ;-) )

I am not sure your output stream video and audio distributions, let's assume the output size is mostly occupied by the video ES.
In the H.266 era, x265 is not a new codec
!ffmpeg -y -i https://github.com/Matroska-Org/matroska-test-files/raw/master/test_files/test5.mkv -c:v libx265 -an VideoOnly_265.mp4

The file size of VideoOnly_265.mp4 is

-rw-r--r-- 1 root root 4283630 Sep  7 12:38 VideoOnly_265.mp4

!ffmpeg -y -i https://github.com/Matroska-Org/matroska-test-files/raw/master/test_files/test5.mkv -c:v libx264 -an VideoOnly_264.mp4

The file size of VideoOnly_264.mp4 is

-rw-r--r-- 1 root root 10956223 Sep  7 12:33 VideoOnly_264.mp4

https://www.videoproc.com/resource/h266-vvc.htm  "Therefore, it would be 3-5 years before H.266 is generally supported by more hardware and software. Some experts expect that this new codec would not be widely accepted and used until 2027. It is not expected to replace H.264 and HEVC. Instead, we will enter a new era with the coexistence of multiple codecs."

Excuse me, I am here to suggest to use x.265.

So, how is this “the h.266 era?”

h265 18 MB, h265 with the same arguments otherwise 11 MB, no blocky image, better than the 12 MB blocky image. I'm going to stick to 264 and will just use MP3 now. So far, this is the command for 264 (and 265 is the same except for 264->265): ffmpeg -loop 1 -y -i Title.jpg -i WhatsApp\ Audio\ 2020-09-02\ at\ 15.54.18.ogg -shortest -acodec copy -vcodec libx264 -preset ultrafast -crf 25  -pix_fmt yuv420p -g 100000 result264.mp4

OK, now definitely the MP3 is the biggest problem, turns to 66 MB just because of the recoded audio.. I'll see if YT can figure out the OGG stream.