Commit Graph

68 Commits

Author SHA1 Message Date
Bastien Montagne d1e732a114 FFMPEG: Cleanup: Remove storage of last FFMPEG frame read as `ImBuf` in anim data.
The `anim` data (e.g. of a VSE sequence) would store the last frame read from
FFMPEG as an image buffer, increasing its refcounting and preventing it
to be freed until the whole `anim` data itself gets freed.

In current code, there is no reason to keep a reference to this image
buffer in the `anim` data, so removing it. This may also give a few
percent improvement on the memory usage of the VSE in some cases.

Found while investigating #114342.

Pull Request: https://projects.blender.org/blender/blender/pulls/114395
2023-11-03 11:18:21 +01:00
Sergey Sharybin c1bc70b711 Cleanup: Add a copyright notice to files and use SPDX format
A lot of files were missing copyright field in the header and
the Blender Foundation contributed to them in a sense of bug
fixing and general maintenance.

This change makes it explicit that those files are at least
partially copyrighted by the Blender Foundation.

Note that this does not make it so the Blender Foundation is
the only holder of the copyright in those files, and developers
who do not have a signed contract with the foundation still
hold the copyright as well.

Another aspect of this change is using SPDX format for the
header. We already used it for the license specification,
and now we state it for the copyright as well, following the
FAQ:

    https://reuse.software/faq/
2023-05-31 16:19:06 +02:00
Campbell Barton 6b9a500a3a Cleanup: disambiguate terms "name", "file" & "str" / "string"
- Rename name/filename/path to filepath when it's used for full paths.
- Rename name/path to dirpath when it refers to a directory.
- Rename file to filepath or path (when it may be a file or dir).
- Rename ImBuf::name & anim::name to filepath.
2023-05-03 15:26:14 +10:00
Sergey Sharybin e3f14b99c3 Refactor: Convert ImBuf to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/107503
2023-05-02 11:32:27 +02:00
Richard Antalik f0a3d2beb2 FFmpeg: Add VFR media support
Variable frame rate (VFR) files have been difficult to work with.
This is because during sequential decoding, spacing between frames is
not always equal, but it was assumed to be equal. This can result in
movie getting out of sync with sound and difference between preview and
rendered image. A way to resolve these issues was to build and use
timecodes which is quite lengthy and resource intensive process. Such
issues are also difficult to communicate through UI because it is not
possible to predict if timecode usage would be needed.

With this patch, double buffer is used to keep previously decoded frame.
If current frame has PTS greater than what we are looking for, it is not
time to display it yet, and previous frame is displayed instead.

Each `AVFrame` has information about it's duration, so in theory double
buffering would not be needed, but in practice this information is
unreliable.

To ensure double buffer is always used, function
`ffmpeg_decode_video_frame_scan` is used for sequential decoding, even
if no scanning is expected.

This approach is similar to D6392, but this implementation does not
require seeking so it is much faster. Currently `AVFrame` is only
referenced, so no data is copied and therefore no overhead is added.

Note: There is one known issue where seeking fails even with double
buffering: Some files may seek too far in stream and miss requested
PTS. These require preseeking or greater negative subframe offset

Fixes: T86361, T72347

Reviewed By: zeddb, sergey

Differential Revision: https://developer.blender.org/D13583
2022-06-27 16:58:07 +02:00
Sebastian Parborg c2016feadc Merge branch 'blender-v3.1-release' 2022-02-18 18:25:31 +01:00
Sebastian Parborg af6a1b08e3 VSE: Refactor our code to be compatible with ffmpeg 5.0
In ffmpeg 5.0, several variables were made const to try to prevent bad API usage.
Removed some dead code that wasn't used anymore as well.

Reviewed By: Richard Antalik

Differential Revision: http://developer.blender.org/D14063
2022-02-18 18:24:16 +01:00
Campbell Barton c434782e3a File headers: SPDX License migration
Use a shorter/simpler license convention, stops the header taking so
much space.

Follow the SPDX license specification: https://spdx.org/licenses

- C/C++/objc/objc++
- Python
- Shell Scripts
- CMake, GNUmakefile

