1

If I have a path with dots in the path, for instance:

/home/user/Documents/hello/test.testing_23-24.123/test.testing_23-24.124

ffmpeg can locate the file if you pass the file's path as an argument but it will truncate the path name to the first dot it encounters in the file's path when it outputs the file.

For instance, I got this:

#!/bin/sh
src_folder=`pwd`

for filename in "${src_folder}"/*.MP4
  do
    ffmpeg -threads 0 -probesize 100M -analyzeduration 100M -i "${filename}" \
      -c:v libx265 -preset medium -pass 1 -tune grain -x265-params "crf=28:pmode=yes" \
      -c:a libmp3lame -q:a 9 -strict experimental "${filename%%.*}"_1stpass.mkv
  done

The output states:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/user/Documents/hello/test.testing_23-24.123/test.testing_23-24.124/GOPR2103.MP4':

[..]

Output #0, matroska, to '/home/user/Documents/hello/test_hevc.mkv':

We see that the output file's folder path below:

 /home/user/Documents/hello/test.testing_23-24.123/test.testing_23-24.124

Gets truncated after ffmpeg encounters the first dot in it's output path. This only happens to the output's filename. Also it uses the truncated path as the filename.

Anyone that could point me in the right direction on how to solve this?

PS: I am aware that a bad workaround should be avoiding folders with dots :]

slm
  • 363,520
  • 117
  • 767
  • 871
  • 2
    The shell is doing this, not ffmpeg. ffmpeg is not evaluating `"${filename%%.*}"`. I think you need to remove one % to trim out the shortest suffix segment. – Gyan Jul 27 '18 at 20:19
  • Hi, I did intentionally use the double %% for unnecessary reasons. Thank you so much for the help. I made the changes you suggested together with [gyan](https://unix.stackexchange.com/users/219759/gyan)'s suggestion and it doesn't truncate the path anymore. – sternumbeef Jul 29 '18 at 14:18
  • If the answer below solved your problem, please [accept it](https://unix.stackexchange.com/help/someone-answers) by clicking the checkmark next to it. Thank you! – Jeff Schaller Aug 13 '18 at 10:50

1 Answers1

1

As Gyan pointed out in a comment, you've (unintentionally?) told the shell to strip as many characters as it can from the end of the file path until it finds the first dot/period; that's the meaning of %% followed by .*. You might have intended to strip off the "extension" of the filename (such as MP4), in which case you'd want to use a single %, which says to match the shortest number of characters.

Since you know that you're picking up MP4 files, you can further simplify the % expansion and simply ask it directly to strip off those 4 characters.

It's also a little pointless to expand pwd when the only thing you need it for is to gather filenames in the current directory.

Use something more like this:

for filename in ./*.MP4
  do
    ffmpeg -threads 0 -probesize 100M -analyzeduration 100M \
      -i "${filename}" \
      -c:v libx265 -preset medium -pass 1 -tune grain -x265-params \
      "crf=28:pmode=yes" -c:a libmp3lame -q:a 9 -strict experimental \
      "${filename%.MP4}"_1stpass.mkv
  done
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250