I'm using FFmpeg to extract frames of a video and therefore I want to print the metadata of the video to a text file first (to get the scene\ value of each frame).
This already works for me with something like:
ffmpeg -i input.mp4 -vf "select='gte(scene,0)',metadata=print:file=scenescores.txt" -an -f null -
Because I'm using all this inside of a Java application I want to pass an absolute path (of an temp directory) to print:file= instead of the currently relative one which will write it to the root directory of the project.
But when I try to specify an absolute path like D:\scenescores.txt I get the following error:
[metadata # 00000203282ff0c0] Unable to parse option value "scenescores.txt" as boolean
[metadata # 00000203282ff0c0] Error setting option direct to value scenescores.txt.
[Parsed_metadata_1 # 00000203269bdf00] Error applying options to the filter.
[AVFilterGraph # 0000020328020840] Error initializing filter 'metadata' with args 'print:file=D:\scenescores.txt'
Is there any way to achieve printing to an absolute path? Am I missing some escape rules or something?
I played a lot with escaping different things and in the end it worked for me like this:
ffmpeg -i input.mp4 -vf "select='gte(scene,0)',metadata=print:file=\'D:\scenescores.txt\'" -an -f null -
The difference is that the path is surrounded by \'.
Also I read that escaping \ to \\ or / can help sometimes.
Related
I'm trying to rotate videos and increase its sound as well as change itsframe rate
ffplay -i C:/Users/thota/OneDrive/Desktop/VET/Input.mp4 -af "volume="10.0",atempo="10.0" -vf "transpose=2,transpose=2,setpts=1/"10.0"*PTS,scale="3840:2160",fps="5.0"
I'm using FFmpeg as I'm trying to build a video editing application hence I need to combine many operations when i try to use above command I'm getting this error(in command im using ffplay as I just want to see output)
error
[atempo # 000001fdd50c7c40] [Eval # 00000047b79fe770] Undefined constant or missing '(' in
'vftranspose=2'
[atempo # 000001fdd50c7c40] Unable to parse option value "10.0 -vf transpose=2"
[atempo # 000001fdd50c7c40] [Eval # 00000047b79fe770] Undefined constant or missing '(' in
'vftranspose=2'
[atempo # 000001fdd50c7c40] Unable to parse option value "10.0 -vf transpose=2"
[atempo # 000001fdd50c7c40] Error setting option tempo to value 10.0 -vf transpose=2.
[Parsed_atempo_1 # 000001fdd50c7b40] Error applying options to the filter.
Error initializing filter 'atempo' with args '10.0 -vf transpose=2'
Pleas help me solve this issue and suggest me a best way to add multiple operations when i try to use , its being tough so is their any other way
If yes please let me know
Thank you
It looks like you are missing quotation marks " character in two places.
The following command works (weird audio, but no errors):
ffplay -i C:/Users/thota/OneDrive/Desktop/VET/Input.mp4 -af "volume="10.0",atempo="10.0"" -vf "transpose=2,transpose=2,setpts=1/"10.0"*PTS,scale="3840:2160",fps="5.0""
You don't need all the quotation marks, and you may improve readability by using '' instead of nested "".
The following command is equivalent:
ffplay -i C:/Users/thota/OneDrive/Desktop/VET/Input.mp4 -af "volume=10.0,atempo=10.0" -vf "transpose=2,transpose=2,setpts=1/10.0*PTS,scale='3840:2160',fps=5.0"
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 am trying to extract and parse KLV data from a video stream. I found the following example in a Github repository. I am wondering what does the mapping option data-re do?
$ ffmpeg -i Day\ Flight.mpg -map data-re -codec copy -f data -
I understand the rest of the command, and know that -map is used to choose streams from inputs. But what does data-re mean. I couldn't find any explanation for it (or similar mapping option or stream identifier) in the documentation, e.g. here and here.
It's a typo and incorrect. The only time you use arbitrary label names is when using -filter_complex.
Use:
$ ffmpeg -i Day\ Flight.mpg -map 0:d -c copy -f data -
I could understand a user trying data, but data-re? Might be a double typo for -map data -re, where -re is intended to be the "Read input at native frame rate" input option (-map data is still invalid in this case).
It's not a valid value currently. It could possibly have been a value historically, but I doubt it. Most likely, it "worked" because the map arg parser would ignore additional letters if a lazy evaluation matched a stream and the d in data-re would match data streams. The parser is no longer that clumsy.
I got pictures named as
pic_0_new.jpg
pic_10_new.jpg
pic_20_new.jpg
...
pic_1050_new.jpg
which I want to turn into a video (Ubuntu ffmpeg). I tried the following
ffmpeg -start_number 0 -i pic_%d_new.jpg -vcodec mpeg4 test.avi
but I don't know how to set the step size and the end number. How to do this?
Thanks for help :)
If your files are named with leading zeroes then you can use the built-in globbing functionality. If not (like your's), you can create a file list and supply that as the input, just like explained here.
The other thing you need to set is the input framerate that tells FFmpeg what framerate should assume for the images (note that the option is ahead of the -i input option).
So the command should look like this:
ffmpeg -framerate 25 -i pic_%04d_new.jpg <encoding_settings> test.avi
Also note that you can use the filename expansion on files with or without leading zeroes (Thanks for #Gyan to pointing it out):
match regularly numbered files: %d (this is what you're using)
img_%d.png // This will match files with any number as a postfix starting from img_0.png
match leading zeroes: %0<number_of_digits>d
img_%03d.png // This will match files ranging from img_000.png to img_999.png
In addition, mpeg4/avi is not the most convenient encoder/container to use...
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