533 Commits

Author SHA1 Message Date
Josh Allmann
a53e20a334 Fix pts overflow in fps filter (#438)
This was causing some very large segments to be produced if the
input had some weird characteristics like missing timestamps.

Co-authored-by: Marco van Dijk <marco@stronk.rocks>
2025-09-05 08:20:32 -07:00
Brad | ad-astra
c1eefa63ff add duration check for input files (#434)
* add duration check for input file to ensure not transcoding long inputs and protect against inputs that have time stamp anomalies causing the output to be much longer than the input

---------

Co-authored-by: Josh Allmann <joshua.allmann@gmail.com>
2025-05-29 11:10:47 -05:00
hjpotter92
e1872bf609 install_ffmpeg: Fix typo when installing nasm 2025-04-18 13:48:23 +05:30
hjpotter92
9e8423c8f9 Merge pull request #433 from livepeer/hjp/replace-nasm.us 2025-04-18 13:25:25 +05:30
hjpotter92
3c88d72991 Replace videolan.org and nasm.us dependecies from install_ffmpeg.sh
We've been hit more than once because those domains were down
or SSL error or something else.
2025-04-18 11:55:30 +05:30
Rick Staa
802f960d26 docs: replace temporary Discord invite URL with permanent URL (#432)
This commit updates the Discord invite URL from a temporary (expiring)
link to a fixed (permanent) one to ensure long-term accessibility.
2025-03-15 17:09:46 +01:00
Josh Allmann
79e6dcf080 Use ffmpeg parser for H.264 (#431)
Fixes a number of things including a LPMS crash, choppy video
quality, green screens during rotation, inconsistent frame counts
vs software decoding, etc. We also apparently gained GPU
support for MPEG2 decoding.

This is a massive change: we can no longer add outputs up front
due to the ffmpeg hwaccel API, so we have to wait until we receive
a decoded video frame in order to add outputs. This also means
properly queuing up audio and draining things in the same order.
2025-01-17 17:43:04 -08:00
hjpotter92
25cbb3659a Merge pull request #430 from livepeer/hjp/gpu-workflows 2024-12-12 05:59:28 +05:30
hjpotter92
95b8bcb5d7 workflows: Use self-hosted gpu based runner 2024-12-11 19:23:08 +05:30
Josh Allmann
fc96cadb63 Fix crash on PNG options 2024-12-03 01:24:05 +00:00
Josh Allmann
b33cac634b install_ffmpeg: Add FLV muxer (#428)
This should make RTMP output work on production
(non-debug) builds of LPMS
2024-12-02 16:05:12 -08:00
Josh Allmann
c4721b87bd ffmpeg: Add demuxer options. (#426)
This adds demuxer options as a complement to the existing encoder/muxer
options which allows us to:

1. explicitly select the demuxer to use if probing doesn't return a good result

2. configure the demuxer with additional options

This has come up a few times while looking at various things so it is good to
have an API that is fully configurable out of the box.
2024-12-02 15:38:36 -08:00
Tibia2000
7b07ba3a22 Update ffmpeg.go change preset from slow to medium (#427)
Going from 2 pass encode slow preset to medium preset.
2024-11-22 15:58:37 +01:00
Rafał Leszko
ffde232753 Fix cross-compilation by compiling zlib from source (#425) 2024-10-17 09:27:16 +02:00
Josh Allmann
fe5aff1fa6 ffmpeg: Add a metadata option to each output (#421)
This will allow us to identify the software version and
who transcoded a given segment.
2024-09-09 10:10:57 -07:00
Josh Allmann
f87352959b ffmpeg: Clamp resolutions in filter expression (#417)
This allows the transcoded resolution to be re-clamped
correctly if the input resolution changes mid-segment.

As a result, we no longer need to do this clamping in golang.

Additionally, make the behavior between GPU and CPU more consistent
by applying nvidia codec limits and clamping CPU transcodes.
2024-08-19 11:04:16 -07:00
Josh Allmann
9d6ea5f718 Plug memory leak when printing filter graph. (#419) 2024-08-19 10:42:34 -07:00
Josh Allmann
20131b673f Fix CUVID crash on resolution change (#418)
Also adds a bunch of other changes necessary to better support
mid-stream resolution changes.

Unfortunately with CUVID there still seems to be a brief flash of
green (looks to be the length of the decoder's internal frame buffer)
but we can tackle that separately. This PR simply makes the transcoder

1. not crash, and
2. correctly encode mid-stream rotations, including with CPUs
2024-08-19 10:36:37 -07:00
Josh Allmann
0e6fd2e7e2 ffmpeg: Add tests for rotation. 2024-08-19 17:18:56 +00:00
Josh Allmann
def71fab18 ffmpeg: Handle EAGAIN from decoder and drain
This usually happens with CUVID if the decoder needs to be reset
internally for whatever reason, such as a mid-stream resolution
change.

Also block demuxing until decoder is ready to receive packets again.
2024-08-19 17:18:10 +00:00
Josh Allmann
f03385968e ffmpeg: Reset the flush packet after each keyframe.
This handles cases where the packet may contain a frame
that triggers a decoder reset - we do not want to cause
a reset during the flushing process.
2024-08-19 17:18:10 +00:00
Josh Allmann
808675b414 ffmpeg: Re-init encoder on resolution change. 2024-08-19 17:18:10 +00:00
Josh Allmann
be728e92af ffmpeg: Flush filters before re-initialization.
Also add another condition for re-initialization: if the
input resolution changes. This triggers the filter graph
to re-build and adjust to the new resolution, when CPU
encoders are in use.
2024-08-19 17:18:10 +00:00
Josh Allmann
b5181eb92c ffmpeg: Rescale DTS better during FPS passthrough (#416)
This mostly ensures that non-B frames have the same dts/pts.

The PTS/DTS from the encoder can be "squashed" a bit during rescaling
back to the source timebase if it is used directly, due to the lower
resolution of the encoder timebase. We avoid this problem with the
PTS in in FPS passthrough mode by reusing the source pts, but only
rescale the encoder-provided DTS back to the source timebase for some
semblance of timestamp consistency. Because the DTS values are
squashed, they can differ from the PTS even with non-B frames.

The DTS values are still monotonic, so the exact numbers are not really
important. However, some tools use `dts == pts` as a heuristic to check
for B-frames ... so help them out to avoid spurious B-frame detections.

To fix the DTS/PTS mismatch, take the difference between the
encoder-provided dts/pts, rescale that difference back to the source
time base, and re-calculate the dts using the source pts.

Also see https://github.com/livepeer/lpms/pull/405
2024-08-12 10:36:42 +01:00
Josh Allmann
c3330413a4 ffmpeg: Estimate duration for some audio formats in GetCodecInfoBytes 2024-08-09 12:43:42 -07:00
Elite Encoder
e67ff9f4ee Add media duration to lpms_get_codec_info for GetCodecInfo (#407)
* add fps and duration to GetCodecInfo
2024-08-09 12:43:42 -07:00
Yondon Fu
46dd338141 ffmpeg: Support image2 demuxer 2024-08-09 12:43:42 -07:00
Yondon Fu
d5161b8104 ffmpeg: Use helper to check for video metadata 2024-08-09 12:43:42 -07:00
Josh Allmann
bd7f8b0760 install_ffmpeg: Compile in more stuff for AI 2024-08-09 12:43:42 -07:00
Rick Staa
a50164a87b docs: improve test instructions (#412)
This commit ensures that people are aware that they need to add the
compiled vrsion of ffmpeg to the PATH to be able to run the tests.
2024-07-26 22:06:52 +02:00
Rick Staa
409f6e0d87 Merge pull request #411 from livepeer/improve_docs
docs: update README with extra dev info
2024-07-25 19:15:33 +02:00
kevincatty
4b092b8fc6 chore: fix some typos in comment (#397)
Signed-off-by: kevincatty <zhanshanmao@outlook.com>
2024-07-25 09:27:29 -07:00
Chase Media
5d250f1833 Fixed typo in vidplayer logging (#390) 2024-07-25 09:26:40 -07:00
Josh Allmann
956ccf4d08 Fix typo in params field (#409) 2024-07-25 09:08:51 -07:00
Josh Allmann
144a983869 Remove unused transcoder2 (#410) 2024-07-25 09:08:29 -07:00
Rick Staa
24ce26985c docs: update README with extra dev info
This commit ensure that developers are aware of the extra build flags
they have to run when installing ffmpeg for the tests to be succesfull.
It also cleans up the README a bit.
2024-07-25 16:11:41 +02:00
Josh Allmann
d9c78b62ef Update FFmpeg to 7.0.1 (#406)
* Port install_ffmpeg.sh from go-livepeer

* Update ffmpeg and nv-codec-headers versions.

* Use local install_ffmpeg.sh in github CI

* Update transcoder for ffmpeg 7.0.1

* Update tests to be compatible with ffmpeg7 binary

* Fix FPS passthrough

* Set the encoder timebase using AVCodecContext.framerate instead of
  the decoder's AVCodecContext.time_base.

  The use of AVCodecContext.time_base is deprecated for decoding.
  See https://ffmpeg.org/doxygen/3.3/structAVCodecContext.html#ab7bfeb9fa5840aac090e2b0bd0ef7589

* Adjust the packet timebase as necessary for FPS pass through
  to match the encoder's expected timebase. For filtergraphs using
  FPS adjustment, the filtergraph output timebase will match the
  framerate (1 / framerate) and the encoder is configured for the same.

  However, for FPS pass through, the filtergraph's output timebase
  will match the input timebase (since there is no FPS adjustment)
  while the encoder uses the timebase detected from the decoder's
  framerate. Since the input timebase does not typically match the FPS
  (eg 90khz for mpegts vs 30fps), we need to adjust the packet timestamps
  (in container timebase) to the encoder's expected timebase.

* For the specific case of FPS passthrough, preserve the original PTS
  as much as possible since we are trying to re-encode existing frames
  one-to-one. Use the opaque field for this, since it is already being
  populated with the original PTS to detect sentinel packets
  during flushing.

  Without this, timestamps can be slightly "squashed" down when
  rescaling output packets to the muxer's timebase, due to the loss of
  precision (eg, demuxer 90khz -> encoder 30hz -> muxer 90khz)
2024-07-10 20:45:24 -07:00
Josh Allmann
3db1a12ba0 Update nvidia tests to pass with VFR changes.
The nvidia test suite was never run after #393 so this breakage
was not noticed.
2024-07-10 12:39:33 -07:00
Thom Shutt
343a3ddb37 Add an error return to makeStreamID to make issues explicit (#400)
* Add an error return to makeStreamID to make issues explicit

* Reinstate nil check
2024-05-28 08:02:57 +01:00
Josh Allmann
11a5584d69 Improve VFR support (#393)
* Improve VFR support.

Manually calculate the duration of each frame and set
the PTS to that before submitting to the filtergraph.

This allows us to better support variable frame rates,
and is also better aligned with how ffmpeg does it.

This may change the number of frames output by the FPS
filter by +/- 1 frame. These aren't issues in themselves
but breaks a lot of test cases which will need to be updated.

* Update test cases for VFR.
2024-05-13 18:15:33 +02:00
dependabot[bot]
ced71c476b Bump actions/cache from 3 to 4 (#379)
Bumps [actions/cache](https://github.com/actions/cache) from 3 to 4.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-02 11:11:53 +01:00
dependabot[bot]
81a482d195 Bump codecov/codecov-action from 3 to 4 (#385)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3 to 4.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-08 13:10:59 +00:00
dependabot[bot]
e64ec3b65a Bump github.com/golang/protobuf from 1.5.2 to 1.5.4 (#389)
Bumps [github.com/golang/protobuf](https://github.com/golang/protobuf) from 1.5.2 to 1.5.4.
- [Release notes](https://github.com/golang/protobuf/releases)
- [Commits](https://github.com/golang/protobuf/compare/v1.5.2...v1.5.4)

---
updated-dependencies:
- dependency-name: github.com/golang/protobuf
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-08 13:10:18 +00:00
hjpotter92
9b5baef308 Merge pull request #378 from livepeer/hjp/ci-runner 2024-01-22 16:09:09 +05:30
hjpotter92
684658a38b Skip testing stage which requires a GPU. 2024-01-20 10:12:55 +05:30
hjpotter92
c03d27c0d0 build.yaml: Revert debugging changes 2024-01-18 19:14:03 +05:30
hjpotter92
058346e313 build.yaml: Debugging paths 2024-01-18 19:01:20 +05:30
hjpotter92
18b8f0dde8 build.yaml: Use nvidia cuda devel image. 2024-01-18 18:07:46 +05:30
hjpotter92
bd0dff02f8 Rename workflow file 2024-01-18 15:58:25 +05:30
hjpotter92
3e862935aa workflows: Try to get lpms builds in line with go-livepeer builds 2024-01-18 15:57:24 +05:30