While most of the source tree has been included

- `./extern/` was left out.
- `./intern/cycles` & `./intern/atomic` are also excluded because they
  use different header conventions.

doc/license/SPDX-license-identifiers.txt has been added to list SPDX all
used identifiers.

See P2788 for the script that automated these edits.

Reviewed By: brecht, mont29, sergey

Ref D14069
2022-02-11 09:14:36 +11:00
Sebastian Parborg ded68fb102 VSE: Fix audaspace not reading ffmpeg files with start offset correctly
The duration and start time for audio strips were not correctly read in
audaspace.

Some video files have a "lead in" section of audio that plays before the
video starts playing back. Before this patch, we would play this lead in
audio at the same time as the video started and thus the audio would not
be in sync anymore.

Now the lead in audio is cut off and the duration should be correctly
calculated with this in mind.

If the audio starts after the video, the audio strip is shifted to
account for this, but it will also lead to cut off audio which might not
be wanted. However we don't have a simple way to solve this at this
point.

Differential Revision: http://developer.blender.org/D11917
2021-08-16 15:10:58 +02:00
Sebastian Parborg 14508ef100 FFmpeg: Fix seeking not returning the correct frame when not using TC index
Fixed the logic for seeking in ffmpeg video files.
The main fix is that we now apply a small offset in ffmpeg_get_seek_pos
to make sure we don't get the frame in front of the seek position when
seeking backward.

The rest of the changes is general cleanup and untangling code.

Reviewed By: Richard Antalik

Differential Revision: http://developer.blender.org/D11492
2021-06-05 02:48:09 +02:00
Sebastian Parborg 8d6264ea12 Cleanup: Remove deprecated variables and functions calls from our ffmpeg code
There need to be more cleanup for ffmpeg 4.5 (ffmpeg master branch).

However this now compiles on ffmpeg 4.4 without and deprication
warnings.

Reviewed By: Sergey, Richard Antalik

Differential Revision: http://developer.blender.org/D10338
2021-05-07 17:12:25 +02:00
Campbell Barton 2abfcebb0e Cleanup: use C comments for descriptive text
Follow our code style guide by using C-comments for text descriptions.
2020-10-10 22:04:51 +11:00
Jacques Lucke 91694b9b58 Code Style: use "#pragma once" in source directory
This replaces header include guards with `#pragma once`.
A couple of include guards are not removed yet (e.g. `__RNA_TYPES_H__`),
because they are used in other places.

This patch has been generated by P1561 followed by `make format`.

Differential Revision: https://developer.blender.org/D8466
2020-08-07 09:50:34 +02:00
Dalai Felinto 2d1cce8331 Cleanup: `make format` after SortedIncludes change 2020-03-19 09:33:58 +01:00
Sybren A. Stüvel 3977854c70 Cleanup: rename anim::duration to anim::duration_in_frames
Units should be explicit, and not left to be guessed by the reader.

The field is only used in a single C file, so it's a relatively low-risk
change.
2019-09-19 15:26:17 +02:00
Campbell Barton e12c08e8d1 ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.

For details on usage and instructions for migrating branches
without conflicts, see:

https://wiki.blender.org/wiki/Tools/ClangFormat
2019-04-17 06:21:24 +02:00
Campbell Barton de13d0a80c doxygen: add newline after \file
While \file doesn't need an argument, it can't have another doxy
command after it.
2019-02-18 08:22:12 +11:00
Campbell Barton eef4077f18 Cleanup: remove redundant doxygen \file argument
Move \ingroup onto same line to be more compact and
make it clear the file is in the group.
2019-02-06 15:45:22 +11:00
Campbell Barton 65ec7ec524 Cleanup: remove redundant, invalid info from headers
BF-admins agree to remove header information that isn't useful,
to reduce noise.

- BEGIN/END license blocks

  Developers should add non license comments as separate comment blocks.
  No need for separator text.

- Contributors

  This is often invalid, outdated or misleading
  especially when splitting files.

  It's more useful to git-blame to find out who has developed the code.

