[libav-tools] Replacing video with a still image at specific points

Chris Angelico rosuav at gmail.com
Wed Jul 15 05:23:34 CEST 2015


I have a video of a talking head, which I wish to replace at certain
points with still images (slides, if you like), for X seconds. The
'overlay' filter seems to be most of what I want, and I can ensure
that all the images are the same size as the video itself (which means
they completely cover the image). But after poking around in the man
page and on the internet, the best I can come up with is this:

# Inputs: input_video.mp4, static_image.png
# Output: combined.mkv
avconv -i input_video.mp4 -t 3 part1.ts -ss 3 -t 5 part2.mkv -ss 8 part3.ts
avconv -i part2.mkv -i static_image.png -filter_complex overlay part2_static.mkv
avconv -i part2_static.mkv part2_static.ts
cat *.ts|avconv -i - -c copy combined.mkv

This appears to work, but it seems like a lot of hassle. I don't have
the 'concat' demuxer, which is referred to in various places on the
internet, so I'm using the .ts format (which appears to concatenate
just fine).

I cut the image into pieces: first piece is up to the point where an
image is overlaid, then the second piece is the duration of that image
(because the audio needs to continue unchanged), then the third piece
follows from there, with additional pieces if there are additional
image overlays. Then the overlays get overlaid with their images, and
then separately converted to .ts; then finally, the .ts files get
combined and converted into a single file.

Attempting to write the overlay directly to .ts results in this:

Error while opening encoder for output stream #0:0 - maybe incorrect
parameters such as bit_rate, rate, width or height

Yet I can write to mkv and then convert separately, which seems strange.

Is this the best way to do things?

For what it's worth, I have a script that sorts out the parameters for me:

https://github.com/Rosuav/shed/blob/master/stills.pike

It pretty much does the commands you see above, except that it feeds
stdin directly for the last step instead of using the 'cat' command.

I feel like I'm waffling about somewhat blindly, just like
https://xkcd.com/763/ ...

ChrisA


More information about the libav-tools mailing list