← back to Goodquestion Ai

video-html/assemble-concat.sh

44 lines

#!/bin/bash
# assemble-concat.sh — Concatenate multiple video segments into one
#
# Usage:
#   ./assemble-concat.sh <segments-list.txt> <output.mp4>
#
# segments-list.txt is a file with lines like:
#   file '/path/to/segment-01.mp4'
#   file '/path/to/segment-02.mp4'

set -euo pipefail

if [ $# -lt 2 ]; then
  echo "Usage: $0 <segments-list.txt> <output.mp4>"
  exit 1
fi

LIST="$1"
OUTPUT="$2"

if [ ! -f "$LIST" ]; then
  echo "Error: Segments list not found: $LIST"
  exit 1
fi

OUTPUT_DIR=$(dirname "$OUTPUT")
mkdir -p "$OUTPUT_DIR"

echo "Concatenating segments..."
cat "$LIST"
echo ""

ffmpeg -y \
  -f concat \
  -safe 0 \
  -i "$LIST" \
  -c copy \
  -movflags +faststart \
  "$OUTPUT"

echo ""
echo "Done! Output: $OUTPUT"
echo "Size: $(du -h "$OUTPUT" | cut -f1)"