See P901 for script to perform these edits.
2019-02-02 01:36:28 +11:00
Campbell Barton c0f88ed8a8 Cleanup: sort forward declarations of enum & struct
Done using:
  source/tools/utils_maintenance/c_sort_blocks.py
2019-01-28 21:17:58 +11:00
Campbell Barton b8467273b8 Cleanup: redundant defines
Comment or remove unused defines.
2019-01-26 19:15:30 +11:00
Campbell Barton e74bd46ede Cleanup: trailing space for imbuf module 2018-06-17 17:04:54 +02:00
Sybren A. Stüvel ea0e2f9bd3 Load metadata from video files and expose via RNA
The MovieSequence and MovieClip classes now have a metadata() function
that exposes the `IDProperty *` holding the video metadata.

Part of: https://developer.blender.org/D2273

Reviewed by: @campbellbarton
2018-04-05 16:50:24 +02:00
Bastien Montagne c528b9b777 Fix T53003: IMB: Invalid framerate handling due to short integer overflow.
FFMPEG uses int for the numerator, while Blender uses a short. So in
cases people gave weird exotic framerate values and we cannot reduce
enough the numerator, we'd get totally weird values (even negative frame
rates sometimes!)

Now we add checks for short overflow and approximate as best as possible
in that case (error should not matter unless you have shots of at least
several hundreds of hours ;) ).
2018-01-26 14:59:16 +01:00
Aaron Carlisle efd5e3c254 Remove quicktime support
It has been deprecated since at least macOS 10.9 and fully removed in 10.12.

I am unsure if we should remove it only in 2.8. But you cannot build blender with it supported when using a modern xcode version anyway so I would tend towards just removing it also for 2.79 if that ever happens.

Reviewers: mont29, dfelinto, juicyfruit, brecht

Reviewed By: mont29, brecht

Subscribers: Blendify, brecht

Maniphest Tasks: T52807

Differential Revision: https://developer.blender.org/D2333
2017-09-22 16:40:05 -04:00
Aaron Carlisle 9f044cb422 Remove MinGW support
The Issue
=======

For a long time now MinGW has been unsupported and unmaintained and at this point,
it looks like something that we should just leave behind and move on.


Why Remove
==========

One of the big motivations for MinGW back in the day is that it was free compared to MSVC which was licensed based.
However, now that this is no longer true we have basically stopped updating the need CMake files.
Along with the CMake files, there are several patches to the extern libs needed to make this work.  For example, see:
https://developer.blender.org/diffusion/B/browse/master/extern/carve/patches/mingw_w64.patch

If we wanted to keep MinGW then we would need to make more custom patches to the external libs and
this is not something our platform maintainers are willing to do.

For example, here is the patches needed to build python: https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-python3

Fixes T51301

Differential Revision: https://developer.blender.org/D2648
2017-05-27 15:34:55 -04:00
Campbell Barton a430c688ee Cleanup: unused defines 2016-06-01 00:26:14 +10:00
Sergey Sharybin cfc8d80f2c ImBuf: Solve re-definition warnings
The idea now is to have FFmpeg/OIIO headers listed after
the system ones. This is because FFmpeg/OIIO might define
some constants with the same name as the ones from math.h.

FFmpeg/OIIO has ifdef around defines, but math.h doesn't
check whether constants were already defined or not, which
causes some noisy warnings.
2016-02-20 14:06:06 +05:00
Campbell Barton 9ab7482657 Imbuf: remove libredcode
D1751, remove this library since its quite a specific - only supports an older version of this codec.

Also ffmpeg has added support for recent versions of the codec.
2016-02-03 18:39:37 +11:00
Campbell Barton 3ce4a58aa9 Cleanup: duplicate includes 2015-06-18 06:32:01 +10:00
Dalai Felinto d5f1b9c222 Multi-View and Stereo 3D
Official Documentation:
http://www.blender.org/manual/render/workflows/multiview.html

Implemented Features
====================
Builtin Stereo Camera
* Convergence Mode
* Interocular Distance
* Convergence Distance
* Pivot Mode

