Recherche avancée
Médias (11)
-
Stereo master soundtrack
17 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Audio
-
Elephants Dream - Cover of the soundtrack
17 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Image
-
#7 Ambience
16 octobre 2011, par
Mis à jour : Juin 2015
Langue : English
Type : Audio
-
#6 Teaser Music
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#5 End Title
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#3 The Safest Place
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
Sur d’autres sites (112)
-
Anomalie #1970 (Fermé) : Pas de crochets dans le HTML !
26 mars 2011, par cedric -corrigé par r17527
-
Revision 34267 : {{{ #DATE_DEBUT }}} dans les forums, c’est le 1er janvier 1970, ce qui ne ...
7 janvier 2010, par fil@… — Log#DATE_DEBUT dans les forums, c’est le 1er janvier 1970, ce qui ne m’arrange pas car je n’etais pas encore ne
-
How can I add chapters to a mp4 file using bash script and ffmpeg
17 septembre 2023, par Rick TI'm trying to add chapters to an mp4 file using bash and ffmpeg. The chapters are located in a file called
chapters.txt
. When the bash script is run which is calledadd_chapters.sh
it reads thechapters.txt
file and creates a file calledchapters.ffmetadata
. The issue is that theSTART
andEND
times in the filechapters.ffmetadata
aren't being created correctly. How can I fix this ?

- 

-
I have a file called
chapters.txt
that has the chapters in it.

00:00:00=Intro
00:02:12=What are selections
00:03:19=Booleans



-
The bash file I run is
add_chapters.sh


The code in it is :


#!/bin/bash

input_file="chapters.txt"
output_file="chapters.ffmetadata"

# Create the FFmetadata chapter file
echo ";FFMETADATA1" > "$output_file"

previous_seconds=0

while IFS="=" read -r timestamp chapter_name; do
 # Convert start time to seconds
 seconds=$(date -u -d "1970-01-01 $timestamp" +"%s")

 # Calculate the end time (previous chapter's start time)
 end_seconds=$previous_seconds

 # Update previous_seconds for the next iteration
 previous_seconds=$seconds

 echo "[CHAPTER]" >> "$output_file"
 echo "TIMEBASE=1/1000" >> "$output_file"
 echo "START=${end_seconds}000" >> "$output_file"
 echo "END=${seconds}000" >> "$output_file"
 echo "title=$chapter_name" >> "$output_file"
done < "$input_file"

echo "Chapter file '$output_file' created successfully."

# Run FFmpeg to add chapters to the video
ffmpeg -i input_video.mp4 -i chapters.ffmetadata -map_metadata 1 -c:v copy -c:a copy -y output_video.mp4



-
It creates a file called
chapters.ffmetadata


;FFMETADATA1
[CHAPTER]
TIMEBASE=1/1000
START=0000
END=0000
title=Intro
[CHAPTER]
TIMEBASE=1/1000
START=0000
END=132000
title=What are selections
[CHAPTER]
TIMEBASE=1/1000
START=132000
END=199000
title=Booleans
[CHAPTER]
TIMEBASE=1/1000
START=199000
END=0000
title=



The
START
andEND
times aren't being calculated correctly. How can I fix this ?










UPDATE #1


I'm almost there thanks to @Freeman code / answer.


The issues in the generated

chapters.ffmetadata
file are just.

- 

-
The first
START=
andEND=
are0000


-
The Intro Chapter doesn't show up (most likely caused by the first
START=
andEND=
being0000
)

-
The Chapters seem to be shifted down by one timecode line (most likely caused by the first
START=
andEND=
being0000
)

;FFMETADATA1
[CHAPTER]
TIMEBASE=1/1000
START=0000
END=0000
title=Intro
[CHAPTER]
TIMEBASE=1/1000
START=0000
END=132000
title=What are selections ?
[CHAPTER]
TIMEBASE=1/1000
START=132000
END=199000
title=Booleans
[CHAPTER]
TIMEBASE=1/1000
START=199000
END=0000
title=
[CHAPTER]
TIMEBASE=1/1000
START=0000
END=4459000
title=











UPDATE #2


Strange ; I tried the changes @Freeman suggested but an error comes up now.


Chapter end time 0 before start 199000
chapters.ffmetadata : Cannot allocate memory


;FFMETADATA1
[CHAPTER]
TIMEBASE=1/1000
START=0000
END=0000
title=Intro
[CHAPTER]
TIMEBASE=1/1000
START=0000
END=132000
title=What are selections?
[CHAPTER]
TIMEBASE=1/1000
START=132000
END=199000
title=Booleans
[CHAPTER]
TIMEBASE=1/1000
START=199000
END=0000
title=
[CHAPTER]
TIMEBASE=1/1000
START=0000
END=4459000
title=




UPDATE #3 using his awk changes


;FFMETADATA1
[CHAPTER]
TIMEBASE=1/1000
START=0000
END=0000
title=Intro
[CHAPTER]
TIMEBASE=1/1000
START=0000
END=132000
title=What are selections?
[CHAPTER]
TIMEBASE=1/1000
START=132000
END=199000
title=Booleans
[CHAPTER]
TIMEBASE=1/1000
START=199000
END=0000
title=



-