ffmpeg concat doesn't work with absolute path

12

6

I need to use concat with absolute path, but it doesn't seem to work. In the doc it says it should work. Anyone have an idea how to make it work? ffmpeg Doc

It doesn't work because it seem to append the text file directory to the file path

Impossible to open 'C:/temp/ffmpeg/c:/temp/ffmpeg/01.mov'

I use Windows 7.

ffmpegTest.txt:
file 'c:/temp/ffmpeg/01.mov'
file 'c:/temp/ffmpeg/02.mov'

"Y:/Shotgun/bin/ffmpeg/bin/ffmpeg.exe" -f concat -i "C:/temp/ffmpeg/ffmpegTest.txt" -c copy "C:/temp/ffmpeg/test.mov
ffmpeg version N-58949-g0e575c2 Copyright (c) 2000-2013 the FFmpeg developers
  built on Dec  9 2013 22:06:49 with gcc 4.8.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 58.100 / 52. 58.100
  libavcodec     55. 45.100 / 55. 45.100
  libavformat    55. 22.100 / 55. 22.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     3. 92.100 /  3. 92.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
[concat @ 0000000000337920] Impossible to open 'C:/temp/ffmpeg/c:/temp/ffmpeg/01.mov'
C:/temp/ffmpeg/ffmpegTest.txt: Invalid argument

DarkPixel

Posted 2014-02-17T15:52:28.403

Reputation: 323

Answers

15

I just ran into similar error messages. I eventually figured it out. There were two issues.

Issue 1:

When doing

ffmpeg -f concat -i <path_to_text_file> ...

the path_to_text_file must use forward slashes, not backslashes, even in Windows. This rule doesn't seem to apply for the video file paths on the command line though -- only for the text file path on the command line.

Issue 2:

The paths listed within your text file are interpreted by ffmpeg as being relative to the location of your text file. (In particular, the paths listed are not relative to the current working directory.)

Thus, for example, if the video files you're trying to concatenate together are in the same directory as your text file (but different than the current working directory), then the paths listed in your text file should simply be the video file names without any preceding directories.

Hope this helps someone in the future.

walrus

Posted 2014-02-17T15:52:28.403

Reputation: 251

The paths listed within your text file are interpreted by ffmpeg as being relative to the location of your text file. There is a bug in ffmpeg under windows, which is highlighted in my answer – Leon – 2018-11-12T10:08:14.660

2

Use

ffmpeg.exe" -f concat -safe 0 -i fileWithAbsoluePaths.txt -c copy out.mov

In your case

"Y:/Shotgun/bin/ffmpeg/bin/ffmpeg.exe" -f concat -safe 0 -i "C:/temp/ffmpeg/ffmpegTest.txt" -c copy "C:/temp/ffmpeg/test.mov

The key is -safe 0. That allows you to put absolute paths in the txt file.

Eric

Posted 2014-02-17T15:52:28.403

Reputation: 131

Under windows there is a caveat that is covered in my answer: https://superuser.com/a/1374679/598963

– Leon – 2018-11-12T10:05:17.597

2

@Eric's answer provides an important instruction to allow full paths in the concat demuxer input (you must provide the -safe 0 option to ffmpeg). However, under Windows, ffmpeg's concat demuxer doesn't correctly handle absolute/full paths starting with the disk name. Though it correctly recognizes full paths in its security checks, it misinterprets such paths as relative (because they don't start with a slash) when opening the file. Since non-absolute paths are relative to the location of the concat demuxer input script, ffmpeg prepends the path of the latter to the file path. If the concat script command line argument doesn't contain any file path separators (i.e. is a just a filename) the problem is masked.

Illustration:

concat.txt:
file 'c:/videos/01.flv'
file 'c:/videos/02.flv'


ffmpeg -f concat -safe 0 -i "C:/temp/concat.txt" -c copy "C:/temp/test.flv"
...
[concat @ 0000000000abcdef] Impossible to open 'C:/temp/c:/videos/01.flv'
C:/temp/concat.txt: Invalid argument


