Javicle - a JSON Video Composition Language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.5 KiB

  1. #!/bin/bash
  2. #
  3. # Concatenate media files
  4. #
  5. # Usage:
  6. #
  7. # jconcat [-n|--no-exec] out-file in-file-1 [in-file-2 ...]
  8. #
  9. # -n or --no-exec : if set, do not execute ffmpeg but print what would have run
  10. # out-file : output file
  11. # in-file-N : input files
  12. #
  13. # BEWARE SHELL WILDCARDS!
  14. # Shell wildcards will match files in non-deterministic order, meaning that
  15. # your combined file will be assembled out of order.
  16. #
  17. # If you are combining files that were split with `jvc` (or `jsplit`), then
  18. # sorting them by time (oldest first) is sufficient.
  19. #
  20. # For example, do this:
  21. #
  22. # jconcat combined-file.mp4 $(ls -1tr path/to/parts*.mp4)
  23. #
  24. # NOT THIS:
  25. #
  26. # jconcat combined-file.mp4 path/to/parts*.mp4 # args not ordered!
  27. #
  28. SCRIPT="${0}"
  29. SCRIPT_DIR="$(cd "$(dirname "${SCRIPT}")" && pwd)"
  30. . "${SCRIPT_DIR}"/jvc_common
  31. OUT_FILE="${1?no out-file provided}"
  32. shift
  33. IN_FILE="${1?no in-file(s) provided}"
  34. echo "
  35. {
  36. \"assets\": [
  37. $(
  38. F_INDEX=0
  39. for path in "$@" ; do
  40. if [[ ${F_INDEX} -gt 0 ]] ; then
  41. echo ","
  42. fi
  43. F_INDEX=$((F_INDEX + 1))
  44. echo -n " { \"name\": \"input_${F_INDEX}\", \"path\": \"${path}\" }"
  45. shift
  46. done)
  47. ],
  48. \"operations\": [
  49. {
  50. \"operation\": \"concat\",
  51. \"creates\": {
  52. \"name\": \"combined\",
  53. \"dest\": \"${OUT_FILE}\"
  54. },
  55. \"sources\": [$(END=$#
  56. for ((i=1;i<=END;i++)); do
  57. if [[ ${i} -gt 1 ]] ; then echo -n "," ; fi
  58. echo -n "
  59. \"input_${i}\""
  60. done)
  61. ]
  62. }
  63. ]
  64. }
  65. " | "${SCRIPT_DIR}"/jvc -z ${JVC_OPTIONS}