[FFmpeg-user] Advice on optimizing bitstream filter usage - unexplained frame count differences

2024-05-10 Thread Gia Ferrari
Greetings,

I feel I've come up against the limits of my ability to narrow down the cause 
of a surprising behavior related to bitstream filters, and could use a pointer 
or two on where to focus my learning. A general description of the system 
challenge I'm trying to solve is at the bottom of this message if you're 
curious, but my primary interest is in understanding why my solution is 
yielding odd results.

Source file is HEVC, containing 1557 keyframes (and many more non-keyframes). 
I'd like to select only the keyframes before decoding (CPU is scarce), rescale 
the selected frames, and write to a new MP4.

$ ffmpeg -i test_input.mp4 -bsf:v "noise=drop=not(key)" -vf "scale=320:-1" -an 
-fps_mode vfr -enc_time_base -1 -c:v libx265 -crf 32 -preset ultrafast 
test_output_combined_command.mp4

This takes 5 minutes and is CPU-bound. It also generates much fewer frames than 
I expect, resulting in choppy video. If I split up the operation into two 
separate commands, the operation completes in 20 seconds and results in a 
visually-correct video.

$ ffmpeg -i test_input.mp4 -bsf:v "noise=drop=not(key)" -an -fps_mode vfr 
-enc_time_base -1 -c:v copy test_intermediate.mp4
$ ffmpeg -i test_intermediate.mp4 -vf "scale=320:-1" -fps_mode vfr -c:v libx265 
-crf 32 -preset ultrafast test_output_split_command.mp4

Checking the 3 output files with ffprobe reveals some surprising results:

$ ffprobe -v error -select_streams v:0 -count_frames -count_packets 
-show_entries stream=nb_read_frames,nb_read_packets -of flat 
test_output_combined_command.mp4
streams.stream.0.nb_read_frames="187"
streams.stream.0.nb_read_packets="187"

$ ffprobe -v error -select_streams v:0 -count_frames -count_packets 
-show_entries stream=nb_read_frames,nb_read_packets -of flat 
test_intermediate.mp4
streams.stream.0.nb_read_frames="1557"
streams.stream.0.nb_read_packets="1557"
$ ffprobe -v error -select_streams v:0 -count_frames -count_packets 
-show_entries stream=nb_read_frames,nb_read_packets -of flat 
test_output_split_command.mp4
streams.stream.0.nb_read_frames="1557"
streams.stream.0.nb_read_packets="1557"

I'm at a bit of a loss to explain these differences. Note that the second 
ffprobe command (on test_intermediate.mp4) took multiple minutes to run, while 
the others were almost instantaneous. test_intermediate.mp4 is also nearly the 
same filesize as the input file, despite containing one thirtieth of the frames.

I feel like I'm missing a fundamental concept here. Why does one approach 
generate more frames than the other? Is noise=drop causing empty packets to be 
written somewhere? Thanks for any and all hints.

Application context:
A system I'm working on generates large HEVC MP4s on disk. These are aged out 
over time to conserve space. When that happens, I'd like to generate low-fps 
(anything above 0.25FPS is fine) low-resolution (320:180 is enough, believe it 
or not) versions of these files to use elsewhere. I've got meager CPU resources 
to dedicate to this. I've made the following observations and mitigations:

- Decoding the full stream takes significant CPU, too much for me to spare. To 
get around this, I drop all non-keyframes before decoding via -bsf:v 
"noise=drop=not(key)". This brings down the cost to acceptable levels. The 
source of the video files reliably includes a keyframe every 2 seconds. 
Hardware decoding options are not available in my environment.
- Encoding at the resolution I need (320:180) using the veryfast or ultrafast 
preset is very much fast enough for my needs, provided the input framerate is 
suitably reduced as per above.
- Scaling the video down to 320:180 is also fast enough, again provided input 
framerate reduction.

--
Gia Ferrari (she/they)
https://giferrari.net

Sent with [Proton Mail](https://proton.me/) secure email.
___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-user] VBR encoding not supported ???

2024-05-10 Thread Aditya Dandavate
On Wed, 8 May, 2024, 2:31 pm Moritz Barsnick via ffmpeg-user, <
ffmpeg-user@ffmpeg.org> wrote:

> On Wed, May 08, 2024 at 12:09:52 +0530, Aditya Dandavate wrote:
> > As I use FFMPEG mostly for creating videos that are uploaded to Youtube,
> is
> > it fine to use VP8/Opus in a .webm container ?
>
> As far as I understand, YouTube does support those formats and codecs
> for uploads. Its recommendations are different though, but feel free to
> ignore them, if it works for you:
>
> https://support.google.com/youtube/answer/1722171?hl=en
>
> > Also, Youtube does support VP8, right ?
>
> Yes, AFAIK. Just try it. ;-)
>
> Cheers,
> Moritz
> ___
> ffmpeg-user mailing list
> ffmpeg-user@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".
>

