ffmpeg - trying to output timecodes in CSV of segments between blacks - filter

I would be so glad to have some help with this.
I have video rushes in this form : black > sequence > black > sequence...
I need the start/end timecodes of each sequences (no black) to create segments on another software so I wondering if it's possible with the blackdetect filter of FFmpeg to output only the sequences data in a csv file. No problem with the simple command line to have the blacks but I'm still at this point with unsuccess others test.
The goal is automate this for multiple files by import the csv in a RPA.
Thank you very much.

You cannot do that with ffmpeg by itself, but with a bit of help from a script (i.e., Python) you can decode the frame metadata. The following filtergraph outputs the black detect output to stdout:
ffmpeg -i input -vf blackdetect,metadata=print:file=- -f null dev/null`
Your script shall capture the pipe output, and parse the output to retrieve the pts and detect either black_start and black_end and reformat and output to a csv file.
If your other program is flexible, you can alternately specify output file name file=xxx and do the parsing there.

Related

FFmpeg drawtext's fontfile unable to load

I have This Parisienne-type Font file and I want to write on a gif using that font but the output font is never Parisienne, it always comes out as normal Arial
the command
ffmpeg -i C:\Users\1997\www\post2\css\back2.gif -vf "drawtext=fontfile='C\:\\Windows\\Fonts\\2.ttf':text='Darbuka 70':fontcolor=#5c391685:fontsize=160::x=(w-text_w)/2:y=20" C:\Users\1997\www\post2\css\output.mp4
This is how the font file looks:
the output:
It's likely due to not having enough escape characters (\). You need one for FFmpeg and double them for shell. So, try
fontfile='C\\\\:/Windows/Fonts/2.ttf'
Four \'s worked when I tested in Python, but if it doesn't add/subtract a pair at a time to see which works for you.
Last, if you want to see if fontfile option is set properly or not, add -loglevel debug option and look in the log for a line like:
[Parsed_drawtext_2 # 0000015e54962a80] Setting 'fontfile' to value 'C:/Windows/Fonts/2.ttf'
If it's not properly escaped, you'd see a log like:
[Parsed_drawtext_2 # 000001c010782440] Setting 'fontfile' to value 'C'
[Parsed_drawtext_2 # 000001c010782440] Setting 'text' to value '/Windows/Fonts/2.ttf'
P.S., I cheated and used / for directory separator. If you want to use \, the same rule applies. You need a several \'s for each \. See documentation

How to save ninja build output without loosing the compressed format of output

I tride to duplicate the output of the ninja build system to the separate file but I want to save original campresed look of the ninja output.
If I tee ninja (ninja all | tee -a someFile) I get wall of text enter image description here
Instead of updating one line.
If there is a better way to duplicate the output of ninja to file without loosing the compress formatig of output please let me know!
UPD: I find out that ninja update lines with [K escape sequence (erasing the line) and after capturing or rederecting ninga output it vanishing. If some body know how to allowed system to capture all tipy of escape sequence, it will solve my problem

How does one obtain the lavfi.aphasemeter.phase frame metadata in FFMPEG?

I'm trying to derive the numeric representation of a sound file's phase.
FFMPEG's aphasemeter filter seems to fit the bill for computing this number; the docs explicitly say:
The filter also exports the frame metadata lavfi.aphasemeter.phase which represents mean phase of current audio frame. Value is in range [-1, 1]. The -1 means left and right channels are completely out of phase and 1 means channels are in phase.
https://ffmpeg.org/ffmpeg-filters.html#aphasemeter
However, I can't seem to figure out how to use this filter to get that numeric value. When I experiment with various commands, I get various error messages. For example, ffmpeg -i input_file.wav -f aphasemeter.phase says I need an output, but ffmpeg -i input_file.wav -f aphasemeter.phase output_file.txt produces is not a suitable output format \ output_file.txt: Invalid argument
I'm looking for that -1 through 1 value; a graphical representation of that--though seemingly the main point of that filter--is not what I'm looking for.
Any ideas?
In case it matters, I'm using the WSL, having installed ffmpeg by apt-get.
Logged metadata values can be accessed and exported using the (a)metadata filter.
ffmpeg -i in.wav -af aphasemeter=video=0,ametadata=print:file=inwav-phase.txt -f null -
The text file will have the data in the format,
...
frame:105 pts:107512 pts_time:2.23983
lavfi.aphasemeter.phase=0.600750
frame:106 pts:108536 pts_time:2.26117
lavfi.aphasemeter.phase=0.554201
...

ffmpeg scale image with unrelated number in the name

I'm attempting to scale image(s) that have any given name. I've found my script is failing on files that have numbers in the name. "0% financing", "24 Hour", etc. The other files are working fine, so it's not the script itself. I get:
[image2 # 0x7fbce2008000] Could find no file with path '/path/to/0% image.jpeg' and index in the range 0-4
How can I tell ffmpeg that this isn't a search pattern, or sequential numbered files ? There's only 1 jpeg in each location, and I do not have control of the file names to change them.
-update-
I've figured out the command
ffmpeg -pattern_type none -i /path/to/0%\ image/0%\ image.jpeg -vf scale=320:-1 /path/to/0%\ image/0%\ image.out.jpeg
gets me past the initial problem, but the output won't work because I can't get it now to escape the final argument. If I am in the directory (so no path) and change the output to just out.jpeg it will work, so I'm confident the first error is corrected.
Now I need to figure out how to use spaces in the path in the output argument? I've tried surrounding it in quotes:
"0% image.out.jpeg"
regular escapes:
0%\ image.out.jpeg
and surrounding it in quotes and using escapes at the same time:
"0%\ image.out.jpeg"

Use ffmpeg to edit metadata titles for multiple files

I'd like to be able to add/edit video metadata titles to multiple files at once or with a single command, but I don't know how to tell ffmpeg to do this.
I read a similar post on the Ubuntu Forums, but I have never used string manipulation in Linux before, so the commands I'm seeing in the post are way out of my comprehension at the moment, and much of the discussion goes over my head.
I've got all of my video files in a filename format that includes the show name, the episode number, and episode title. For example:
show_name - episode_number - episode_title.extension
Bleach - 001 - A Shinigami Is Born!.avi
Is there a simple way to read the title and episode number from the filename and put it into a metadata tag without having to go through each and every file manually?
EDIT 1: So I found out that I can iterate through files in a directory, and echo the filename, and I was told by a friend to try bash to parse the strings and return values from that to use in the ffmpeg command line. The problem is, I have absolutely no idea how to do this. The string manipulation in bash is very confusing on first look, and I can't seem to get it to output what I want into my variables. My test bash:
for file in "Bleach - 206 - The Past Chapter Begins! The Truth from 110 Years Ago.mkv"; do extension=${file##*.} showName=${file%% *} episode=${file:9:3}; echo Extension: $extension Show: $showName Episode: $episode; done
That outputs
Extension: mkv Show: Bleach Episode: 206
Which are all the variables I'm going to need, I just don't know how to move those to be run in ffmpeg now.
EDIT 2: I believe I was able, through much trial and error, to find a bash command that would do exactly what I wanted.
for file in *; do newname=${file:0:-4}_2 ext=${file##*.} filename=${file} showname=${file%% *} episode=${file:9:3} nameext=${file##*- } title=${nameext%.*}; ffmpeg -i "$filename" -metadata title="$title" -metadata track=$episode -metadata album=$showname -c copy "$newname.$ext"; mv -f "$newname.$ext" "$filename"; done
This lets me parse the information from the filename, copy it to some variables, and then run ffmpeg using those variables. It outputs to a second file, then moves that file to the original location, overwriting the original. One could remove that section out if you're not sure about how it's going to parse your files, but I'm glad I was able to get a solution that works for me.

Resources