How can I remove metadata from a flv file? - ffmpeg

with ffmpeg I can use the command below to remove the metadata in General section
ffmpeg -i input.flv -c copy -metadata description= -metadata title= output.flv
What if I want to remove the metadata in Video and Audio section?
EDIT:
I want to remove writing library

With FFmpeg v4.0 or newer, for your particular case,
ffmpeg -i in -c copy -bitexact -map_metadata -1 -vbsf filter_units=remove_types=6 out

Related

merge audio and video with ffmpeg doesnt work correctly

I have ubuntu 20.04 and in past days I did this job(merge video and audio) well in terminal and with ffmpeg:
ffmpeg -i input.mp4 -i input2.mp3 -c copy output.mp4
so fast I have recived output.mp4, but now I tried this one and get output without any sound!
I try another ways to merge this ones(also with ffmpeg) but there are no diffrent...
ffmpeg -f concat -safe 0 -i <(for f in ./input*.mp4; do echo "file '$PWD/$f'"; done) -c copy output.mp4
Note -f concat will select a demuxer. This alters the way -i nput files are read.
So instead video-files 'concat expects a txt-file listing the files to concatenate.
However we somehow omit the creation of that text file and use process substitution to generate and pass that list on the fly to demux.
For more details go here:
https://trac.ffmpeg.org/wiki/Concatenate#demuxer
If you want to merge several video files, you can use these command.
merge two video files.
ffmpeg -f concat -i 1.mp4 -1 2.mp4 -codec copy out.mp4
merge multiple video files.
ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mpt -vcodec copy -acodec copy out.mp4

Add subtitles to multiple files at once

I have a folder with episodes called ep and a folder with subtitles called sub
Each episode has corresponding subtitles and i need to bulk add them with ffmpeg.
I've read that i can add subtitles with the following command:
ffmpeg -i video.avi -vf "ass=subtitle.ass" out.avi
But that only does it one file at a time.
Is there a bulk variant?
Some useful info:
ls ep prints
<series name> - Ep<episode number>.mkv
ls sub prints
<series name> - Ep<episode number>.ass
I made a small sh script that will do this:
#!/bin/sh
SUBTITLES_FOLDER=sub
EPISODES_FOLDER=ep
OUTPUT_FOLDER=out
for i in "$EPISODES_FOLDER"/*.mkv; do
sub="$SUBTITLES_FOLDER/$(echo "$i" | sed 's/mkv$/ass/')"
ffmpeg -i "$i" -i "$sub" -c:v copy -c:a copy -c:s copy -map 0:0 -map 0:1 -map 1:0 -y "$OUTPUT_FOLDER/$i" &
done
Note the '&' at the end of the ffmpeg command: it makes sure ffmpeg runs in parallel (is this the correct term for it?)
You may want to modify the file extensions and check if ffmpeg supports subtitles with your format, the rest will be done by itself.

How to add a Subtitle as default to a video already containing a subtitle stream using ffmpeg? [duplicate]

By adding an .ass subtitles track to an mkv video with ffmpeg, it isn't set as default track, so on playback you have to manually turn on subtitles. Is it possible to set the default flag for the subtitles track?
ffmpeg command used:
ffmpeg -i video.mp4 -i subtitles.ass -c:v libx264 -preset veryslow \
-pix_fmt yuv420p10le -c:a copy -c:s copy output.mkv
Note that I want to keep .ass subtitle format, not convert the subtitles to mov_text like suggested in this similar question:
How to set default streams with ffmpeg
There is the possibility to set the default flag afterwards with mkvpropedit like this:
mkvpropedit output.mkv --edit track:s1 --set flag-default=1
But is it possible to do this directly with ffmpeg?
I think as per this patch this is now possible. At least for me it works with:
ffmpeg -i in.mp4 -i in.srt -c copy -disposition:s:0 default out.mkv
Note s in -disposition:s:0 in this case stands for subtitle and not stream. To select the second steam by index use -disposition:1.
You can use 'forced' instead of default to force vlc to play it
ffmpeg -f mp4 -i outfile.mp4 -f srt -i VTS_07_0.EnglishV2.srt -c:v copy -c:a copy -metadata:s:a:0 language=Japanese -c:s mov_text -metadata:s:s:0 language=English -disposition:s:s:0 forced mix.mp4

replace a word in subtitle with ffmpeg

I want to use ffmpeg to replace all occurrences of a word in all subtitles of a video file with ffmpeg. All non-subtitles channels should be copied (not reencoded) and all formatting from the original subtitles should stay if possible.
example:
ffmpeg -i input.mkv -SUBTITLEFILER='old_word/new_word' output.mkv
I am using ubuntu 19.04 and bash (in case additional steps or dependencies would be required for this)
ffmpeg has no find/replace functionality for subtitles, but you can do this losslessly in 3 commands:
Extract the subtitles:
ffmpeg -i input.mkv -map 0:s:0 -c copy sub0.ass -map 0:s:1 -c copy sub1.ass -map 0:s:2 -c copy sub2.ass
I'm assuming your subtitles are SubStation Alpha (ASS/SSA) subtitles. Use the appropriate output name if they differ: such as .srt for SubRip (refer to ffmpeg -muxers).
Replace with sed:
sed -i 's/cat/dog/g' *.ass
Remux:
ffmpeg -i input.mkv -i sub0.ass -i sub1.ass -i sub2.ass -map 0 -map -0:s -map 1 -map 2 -map 3 -c copy -metadata:s:s:0 language=fas -metadata:s:s:1 language=eng -metadata:s:s:2 language=fin output.mkv
If you want to make a certain subtitle the default see the -disposition option as shown in ffmpeg set subtitles track as default.

How do I add a custom thumbnail to a .mp4 file using ffmpeg?

I am trying to find the proper ffmpeg command to add a .png or .jpg image to a .mp4 video as a thumbnail. The command will eventually automatically be executed by a C# program.
This is what I have so far:
# This does not work. It only removes the default thumbnail.
ffmpeg -i video.mp4 -i image.png -acodec copy -vcodec copy -map 0 -map 1:0 OUTPUT.mp4
Is what I want possible with ffmpeg? If so, please guide me in the right direction.
Using ffmpeg 4.0, released Apr 20 2018 or newer,
ffmpeg -i video.mp4 -i image.png -map 1 -map 0 -c copy -disposition:0 attached_pic out.mp4
As in version 4.2.2...See Section 5.4 in FFmpeg documentation
To add an embedded cover/thumbnail:
ffmpeg -i in.mp4 -i IMAGE -map 0 -map 1 -c copy -c:v:1 png -disposition:v:1 attached_pic out.mp4
Not all muxers support embedded thumbnails, and those who do, only support a few formats, like JPEG or PNG.

Resources