Yes, Youtube accepts VP8 video in a .webm container, but I'll stick to x264
and will use Opus (libopus) in .mp4 container instead of AAC as recommended
by Ferdi sir. Youtube accepts H.264/Opus in an .mp4 container.

Thanks anyways 👍

>
___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-user] Non-monotonic DTS issue with merging MP4 files with different tbn

2024-05-10 Thread Abhishek Gupta
Hello all,

I am trying to merge two files below that have different AV properties:
1.mp4

2.mp4


*Below is ffprobe output for 1.mp4:*
ffprobe version 6.1.1-3ubuntu5 Copyright (c) 2007-2023 the FFmpeg developers
  built with gcc 13 (Ubuntu 13.2.0-23ubuntu3)
  configuration: --prefix=/usr --extra-version=3ubuntu5
--toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu
--incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl
--disable-stripping --disable-omx --enable-gnutls --enable-libaom
--enable-libass --enable-libbs2b --enable-libcaca --enable-libcdio
--enable-libcodec2 --enable-libdav1d --enable-libflite
--enable-libfontconfig --enable-libfreetype --enable-libfribidi
--enable-libglslang --enable-libgme --enable-libgsm --enable-libharfbuzz
--enable-libmp3lame --enable-libmysofa --enable-libopenjpeg
--enable-libopenmpt --enable-libopus --enable-librubberband
--enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex
--enable-libtheora --enable-libtwolame --enable-libvidstab
--enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265
--enable-libxml2 --enable-libxvid --enable-libzimg --enable-openal
--enable-opencl --enable-opengl --disable-sndio --enable-libvpl
--disable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883
--enable-chromaprint --enable-frei0r --enable-ladspa --enable-libbluray
--enable-libjack --enable-libpulse --enable-librabbitmq --enable-librist
--enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libx264
--enable-libzmq --enable-libzvbi --enable-lv2 --enable-sdl2
--enable-libplacebo --enable-librav1e --enable-pocketsphinx
--enable-librsvg --enable-libjxl --enable-shared
  libavutil  58. 29.100 / 58. 29.100
  libavcodec 60. 31.102 / 60. 31.102
  libavformat60. 16.100 / 60. 16.100
  libavdevice60.  3.100 / 60.  3.100
  libavfilter 9. 12.100 /  9. 12.100
  libswscale  7.  5.100 /  7.  5.100
  libswresample   4. 12.100 /  4. 12.100
  libpostproc57.  3.100 / 57.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
  Metadata:
major_brand : mp42
minor_version   : 0
compatible_brands: mp42mp41
creation_time   : 2024-04-11T07:52:09.00Z
  Duration: 00:00:10.40, start: 0.00, bitrate: 1226 kb/s
  *Stream #0:0[0x1](eng): Video: h264 (Main) (avc1 / 0x31637661),
yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 861 kb/s, 30
fps, 30 tbr, 30k tbn (default)*
Metadata:
  creation_time   : 2024-04-11T07:52:09.00Z
  handler_name: ?Mainconcept Video Media Handler
  vendor_id   : [0][0][0][0]
  encoder : AVC Coding
  Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp, 316 kb/s (default)
Metadata:
  creation_time   : 2024-04-11T07:52:10.00Z
  handler_name: #Mainconcept MP4 Sound Media Handler
  vendor_id   : [0][0][0][0]


*Below is ffprobe output for 2.mp4:*ffprobe version 6.1.1-3ubuntu5
Copyright (c) 2007-2023 the FFmpeg developers
  built with gcc 13 (Ubuntu 13.2.0-23ubuntu3)
  configuration: --prefix=/usr --extra-version=3ubuntu5
--toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu
--incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl
--disable-stripping --disable-omx --enable-gnutls --enable-libaom
--enable-libass --enable-libbs2b --enable-libcaca --enable-libcdio
--enable-libcodec2 --enable-libdav1d --enable-libflite
--enable-libfontconfig --enable-libfreetype --enable-libfribidi
--enable-libglslang --enable-libgme --enable-libgsm --enable-libharfbuzz
--enable-libmp3lame --enable-libmysofa --enable-libopenjpeg
--enable-libopenmpt --enable-libopus --enable-librubberband
--enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex
--enable-libtheora --enable-libtwolame --enable-libvidstab
--enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265
--enable-libxml2 --enable-libxvid --enable-libzimg --enable-openal
--enable-opencl --enable-opengl --disable-sndio --enable-libvpl
--disable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883
--enable-chromaprint --enable-frei0r --enable-ladspa --enable-libbluray
--enable-libjack --enable-libpulse --enable-librabbitmq --enable-librist
--enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libx264
--enable-libzmq --enable-libzvbi --en