Viewport
* Cameras
* Plane
* Volume

Compositor
* View Switch Node
* Image Node Multi-View OpenEXR support

Sequencer
* Image/Movie Strips 'Use Multiview'

UV/Image Editor
* Option to see Multi-View images in Stereo-3D or its individual images
* Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images

I/O
* Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images

Scene Render Views
* Ability to have an arbitrary number of views in the scene

Missing Bits
============
First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report.

Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report.

Everything else is likely small todos, and may wait until we are sure none of the above is happening.

Apart from that there are those known issues:
* Compositor Image Node poorly working for Multi-View OpenEXR
(this was working prefectly before the 'Use Multi-View' functionality)
* Selecting camera from Multi-View when looking from camera is problematic
* Animation Playback (ctrl+F11) doesn't support stereo formats
* Wrong filepath when trying to play back animated scene
* Viewport Rendering doesn't support Multi-View
* Overscan Rendering
* Fullscreen display modes need to warn the user
* Object copy should be aware of views suffix

Acknowledgments
===============
* Francesco Siddi for the help with the original feature specs and design
* Brecht Van Lommel for the original review of the code and design early on
* Blender Foundation for the Development Fund to support the project wrap up

Final patch reviewers:
* Antony Riakiotakis (psy-fi)
* Campbell Barton (ideasman42)
* Julian Eisel (Severin)
* Sergey Sharybin (nazgul)
* Thomas Dinged (dingto)

Code contributors of the original branch in github:
* Alexey Akishin
* Gabriel Caraballo
2015-04-06 10:40:12 -03:00
Sergey Sharybin 759e96164a Fix #33433: Importing video files into movie clip editor crashes Blender
This was a regression in svn rev52718 caused by the fact that we can not
free packet fun until we've finished all manipulation with decoded frame
since frame and packet could share same pointers.

For now restored old behavior of next_packet which seems to be well
tested and better not do bigger refactoring here so close to release.

Memory leak fixed by that revision was fixed by calling av_free_packet
just before avcodec_decode_video2 in cases we're at the end of file.

Tested with valgrind and could not see any memory leaks in ffmpeg
area.
2012-12-06 21:08:24 +00:00
Peter Schlaile ecf89326e1 == FFMPEG ==
This fixes a memory leak caused by the last packet on stream EOF not freed.
(Memory leak occurs on ffmpeg heap managed by av_malloc / av_free, so it is
invisible to Blender)

Also: clean up the code a little bit (anim->next_packet was never really used,
so could be moved into a local variable)
2012-12-02 15:15:44 +00:00
Campbell Barton aa1e50be94 add option to build without blenders default avi codec. 2012-10-08 02:51:42 +00:00
Sergey Sharybin a73dd3476e Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.

This introduces two configurable color spaces:

- Input color space for images and movie clips. This space is used to convert
  images/movies from color space in which file is saved to Blender's linear
  space (for float images, byte images are not internally converted, only input
  space is stored for such images and used later).

  This setting could be found in image/clip data block settings.

- Display color space which defines space in which particular display is working.

  This settings could be found in scene's Color Management panel.

When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.

This conversions are:

- View, which defines tone curve applying before display transformation.
  These are different ways to view the image on the same display device.
  For example it could be used to emulate film view on sRGB display.

- Exposure affects on image exposure before tone map is applied.

- Gamma is post-display gamma correction, could be used to match particular
  display gamma.

- RGB curves are user-defined curves which are applying before display
  transformation, could be used for different purposes.

All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.

This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).

Some technical notes:

- Image buffer's float buffer is now always in linear space, even if it was
  created from 16bit byte images.

- Space of byte buffer is stored in image buffer's rect_colorspace property.

- Profile of image buffer was removed since it's not longer meaningful.

- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
  to support other spaces, but it's quite large project which isn't so
  much important.

- Legacy Color Management option disabled is emulated by using None display.
  It could have some regressions, but there's no clear way to avoid them.

- If OpenColorIO is disabled on build time, it should make blender behaving
  in the same way as previous release with color management enabled.

More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management

