I am trying to concatenate a bunch of audio files with the following command:
ffmpeg -f concat -safe 0 -i Filelist.txt -c copy out.mp3
Unfortunately, one of my audio files has an apostrophe in its name, which are used to indicate the start and end of the filename:
file 'Murfy's in Trouble!.mp3'
giving the following error:
Impossible to open 'Murfy%s'
Filelist.txt: No such file or directory
I tried escaping it with \ and %, but those don't work. Is there any way around this without changing all my filenames?
Escaping ' in a quote needs to be done with '\'', as per the documentation.
Related
I'm attempting to concatenate various .ts video clips into one video and then convert the video into an .mp4 file. I know I can make a .txt file formatted like so:
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
and then concatenate them like so:
ffmpeg -f concat -i mylist.txt -c copy all.ts
and then convert the file like so:
ffmpeg -i all.ts -acodec copy -vcodec copy all.mp4
My question is, can my .txt file be urls from another domain? e.g.:
http://somewebsite.com/files/videoclip1.ts
http://somewebsite.com/files/videoclip2.ts
http://somewebsite.com/files/videoclip3.ts
Or, do I first have to download all these clips, store them locally on my domain, then make a .txt file pointing to them? I'm using PHP. Thanks.
Yes, this is possible. Note that in the following examples I use the urls and filenames from your question, when testing I used some test files on my own web server.
Trying this with the example text file you provided will give a pretty clear error message:
[concat # 0x7f892f800000] Line 1: unknown keyword 'http://somewebsite.com/files/videoclip1.ts
mylist.txt: Invalid data found when processing input
This is easily fixed by re-introducing the 'file' keyword in mylist.txt:
file 'http://somewebsite.com/files/videoclip1.ts'
file 'http://somewebsite.com/files/videoclip2.ts'
file 'http://somewebsite.com/files/videoclip3.ts'
That updated file will give a different error message:
[concat # 0x7fa467800000] Unsafe file name 'http://somewebsite.com/files/videoclip1.ts'
mylist.txt: Operation not permitted
The reason for this is that ffmpeg will not allow http-urls by default. This can be bypassed by including the -safe 0 argument in your ffmpeg call before the -i argument:
ffmpeg -f concat -safe 0 -i mylist.txt -c copy all.ts
This might work out of the box on your installation, on mine this gave another error message:
[http # 0x7faa68507940] Protocol 'http' not on whitelist 'file,crypto'!
[concat # 0x7faa69001200] Impossible to open 'http://somewebsite.com/files/videoclip1.ts'
mylist.txt: Invalid argument
This is because, on my installation, ffmpeg's default protocol whitelist only includes file and crypto. To allow the http protocol as well, we need to explicitly provide the allowed protocols whitelist in the command. As it turns out, tcp is also required:
ffmpeg -f concat -safe 0 -protocol_whitelist file,http,tcp -i mylist.txt -c copy all.ts
This allowed my installation to download and concatenate the video files.
I have a bunch of .ts videofiles that I want to merge into a single file so I can convert it to a .mp4 video.
The .ts files are in a folder "E:\videotest" like:
E:\videotest\0.ts
E:\videotest\1.ts
[...]
E:\videotest\100.ts
I used a PowerShell command to output the filepaths in a .txt file:
foreach ($i in Get-ChildItem .\*.ts) {echo "file '$i'" >> mylist.txt}
The resulting mylist.txt looks like:
file 'E:\videotest\0.ts'
file 'E:\videotest\1.ts'
[...]
file 'E:\videotest\100.ts'
When I run the command:
ffmpeg -f concat -safe "0" -protocol_whitelist "file,http,https,tcp,tls" -i "E:\videotest\concat\mylist.txt" -c copy "E:\videotest\concat\combined_video.ts"
I get the error:
Line 1: unknown keyword ' ■f'
E:\videotest\concat\mylist.txt:
Invalid data found when processing input
But if I add a subfolder layer to the files like this:
E:\videotest\0\0.ts
E:\videotest\1\1.ts
[...]
E:\videotest\100\100.ts
And change mylist.txt to:
file 'E:\videotest\0\0.ts'
file 'E:\videotest\1\1.ts'
[...]
file 'E:\videotest\100\100.ts'
The same ffmpeg command will work and create the combined_video.ts file.
Why does converting work with the subfolder structure but not from the main folder?
How do I adjust the ffmpeg command to make it work?
Thank you.
It turns out that the problem was the encoding of the "mylist.txt" file. For some reason it was encoded as "UCS-2 LE BOM". After setting it to "UTF-8" I was able to concatenate the files.
I am trying to concatenate two video files using ffmpeg, and I am receiving an error.
To eliminate compatibility issues between the two videos, I have been concatenating the same video with itself, and the same error persists.
ffmpeg \
-f concat \
-safe 0 \
-i intro_prepped.avi intro_prepped.avi \
-c copy \
concat.avi
And the error output I receive is....
[concat # 0x220d420] Line 1: unknown keyword 'RIFFf�?'
intro_prepped.avi: Invalid data found when processing input
I have tried various combinations of concat flags and have not been able to get it to work. Has anyone seen this error before?
This is a bit late for the original post, but I was just searching for answers to the same problem so I think it's still relevant and I haven't found any more recent posts answering the same problem.
I found that my .txt file was encoded wrong. I opened the file in Notepad and did a 'Save As...'
I changed the encoding to UTF-8 and the ffmpeg concat command worked.
Docs for several ways of concatenating files: https://trac.ffmpeg.org/wiki/Concatenate
Here's a command I use to concatenate videos:
ffmpeg \
-i "concat:input1.avi|input2.avi|input3.avi" \
-c:a copy \
-c:v copy \
output.avi
I tried all of the aforementioned and it didn't work.
It looks like that the file names in the list have to be specially formatted to look like:
file '/path/to/file1.wav'
with a word file included. I spend a lot of time trying to guess why ffmpeg encountered an error trying to read the file names. It didn't matter if they were in the list or in the command line. So only after I utilized a command
for f in *.wav; do echo "file '$f'" >> mylist.txt; done
to make list from ffmpeg's manual I had success. The only difference was an additional word file.
Here you can read it yourself: https://trac.ffmpeg.org/wiki/Concatenate#demuxer
Your text file is likely encoded in UTF-16.
Fix: (Windows 10)
Open text file
Select 'Save as'
Look by the save button, you get to pick encoding with a drop down box, select UTF-8.
Save and run ffmpeg again.
I used the Powershell code on ffmpegs webpage to make a text file with filenames, and Powershell seems to save text files as some variant of UTF-16, so I chose the safer UTF-8.
The input file should be a text file, not an avi. The text file lists the files to concatenate.
See the concat demuxer documentation and FFmpeg Wiki: Concat.
Nobody had a full, working, concat text file batch file anywhere. So I am posting it
md ts
for %%x in (input\*.m4a) do (ffmpeg -i "%%x" -c copy -bsf:v h264_mp4toannexb ts\%%~nx.ts)
for %%c in ("ts\*ts") do (echo file '%%c')>>list.txt
for %%f in (input\*.m4a) do (set fn=%%~nf)
ffmpeg -f concat -safe 0 -i "list.txt" -c copy "%cd%\%fn%".m4a
I struggled with all these instructions above on my Mac (M1, Ventura, ffmpeg version N-109530-g4a80db5fc2-tessus). None of them worked for me - but a combination of all did the trick!
This is how I got it running:
place all input files the same folder
create input.txt in this folder - content looks like this:
file 'input1.mp4'
file 'input2.mp4'
file 'input3.mp4'
file 'input4.mp4'
Note:
file encoding must be UTF-8
file keyword must be present
filename must not be fully qualified (I got exceptions using '/path/to/input1.mp4')
filename must be enclosed by '
navigate to this folder in the terminal
execute ffmpeg -f concat -i input.txt -c copy ffmpegOUT.mp4
I am trying to make an FFMPEG script that relied on a glob input pattern from Linux to Windows. Unfortunately that is not supported so I am looking for an alternative. I do not want to have to rename or copy the files every time I run the script because the files are used elsewhere and I cannot rename them and I would like to avoid duplication or unnecessary temporary files.
Are globs numerically sequential named images my only option here? Ideally I would like to input a list of image paths to FFMPEG as a substitute for ffmpeg -i *.jpg
The workarounds are to prepare a text file with the names and use the concat demuxer.
Or you can use image2pipe
cat *.jpg | ffmpeg -f image2pipe -framerate 25 -i - out.mp4
The best solution I could find (that's Windows compatible) was to generate a line separated list of files in a text file and pass that through to FFMPEG. For example, to generate a stabilized MP4 from a bunch of JPEGs:
ffmpeg -f concat -safe 0 -i ./files.txt -vf deshake=rx=64:ry=64 ./stabilized.mp4
Where files.txt is a list of the files in the following format. The safe option toggles the ability to have absolute/relative file paths.
# this is a comment
file 'C:/path/to/file1.jpg'
file 'C:/path/to/file2.jpg'
file 'C:/path/to/file3.jpg'
I am trying to make an FFMPEG script that relied on a glob input pattern from Linux to Windows. Unfortunately that is not supported so I am looking for an alternative. I do not want to have to rename or copy the files every time I run the script because the files are used elsewhere and I cannot rename them and I would like to avoid duplication or unnecessary temporary files.
Are globs numerically sequential named images my only option here? Ideally I would like to input a list of image paths to FFMPEG as a substitute for ffmpeg -i *.jpg
The workarounds are to prepare a text file with the names and use the concat demuxer.
Or you can use image2pipe
cat *.jpg | ffmpeg -f image2pipe -framerate 25 -i - out.mp4
The best solution I could find (that's Windows compatible) was to generate a line separated list of files in a text file and pass that through to FFMPEG. For example, to generate a stabilized MP4 from a bunch of JPEGs:
ffmpeg -f concat -safe 0 -i ./files.txt -vf deshake=rx=64:ry=64 ./stabilized.mp4
Where files.txt is a list of the files in the following format. The safe option toggles the ability to have absolute/relative file paths.
# this is a comment
file 'C:/path/to/file1.jpg'
file 'C:/path/to/file2.jpg'
file 'C:/path/to/file3.jpg'