.tc-video-custom.in 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/bin/sh
  2. usage () {
  3. cat <<EOF>&2
  4. Usage: ${0##*/} MODE
  5. This script was generated with tc-video-custom.
  6. It transcodes the embedded list of files using FFmpeg. MODE will specify what
  7. kind of output you want. Edit this file to fit your needs and learn more about
  8. FFmpeg.
  9. Modes:
  10. -f: Full video.
  11. -s: Sample of 5 minute starting at 1 minute.
  12. -S N: Sample of N minutes starting at 1 minute.
  13. EOF
  14. }
  15. SAMPLE=""
  16. OPT_PROCESS=false
  17. while getopts ":hfsS:" opt; do
  18. case $opt in
  19. h)
  20. usage
  21. exit ;;
  22. f)
  23. OPT_PROCESS=true ;;
  24. s)
  25. SAMPLE="-ss 60 -t 300"
  26. OPT_PROCESS=true ;;
  27. S)
  28. SAMPLE="-ss 60 -t $((60*$OPTARG))"
  29. OPT_PROCESS=true ;;
  30. \?)
  31. usage
  32. exit 1 ;;
  33. esac
  34. done
  35. shift $(($OPTIND - 1))
  36. if ! $OPT_PROCESS; then
  37. usage
  38. exit
  39. fi
  40. if ! command -v ffmpeg >/dev/null 2>&1; then
  41. echo >&2 "'ffmpeg' not found"
  42. exit 1
  43. fi
  44. transcode () {
  45. ## You can choose here to process all files at the same time. Useful if you
  46. ## need to remux streams or to concatenate.
  47. # ffmpeg -i ###FILELIST \
  48. ffmpeg -nostdin $SAMPLE -i "$@" \
  49. -c:v libx264 -preset slow -crf 20 \
  50. -c:a libvorbis -b:a 192k -ac 2 \
  51. -c:s copy \
  52. -dn \
  53. -map 0 \
  54. "${1%.*}-$(date '+%F-%H%M%S').mkv"
  55. }
  56. set -- ###FILENAMES
  57. ## Choose to process all files one after another.
  58. for i ; do
  59. transcode "$i"
  60. done
  61. ## Or all files at the same time. You have to change the ffmpeg input in the
  62. ## function.
  63. # transcode
  64. ################################################################################
  65. ## USE CASES
  66. ##
  67. ## Exchange stream 1 an 2 by first removing them, then reading them in the
  68. ## desired order.
  69. ##
  70. ## -map -0:1 -map -0:2 -map 0:2 -map 0:1
  71. ##
  72. ## Change audio stream 1 title and remove audio stream 2 title:
  73. ##
  74. ## -metadata:s:a:0 title="FR: OGG Stereo" -metadata:s:a:1 title=""
  75. ##
  76. ## Demux audio:
  77. ## -vn -sn -c:a copy -map 0:1
  78. ##
  79. ## Dump audio to an ogg file:
  80. ## -vn -c:a libvorbis -b:a 192k
  81. ##
  82. ## Add a delay to audio (assuming stream 0 is video and stream 1 is audio)
  83. ## -i "$1" -itsoffset 0.300 -i "$1" -map 0:0 -map 1:1
  84. ##
  85. ## Insert stream 3 from file2 between all non-audio streams and audio streams of
  86. ## file1:
  87. ## -i "file1" -i "file2" -map -0:a map 1:3 -map 0:a
  88. ##
  89. ## Concatenate files. See <https://trac.ffmpeg.org/wiki/Concatenate> for more
  90. ## details.
  91. ##
  92. ## -f concat -i list.txt -c copy out.ext
  93. ##
  94. ## with `cat list.txt`:
  95. ## file 'file1'
  96. ## file 'file2'
  97. ##
  98. ## With different codecs:
  99. ##
  100. ## -filter_complex '[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]' -map '[v]' -map '[a]'
  101. ##
  102. ################################################################################
  103. ################################################################################
  104. ## SOUND
  105. ##
  106. ## You should consider mixing down audio to 2 channels with '-ac
  107. ## 2'. This greatly reduce file size and avoid any confusion for playback, which
  108. ## is often the case when converting DTS to any other format because DTS has
  109. ## embedded channel description which is not available in other formats.
  110. ################################################################################
  111. ################################################################################
  112. ## X264 OPTIONS
  113. ##
  114. ## x264 presets (-preset <preset>).
  115. ## preset ~= speed and quality*size ~= 1/speed
  116. ## ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
  117. ## Recommended values: faster -- slow
  118. ## slow is approx. two times slower than fast, and reduces the size by approx. 10%.
  119. ##
  120. ## x264 overall quality (-crf) is a logarithmic scale.
  121. ## 18 is near perfection.
  122. ## 22 is really good compression, while a bit more blurry than the original.
  123. ## 20 is a good compromise.
  124. ##
  125. ## x264 tuning (-tune <preset>).
  126. ## Possible values: film, animation, grain, ...
  127. ## See x264 --fullhelp.
  128. ## No tuning by default.
  129. ##
  130. ## x264 options (-x264opts me=<value>).
  131. ## Possible values: hex, umh...
  132. ## me=umh is default.
  133. ################################################################################
  134. ################################################################################
  135. ## FALLACIOUS INPUT
  136. ##
  137. ## In general, FFmpeg is not so good at copying fallacious streams. Reecoding
  138. ## video and audio streams helps a lot.
  139. ##
  140. ## "Can't write packet with unknown timestamp"
  141. ## Put '-fflags genpts' before the input command.
  142. ################################################################################
  143. ################################################################################
  144. ## MISC
  145. ## To check what ffmpeg supports:
  146. ## $ ffmpeg -codecs
  147. ## $ ffmpeg -formats
  148. ##
  149. ## Useful guides:
  150. ## x264: http://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide
  151. ## ID3 details: http://en.wikipedia.org/wiki/ID3
  152. ################################################################################