#!/bin/bash set -euo pipefail # This script is a template. It needs to be rendered with: # - video_file: A VideoFile object from models.streams. # - output_file: The absolute path to the output file. # By default, set log level to error. LOG_FLAGS=("-loglevel" "error") # If -v or --verbose is passed as the first argument, remove the log flags # to use ffmpeg's default log level (usually 'info'). if [[ "$1" == "-v" || "$1" == "--verbose" ]]; then LOG_FLAGS=() fi ffmpeg -hide_banner "${LOG_FLAGS[@]}" -i '{{ video_file.video_path.absolute() }}' \ -map_metadata -1 \ {%- if video_file.title %} -metadata title='{{ video_file.title }}' \ {%- endif %} {%- if video_file.date_released %} -metadata date_released='{{ video_file.date_released.strftime("%Y-%m-%d") }}' \ {%- endif %} {%- if video_file.imdb %} -metadata imdb='{{ video_file.imdb }}' \ {%- endif %} {%- if video_file.original_media_type %} -metadata original_media_type='{{ video_file.original_media_type.value }}' \ {%- endif %} -pix_fmt yuv420p10le \ {%- for stream in video_file.video_streams %} -map 0:{{ stream.index }} \ -c:v libsvtav1 \ -crf {{ stream.crf }} \ -preset {{ stream.preset }} \ -svtav1-params tune=0:film-grain={{ stream.film_grain }}:scd=1 \ -vf 'bwdif=mode=0,scale=iw*sar:ih,setsar=1,scale=-2:ih:lanczos' \ -g {{ (stream.fps | round * 5) | int }} \ {%- endfor %} {%- for stream in video_file.audio_streams %} -map 0:{{ stream.index }} -c:a:{{ loop.index0 }} libopus \ {%- if 'side' in stream.channel_layout %} -filter:a:{{ loop.index0 }} 'channelmap=channel_layout=5.1' \ {%- endif %} {%- if stream.tags and stream.tags.language %} -metadata:s:a:{{ loop.index0 }} language={{ stream.tags.language }} \ {%- endif %} {%- if stream.tags and stream.tags.title %} -metadata:s:a:{{ loop.index0 }} title='{{ stream.tags.title }}' \ {%- endif %} {%- if stream.disposition.default %} -disposition:a:{{ loop.index0 }} default \ {%- endif %} {%- endfor %} {%- if video_file.allow_subtitle %} {%- for stream in video_file.subtitle_streams %} -map 0:{{ stream.index }} -c:s:{{ loop.index0 }} copy \ {%- if stream.tags and stream.tags.language %} -metadata:s:s:{{ loop.index0 }} language={{ stream.tags.language }} \ {%- endif %} {%- endfor %} {%- endif %} '{{ output_file }}'