cd C:\temp
ffmpeg -f concat -safe 0 -i "./concat.txt" -c copy "C:/temp/test.flv"
...
[concat @ 0000000000abcdef] Impossible to open './c:/videos/01.flv'
./concat.txt: Invalid argument


ffmpeg -f concat -safe 0 -i "concat.txt" -c copy "C:/temp/test.flv"
# Works successfully!

Leon

Posted 2014-02-17T15:52:28.403

Reputation: 286

2

You can either use a text file that is a list of input files like so:

ffmpeg -f concat -i ffmpegTest.txt -c:v copy output.mov

OR

You can explicitly name the files like so:

ffmpeg.exe -f concat -i 'c:/temp/ffmpeg/01.mov' -i 'c:/temp/ffmpeg/02.mov' -c:v copy 'C:/temp/ffmpeg/output.mov'    

Note that you use 2 inputs one after another, and then use -c:v copy to say that there should be no re-encoding- only joining. Also, this is the concat demuxer. This is flexible, but does require the 2 input files to have same codecs.

The content of the text file is as you wrote:

file 'c:/temp/ffmpeg/01.mov'
file 'c:/temp/ffmpeg/02.mov'

Note the single quotes

The generic format is:

file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'

That would apply to multiple drives and paths.

Here is a real example of a concatenation file that works:

file '/run/media/rnx/New Volume1/PREMIER_OUTPUTEST/Sequence004.mpeg'
file '/home/rnx/Sequence003.mpeg'
file '/run/user/rnx/gvfs/users on edtmchn/Public/Sequence01.mpeg'

This is across :
One internal drive
One external USB Drive
One Network drive on another windows machine on the same domain

The command use is :

ffmpeg -f concat -i conc.txt -c:v copy -strict -2 output.mpeg

This works as expected without any errors.

Rajib

Posted 2014-02-17T15:52:28.403

Reputation: 2 406

1This answer works on ffmpeg version N-90173, Win10, CMD prompt only if the -i parameter does NOT have single quotes and does NOT use forward slashes:

-i C:\foo\bar\filelist.txt – Jay Borseth – 2018-03-04T18:04:20.930

@JayBorseth this is for Linux. Forward slashes, /run/ folder, /home/ folder are typical of Linux. – Rajib – 2018-03-04T18:23:54.947

1I need to use a file since I can have a lot of video. And I need absolute path in the file – DarkPixel – 2014-02-17T16:28:50.817

I can't, the file are on a network drive and in multiple folder. I can't force a specific directory – DarkPixel – 2014-02-17T16:36:06.580

I have this error with absolute path: Impossible to open 'C:/temp/ffmpeg/c:/temp/ffmpeg/01.mov' – DarkPixel – 2014-02-17T16:43:29.700

You are getting the error because you command is wrong. See the answer. – Rajib – 2014-02-17T16:46:45.580

It doesn't work for absolute path. It only work if the file are at the same place of the text file. – DarkPixel – 2014-02-17T16:55:29.753

I added in my question that I'm on Windows. It's probably related to the path formatting if your example work and mine doesn't – DarkPixel – 2014-02-17T17:33:28.323

Try with single quotes. And on windows forward slashes become back-slashes. – Rajib – 2014-02-17T17:34:04.853

Doesn't work, I tried blackslash/slash too :( – DarkPixel – 2014-02-17T17:38:23.103

2

Notice; on Windows, if you are using concat with a textfile, the paths in the textfile need to be relative to the output path.

E.g.

ffmpeg -f concat -i file.txt "C:\foo\file.mp4"

If your files are located in the directory C:\temp\bar.mp4 your textfile looks like this:

file ..\temp\bar.mp4
...

Patrick

Posted 2014-02-17T15:52:28.403

Reputation: 21

1Missing " character? – DavidPostill – 2014-12-16T14:29:54.020

-1

While cmd.exe is case-insensitive, ffmpeg isn't (being built primarily on linux, it tends towards *nix shell conventions). If you change the c: on each line of your input file to C:, it should work, I think.

evilsoup

Posted 2014-02-17T15:52:28.403

Reputation: 10 085