Skip to content

Commit

Permalink
Merge pull request #128 from AllenNeuralDynamics/fix-ffmpeg-gray-conv…
Browse files Browse the repository at this point in the history
…ersion

Change gray online encoding string again
  • Loading branch information
bruno-f-cruz authored Nov 20, 2024
2 parents ea23a30 + 066a8e2 commit 60638c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions docs/articles/data_formats/video.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,23 @@ or
- Acquire without any gamma correction
- Use ``ffmpeg`` with the following encoding codec string for online encoding (optimized for compression quality and speed):

Note: this has been tested with monochrome videos with the raw pixel format
``gray``. For color videos, the input arguments might need to be altered to
match the color space of the input.

- output arguments: ``-vf "scale=out_color_matrix=bt709:out_range=full" -c:v h264_nvenc -pix_fmt nv12 -color_range full -colorspace bt709 -color_trc linear -tune hq -preset p4 -rc vbr -cq 12 -b:v 0M -metadata author="Allen Institute for Neural Dynamics" -maxrate 700M -bufsize 350M``
.. note::
This pipeline has been designed and tested with monochrome videos with the raw pixel format ``gray``. For color videos, the arguments might need to be altered to match the color space of the input.

- output arguments: ``-vf "scale=out_color_matrix=bt709:out_range=full,format=bgr24,scale=out_range=full" -c:v h264_nvenc -pix_fmt yuv420p -color_range full -colorspace bt709 -color_trc linear -tune hq -preset p4 -rc vbr -cq 12 -b:v 0M -metadata author="Allen Institute for Neural Dynamics" -maxrate 700M -bufsize 350M``
- input_arguments: ``-colorspace bt709 -color_primaries bt709 -color_range full -color_trc linear``

and the following encoding codec string for offline re-encoding (optimized for quality and size):

- output arguments: ``-vf "scale=out_color_matrix=bt709:out_range=full:sws_dither=none,format=yuv420p10le,colorspace=ispace=bt709:all=bt709:dither=none,scale=out_range=tv:sws_dither=none,format=yuv420p" -c:v libx264 -preset veryslow -crf 18 -pix_fmt yuv420p -metadata author="Allen Institute for Neural Dynamics" -movflags +faststart+write_colr``

.. warning::

For higher bit depth (more than 8 bit) recordings, change the output arguments of the online, first stage, encoding to be as follows:
- output arguments: ``-vf "scale=out_color_matrix=bt709:out_range=full,format=rgb48le,scale=out_range=full" -c:v h264_nvenc -pix_fmt yuv420p -color_range full -colorspace bt709 -color_trc linear -tune hq -preset p4 -rc vbr -cq 12 -b:v 0M -metadata author="Allen Institute for Neural Dynamics" -maxrate 700M -bufsize 350M``

This is almost the same, except the intermediate color representation is 48 bits per pixel instead of 24.

Application notes
#####################

Expand Down
4 changes: 2 additions & 2 deletions src/aind_behavior_services/rig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class VideoWriterFfmpeg(BaseModel):
frame_rate: int = Field(default=30, ge=0, description="Encoding frame rate")
container_extension: str = Field(default="mp4", description="Container extension")
output_arguments: str = Field(
default='-vf "scale=out_color_matrix=bt709:out_range=full" -c:v h264_nvenc -pix_fmt nv12 -color_range full -colorspace bt709 -color_trc linear -tune hq -preset p4 -rc vbr -cq 12 -b:v 0M -metadata author="Allen Institute for Neural Dynamics" -maxrate 700M -bufsize 350M', # E501
default='-vf "scale=out_color_matrix=bt709:out_range=full,format=bgr24,scale=out_range=full" -c:v h264_nvenc -pix_fmt yuv420p -color_range full -colorspace bt709 -color_trc linear -tune hq -preset p4 -rc vbr -cq 12 -b:v 0M -metadata author="Allen Institute for Neural Dynamics" -maxrate 700M -bufsize 350M', # E501
description="Output arguments",
)
input_arguments: str = Field(
default="-v verbose -colorspace bt709 -color_primaries bt709 -color_range full -color_trc linear",
default="-colorspace bt709 -color_primaries bt709 -color_range full -color_trc linear",
description="Input arguments",
)

Expand Down

0 comments on commit 60638c2

Please sign in to comment.