--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00
Campbell Barton 84bf3e48c0 style cleanup: use c style comments in C code 2012-07-06 23:56:59 +00:00
Campbell Barton e34a1fc1a5 style cleanup: imbuf 2012-05-16 09:26:37 +00:00
Campbell Barton 112162e09e code cleanup: header cleanup 2012-04-30 14:24:11 +00:00
Campbell Barton a0c4efa3d2 code cleanup: remove duplicate define on windows. 2012-04-12 03:10:36 +00:00
Campbell Barton 2b7ca2304a unify include guard defines, __$FILENAME__
without the underscores these clogged up the namespace for autocompleation which was annoying.
2012-02-17 18:59:41 +00:00
Campbell Barton ae771e742b change filepath limit from 240 to 1024 2012-01-21 14:54:53 +00:00
Peter Schlaile af66321f3b == Sequencer / FFMPEG ==
This fixed two issues:

* RAW DV-seeking has to be done using DTS. Sounds silly, but ffmpeg
  tracks internal state in RAW DV format decoder and runs mad, if
  we seek by byte. Don't know, why I haven't noticed that, when I
  added it.
  
* real fix(tm) for #29295
  problem was: we did AVFrame read ahead, and the pattern
  read_frame -> decode -> read_frame -> do color conversion of first frame
  works everywhere but RAW RGB-files which do some pointer shuffling
  within ffmpeg to save a memcpy...
  
  I removed read ahead completely, since it didn't work like originally
  intented. Might come back later, but the original purpose (making
  resyncing easier if we are completely lost in stream) it never
  fullfilled.
2011-11-20 16:08:56 +00:00
Campbell Barton 4a04f72069 remove $Id: tags after discussion on the mailign list: http://markmail.org/message/fp7ozcywxum3ar7n 2011-10-23 17:52:20 +00:00
Campbell Barton 74017cb020 header cleanup and typo's 2011-10-22 01:53:35 +00:00
Campbell Barton 83a2f02a78 cleanup endian handling
- define __BIG_ENDIAN__ or __LITTLE_ENDIAN__ with cmake & scons.
- ENDIAN_ORDER is now a define rather than a global short.
- replace checks like this with single ifdef: #if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__hppa__) || defined (__BIG_ENDIAN__)
- remove BKE_endian.h which isn't used
2011-09-19 08:02:17 +00:00
Campbell Barton 425a81a29b remove WITH_* defines from image formats, instead just dont build the files at all. 2011-09-19 06:32:19 +00:00
Peter Schlaile c07bd1439a == Sequencer ==
This patch adds:

* support for proxy building again (missing feature from Blender 2.49)
  additionally to the way, Blender 2.49 worked, you can select several
  strips at once and make Blender build proxies in the background (using
  the job system)
  Also a new thing: movie proxies are now build into AVI files, and
  the proxy system is moved into ImBuf-library, so that other parts
  of blender can also benefit from it.
  
* Timecode support: to fix seeking issues with files, that have
  a) varying frame rates
  b) very large GOP lengths
  c) are broken inbetween
  d) use different time code tracks
  
  the proxy builder can now also build timecode indices, which are
  used (optionally) for seeking.
  
  For the first time, it is possible, to do frame exact seeking on
  all file types.
  
* Support for different video-streams in one video file (can be
  selected in sequencer, other parts of blender can also use it,
  but UI has to be added accordingly)

* IMPORTANT: this patch *requires* ffmpeg 0.7 or newer, since
  older versions don't support the pkt_pts field, that is essential
  for building timecode indices.
  
  Windows and Mac libs are already updated, Linux-users have to build
  their own ffmpeg verions until distros keep up.
2011-08-28 14:46:03 +00:00
Campbell Barton 6e39d908a9 quiet compiler warnings for -Wundef 2011-05-22 04:25:31 +00:00
Nathan Letwory 192ab99b5c doxygen: blender/imbuf tagged. 2011-02-27 20:23:21 +00:00
Nathan Letwory 5b607701a7 doxygen: prevent GPL license block from being parsed as doxygen comment. 2011-02-23 10:52:22 +00:00