0

When I run the following code, that is supposed to print out the filename and redirect ffmpeg's stderr information to stdout:

#!/bin/bash

while read -r filename; do
  echo $filename
  cmd_out=$(ffmpeg -i "$filename" -f null - 2>&1)
done < inputs.txt

With the following inputs.txt:

intro.mp3
silence.mp3
outro.mp3
intro2.mp3

I get

intro.mp3
ilence.mp3
outro.mp3
ntro2.mp3

Notice the first letter of the filename is missing in both the 2nd and 4th lines.

This happens only if the inputs.txt entries are existing audio files, and ffmpeg is used.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Tomasz
  • 328
  • 2
  • 10
  • 3
    if you comment out (or remove) the `cmd_out=$(...)` line (ie, leaving just the `echo`), do you get the same output? if so, might be of interest to see if `inputs.txt` contains any non-printing characters; can you update the question with the output from `od -c inputs.txt` or `xxd inputs.txt` – markp-fuso Apr 15 '23 at 14:27
  • 3
    I suspect `ffmpeg` is reading a character for some reason. Try adding ` – Barmar Apr 15 '23 at 14:49
  • 2
    See ["Strange errors when using ffmpeg in a loop"](https://unix.stackexchange.com/questions/36310/strange-errors-when-using-ffmpeg-in-a-loop) and [BashFAQ #89: "I'm reading a file line by line and running ssh or ffmpeg, only the first line gets processed!"](http://mywiki.wooledge.org/BashFAQ/089) – Gordon Davisson Apr 15 '23 at 16:18

0 Answers0