Last active
October 25, 2025 22:37
-
-
Save gordielachance/7a5f3690e4e1e598c5c5c4edb67ab03e to your computer and use it in GitHub Desktop.
After Effects script that exports the active comp markers to a chapters file for FFMpeg.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ================================ | |
| // Export AE markers to FFmpeg chapters (UTF-8 safe, FFmpeg compatible) | |
| // Usage: ffmpeg -i input.mp4 -i chapters.txt -map_metadata 1 -c copy output.mkv | |
| // ================================ | |
| { | |
| // Check active comp | |
| var comp = app.project.activeItem; | |
| if (!(comp instanceof CompItem)) { | |
| alert("Select a comp that has markers."); | |
| } else { | |
| var markers = comp.markerProperty; | |
| var numMarkers = markers.numKeys; | |
| if (numMarkers === 0) { | |
| alert("No markers found in that comp!"); | |
| } else { | |
| var durationMS = Math.round(comp.duration * 1000); | |
| var output = ";FFMETADATA1\n"; // pas de BOM | |
| for (var i = 1; i <= numMarkers; i++) { | |
| var startMS = Math.round(markers.keyTime(i) * 1000); | |
| var endMS = (i < numMarkers) ? Math.round(markers.keyTime(i + 1) * 1000) : durationMS; | |
| // Get marker comment | |
| var markerComment = markers.keyValue(i).comment; | |
| var title = markerComment && markerComment.length > 0 ? markerComment : "Chapter " + i; | |
| // Clean title | |
| title = title.replace(/^\s+|\s+$/g, ''); | |
| output += "[CHAPTER]\n"; | |
| output += "TIMEBASE=1/1000\n"; | |
| output += "START=" + startMS + "\n"; | |
| output += "END=" + endMS + "\n"; | |
| output += "title=" + title + "\n"; | |
| } | |
| // Save dialog | |
| var file = File.saveDialog("Save the FFmpeg chapters file", "*.txt"); | |
| if (file) { | |
| if (file.name.indexOf(".") === -1) { | |
| file = new File(file.fsName + ".txt"); | |
| } | |
| // UTF-8 without BOM | |
| file.encoding = "UTF-8"; | |
| file.lineFeed = "Unix"; // force LF (\n) | |
| file.open("w"); | |
| file.write(output); | |
| file.close(); | |
| alert("Export done!\nFile: " + file.fsName); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment