combining 1 image + 1 audio using FFmpeg

0

I want to combine an audio file and one image file into a video. Output will be in .webm format so I will be using libvpx. The video must have one frame with the best/lossless quality.

So far I have tried these, but I got bad results or no results at all:

1st command:

ffmpeg -i image.jpg -i audio.ogg -c:v copy -c:a copy outputvideo.webm

This is not working. It gives this error:

[webm @ 0000000002c7f8a0] Only VP8 or VP9 video and Vorbis or Opus audio and Web
VTT subtitles are supported for WebM.
...
Could not write header for output file #0 (incorrect codec parameters ?): Error
number -22 occurred

2nd command:

ffmpeg -i image.jpg -i audio.ogg -c:v libvpx -c:a copy outputvideo.webm

This produces poor quality, not acceptable for me.

3rd command:

ffmpeg -i image.jpg -i audio.ogg -c:v libvpx -crf 4 -c:a copy outputvideo.webm

So I added -crf 4 parameter. I expected that would produce visually lossless video. In fact, it has no effect at all. -crf 4 and -crf 63 produces same results.

Then I have tried the similar settings with the libvpx-vp9 codec, but no luck. Even the -lossless 1 parameter does nothing for improving quality.

destor

Posted 2015-01-18T00:07:47.123

Reputation: 183

Answers

0

1st command: jpg is not contains webm. http://en.wikipedia.org/wiki/WebM

2nd command: You can use -loop 1 in front of inputfile, and use -shortest behind inputfile.

ffmpeg -loop 1 -i image.jpg -i audio.ogg -shortest -c:v libvpx -c:a copy outputvideo.webm

If you want to set fps, use fps filter.

ffmpeg -loop 1 -i image.jpg -i audio.ogg -vf fps=10 -shortest -c:v libvpx -c:a copy outputvideo.webm

3rd command: You can use quality best. http://ffmpeg.org/ffmpeg-codecs.html#libvpx

ffmpeg -loop 1 -i image.jpg -i audio.ogg -shortest -c:v libvpx -quality best -c:a copy outputvideo.webm

nico_lab

Posted 2015-01-18T00:07:47.123

Reputation: 402

Your commands creates more than just one frame. Since my audio files are too long, the video stream size will be at least 2x larger than the given .jpg file, with worse quality. BTW, I tried to set fps at smaller values than 1, but it didn't work. I have tried both, -r 1/60 parameter and -vf fps="fps=1/60" filter. I don't know why. – destor – 2015-01-18T04:36:44.707

I don't know why libvpx doesn't set fps at smaller values than 1, using libx264 sets fps at smaller values than 1.

wiki:Create a video slideshow from images

ffmpeg -loop 1 -i image.jpg -i audio.ogg -vf -vf "fps=1/60" -pix_fmt yuv420p -shortest -c:v libx264 -c:a copy outputvideo.mkv

– nico_lab – 2015-01-18T10:45:02.580

0

I'm not sure if it's a bug, but using -qscale:v instead of -crf works for libvpx. Qscale works the opposite way to CRF, higher is larger / better quality. Try the second command with -qscale:v 10 instead of the -crf option.

stib

Posted 2015-01-18T00:07:47.123

Reputation: 3 320

0

You could try to get quality by manually setting video bitrate "-b:v 2000M"

As for FPS, seems like it doesn't affect size much. Experimented a bit with -b:v and framerates:

ffmpeg -loop 1 -i ./frames/0254.png -i camera-shutter-click-07.wav -r 10000 -pix_fmt yuv420p -shortest -vcodec libvpx -strict -2 -acodec vorbis  outputvideo6.webm

ffmpeg -loop 1 -i ./frames/0254.png -i camera-shutter-click-07.wav -pix_fmt yuv420p -shortest -vcodec libvpx -strict -2 -acodec vorbis  outputvideo5.webm

ffmpeg -loop 1 -i ./frames/0254.png -i camera-shutter-click-07.wav -r 10000 -pix_fmt yuv420p -shortest -b:v 2000M -vcodec libvpx -strict -2 -acodec vorbis  outputvideo7.webm

First two videos are 25fps and 10000fps but their filesizes are almost equal: 101.3 and 102.7kB But since in third bitrate is higher it's size 339.7kB

ffmpeg -i outputvideo5.webm -i outputvideo6.webm -i outputvideo7.webm
ffmpeg version 2.5.git Copyright (c) 2000-2015 the FFmpeg developers
  built on Jan 11 2015 19:12:34 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --prefix=/home/alexandrov/ffmpeg_build --extra-cflags=-I/home/alexandrov/ffmpeg_build/include --extra-ldflags=-L/home/alexandrov/ffmpeg_build/lib --bindir=/home/alexandrov/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
  libavutil      54. 16.100 / 54. 16.100
  libavcodec     56. 20.100 / 56. 20.100
  libavformat    56. 18.100 / 56. 18.100
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  7.100 /  5.  7.100
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, matroska,webm, from 'outputvideo5.webm':
  Metadata:
    encoder         : Lavf56.18.100
  Duration: 00:00:01.32, start: 0.000000, bitrate: 613 kb/s
    Stream #0:0: Video: vp8, yuv420p, 1280x720, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
    Stream #0:1: Audio: vorbis, 48000 Hz, stereo, fltp (default)
Input #1, matroska,webm, from 'outputvideo6.webm':
  Metadata:
    encoder         : Lavf56.18.100
  Duration: 00:00:01.30, start: 0.000000, bitrate: 631 kb/s
    Stream #1:0: Video: vp8, yuv420p, 1280x720, SAR 1:1 DAR 16:9, 10k fps, 25 tbr, 1k tbn, 1k tbc (default)
    Stream #1:1: Audio: vorbis, 48000 Hz, stereo, fltp (default)
Input #2, matroska,webm, from 'outputvideo7.webm':
  Metadata:
    encoder         : Lavf56.18.100
  Duration: 00:00:01.30, start: 0.000000, bitrate: 2088 kb/s
    Stream #2:0: Video: vp8, yuv420p, 1280x720, SAR 1:1 DAR 16:9, 10k fps, 25 tbr, 1k tbn, 1k tbc (default)
    Stream #2:1: Audio: vorbis, 48000 Hz, stereo, fltp (default)

Adrian

Posted 2015-01-18T00:07:47.123

Reputation: 73