To convert an MP4 video with an SRT subtitle file to an M3U8 format with a maximum file size of 5MB using FFmpeg, you can follow these steps:

  1. Install FFmpeg on your computer if you haven't already. You can download it from the official website (https://ffmpeg.org/) or use package managers like Homebrew (for macOS) or apt (for Linux).

  2. Create a text file named input.txt and list all the MP4 filenames (each on a new line) with their corresponding SRT subtitle filenames. For example:

input1.mp4 input1.srt
input2.mp4 input2.srt
  1. Create a script file (e.g., convert.sh) and add the following code:
#!/bin/bash

while read -r line; do
  input=$(echo "$line" | awk '{print $1}')
  subtitle=$(echo "$line" | awk '{print $2}')
  output=$(echo "$input" | cut -d'.' -f1).m3u8

  ffmpeg -i "$input" -vf "subtitles=$subtitle" -c:v libx264 -preset ultrafast -c:a aac -hls_time 10 -hls_list_size 0 -hls_segment_filename "$output-%03d.ts" "$output"

  # Split the resulting M3U8 file into multiple segments if the size exceeds 5MB
  split -b 5M "$output" "$output-segment-"
  rm "$output"
done < input.txt
  1. Save the script file and make it executable by running the following command in the terminal:
chmod +x convert.sh
  1. Run the script by executing ./convert.sh in the terminal. FFmpeg will convert each MP4 file with its respective SRT subtitle file to an M3U8 format. If the resulting M3U8 file size exceeds 5MB, it will be split into multiple segments.

Note: Make sure to place all the MP4 files and their corresponding SRT subtitle files in the same directory as the script file and the input.txt file. Adjust the script if your file naming or directory structure is different

how to ffmpeg auto transfer from mp4 with srt file subtitle to m3u8 each file no more than 5mb

原文地址: https://www.cveoy.top/t/topic/hJBz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录