Skip to content

Commit

Permalink
feat: remove MP4 stuff
Browse files Browse the repository at this point in the history
No need to occupy more disk spaces or spend more time to just change the
  container of video files.
  • Loading branch information
pzhlkj6612 committed May 18, 2024
1 parent bc627b8 commit add431b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 53 deletions.
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@
## What does this docker image do

- Download the live streaming or VOD from [eplus - Japan most famous ticket play-guide](https://ib.eplus.jp/) via Streamlink or yt-dlp.
- Transcode the downloaded TS file to MP4 via FFmpeg.
- Upload both the TS and MP4 files to S3-compatible object storage via S3cmd or to Azure Storage container via Azure CLI.
- Download the live streaming or VOD from [eplus](https://ib.eplus.jp/) and other websites via Streamlink or yt-dlp.
- Upload the video file to S3-compatible object storage via S3cmd or to Azure Storage container via Azure CLI.

## Details

### Storage requirement

For a 4-hour live event, the size of a MPEG-TS recording with the best quality is about 9.88 GB (9.2 GiB). Since we may transcode MPEG-TS to MP4 (a bit smaller) and keep both files, 20 GB free disk space is required.
For a 4-hour live event, the size of a MPEG-TS recording with the best quality is about 9.88 GB (9.2 GiB).

### Downloader support

The yt-dlp support is experiment.

### Output

All output files are located in the "/SL-downloads" directory in the container. You are able to access those files locally by mounting a volume into that directory **before** creating the container (otherwise you may have to play with anonymous volumes).
The output file is in ".ts" format. I believe that your media player is smart enough to get to know the actual codec.

The file is located in the "/SL-downloads" directory in the container. You are able to access those files by mounting a volume into that directory **before** creating the container (otherwise you may have to play with [`docker cp`](https://docs.docker.com/reference/cli/docker/container/cp/) or anonymous volumes).

Intermediate files. Those files will be renamed to "final files" before being uploaded:
You will see some intermediate files. Those files will be renamed to "final files" finally:

```shell
# template:
${datetime}.${OUTPUT_FILENAME_BASE}.{ts,mp4} # full
${OUTPUT_FILENAME_BASE}.{ts,mp4} # NO_AUTO_PREFIX_DATETIME
${datetime}.${OUTPUT_FILENAME_BASE}.ts # full
${OUTPUT_FILENAME_BASE}.ts # NO_AUTO_PREFIX_DATETIME

# example:
'20220605T040302Z.name-1st-Otoyk-day0.ts' # full
Expand All @@ -35,10 +40,10 @@ Final files:

```shell
# template:
${datetime}.${OUTPUT_FILENAME_BASE}.${size}.${md5}.{ts,mp4} # full
${OUTPUT_FILENAME_BASE}.${size}.${md5}.{ts,mp4} # NO_AUTO_PREFIX_DATETIME
${datetime}.${OUTPUT_FILENAME_BASE}.${md5}.{ts,mp4} # NO_AUTO_FILESIZE
${datetime}.${OUTPUT_FILENAME_BASE}.${size}.{ts,mp4} # NO_AUTO_MD5
${datetime}.${OUTPUT_FILENAME_BASE}.${size}.${md5}.ts # full
${OUTPUT_FILENAME_BASE}.${size}.${md5}.ts # NO_AUTO_PREFIX_DATETIME
${datetime}.${OUTPUT_FILENAME_BASE}.${md5}.ts # NO_AUTO_FILESIZE
${datetime}.${OUTPUT_FILENAME_BASE}.${size}.ts # NO_AUTO_MD5

# example:
'20220605T040302Z.name-1st-Otoyk-day0.123456789.0123456789abcdef0123456789abcdef.ts' # full
Expand Down Expand Up @@ -183,12 +188,6 @@ services:
- RTMP_FFMPEG_USE_LIBX264_ENCODING= # enable video encoding, otherwise just copy the video stream.
- RTMP_FFMPEG_CRF= # CRF value, 23 by detault, see https://trac.ffmpeg.org/wiki/Encode/H.264#a1.ChooseaCRFvalue .

# MP4 output control

- NO_TRANSCODE= # disable FFmpeg transcode.

- GENERATE_DUMMY_MP4= # generate a dummy MP4 file when "NO_TRANSCODE" is set.

# uploading control

- ENABLE_S3= # enable s3cmd.
Expand Down
36 changes: 1 addition & 35 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ ffmpeg_stdin_stream_transcode_flv_rtmp_no_target_url_partial_command=(

#
# $1: output_ts_base_path
# $2: output_mp4_base_path
#
function process_stream_and_video() {
echo '------ vvvvvv process stream and video vvvvvv'
Expand Down Expand Up @@ -304,35 +303,6 @@ function process_stream_and_video() {
exit 5
fi

# Produce MP4

if [[ -z "${NO_TRANSCODE}" ]]; then
# (.ts)-> ffmpeg ->(.mp4)
# should be a seekable MP4 video

ffmpeg_video_file_copy_mp4_file_command=(
'ffmpeg'
"${ffmpeg_common_global_arguments[@]}"
'-i' "${1}"
'-c' 'copy'
'-f' 'mp4'
"${2}"
)

"${ffmpeg_video_file_copy_mp4_file_command[@]}"

elif [[ -n "${GENERATE_DUMMY_MP4}" ]]; then
# text ->(.mp4)

if [[ -f "${2}" ]]; then
echo "MP4 file exists, no overwriting it."
exit 4
fi

echo "${2}" 1>"${2}"

fi

echo '------ ^^^^^^ process stream and video ^^^^^^'
}

Expand Down Expand Up @@ -505,8 +475,6 @@ function main() {
# It could be a MKV. PLease believe our media player.
output_ts_base_path="/SL-downloads/${output_file_basename}.ts"

output_mp4_base_path="/SL-downloads/${output_file_basename}.mp4"

if [[ -n "${ENABLE_S3}" ]]; then
init_s3
fi
Expand All @@ -515,11 +483,9 @@ function main() {
init_azure
fi

process_stream_and_video "${output_ts_base_path}" "${output_mp4_base_path}"
process_stream_and_video "${output_ts_base_path}"

obtain_calculate_rename_upload "${output_ts_base_path}"

obtain_calculate_rename_upload "${output_mp4_base_path}"
}

# ENTRYPOINT #
Expand Down

0 comments on commit add431b

Please sign in to comment.