5

There are many audio and video players but I prefer to use one tool for many purposes. And so I thought of using ffplay as both audio and video player.

To play a file the command is like this.

ffplay path_to_audio_file.mp3

Fine, but how do I play a list of audio files or a list of videos?

I tried to use:

ffplay *.mp3

but to no avail. It gives me the following error:

Argument 'audiofileB.mp3'  provided as input filename, but 'audiofileA.mp3' was already specified.

4 Answers 4

7

ffplay appears to only support a single input file, so you'll need to use code to loop over a list of input files (and possibly to shuffle them); wildly assuming coreutils (for shuf), perhaps something like:

find musicdir -type f -name "*.mp3" | shuf | while read f; do ffplay -autoexit -- "$f"; done

This will of course break horribly if there are spaces or newlines in the filenames.

(My current music player is fairly similar, find ~/music -type f -name "*.mp3" | mpg123 --shuffle -Z --list -)

3
  • I tried you solution and it's almost good, but ... there are some problems related to ffplay which I'm not sure if they should be resolved in this question or in another. one of problems is that ffplay will not end playing current song and for this reason will not go to the next song at the end of current untill I will not use CTRL+c keyboard combination.
    – Scantlight
    Apr 11, 2016 at 21:29
  • 1
    @Scantlight the -autoexit flag seems relevant to that issue.
    – thrig
    Apr 11, 2016 at 23:33
  • 1
    -autoexit solved that issue. Now I have another which can be solved by using -nodisp ... this will disable the visualisation of waveform and similar stuff. This will avoid to create a new window and steal focus from current working application (this was very annoying behavior). would you like to include this option in your answer, as a possible option to solve the annoying behavior.
    – Scantlight
    Apr 12, 2016 at 11:43
3

I found from this https://ubuntuforums.org/showthread.php?t=2068478

for f in *.mp3 ; do ffplay -autoexit "$f"; done
2
2

I found this thread while I was writing an FFplay GUI in Lazarus/FPC. It could already play a dropped file list and skip to next/previous file, but I had to kill the ffmpeg process and create a new one every time. I was trying to add the ability to play a whole file list. The simplest workaround I found to the moment was of course using -autoexit, and creating a playlist file with this Pascal code:

begin
      AssignFile(tfOut, C_FNAME);
      try
        rewrite(tfOut);
        for i:= 0 to Fichiers.Items.Count - 1 do
        if Fichiers.Selected[i] then
        begin
          writeln(tfOut, 'file ' + #39 + conv(Fichiers.Items[i]) + #39)
        end;
        CloseFile(tfOut);
      except
        on E: EInOutError do
        ShowMessage ('File error')
      end;
  end;

Then reading it this way:

'ffplay -f concat -safe 0 -i flist.txt -autoexit'

which is the same syntax I use for concatenating files with FFMPeg.

I'm now searching for a proper way to add a delay if files are image files…

1

ffplay can use the concat demuxer similar to ffmpeg.

Create a file that lists up the files you want to play:

# list.txt
file 'audiofileA.mp3'
file 'audiofileB.mp3'

Then run ffplay:

ffplay -f concat -i list.txt

Other useful options:

  • Use -autoexit to make it exit when it's done
  • Use -loop 0 to loop forever (press q to quit).
  • Use -safe 0 if the file paths are absolute (or contain other special characters).

See the ffmpeg wiki about concat demuxer for more details.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .