0

I have a video that is only one image and an audio track. It is very large and I would like to make it smaller. Since there is only one image/frame, I would think it would be more efficient if only this one frame would be saved and just shown, instead of having a copy of the image in every frame. How can I make such a video with ffmpeg on linux?

So far I have used the command

ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4

which greatly reduced the size. I am not quite sure how it does it, but since the result is nearly as small as the audio track (that I extracted for comparison), it seems that the condec is a good choice.

However it takes SO much time for the transformation and I have a couple of other videos I would like to transform. Is there a way to speed up the process or choose a different command?

For example I am thinking, whether I could tell ffmpeg that it is just one image and it should just use the n-th frame and not bother with encoding the rest.


EDIT: Using the ideas from Баяр Гончикжапов is used these commands:

file="input.mp4"
ffmpeg -i "$file" -f image2 -frames:v 1 /tmp/tmp.jpg
ffmpeg -i "$file" -i /tmp/tmp.jpg -map 0:a -map 1:v -c:a copy -c:v copy output.mp4

$ mediainfo "$file"         
General
Complete name                            : 1 Hour Epic Music _ Best Of Two Steps From Hell Voll. III.mp4
Format                                   : MPEG-4
Format profile                           : Base Media / Version 2
Codec ID                                 : mp42
File size                                : 134 MiB
Duration                                 : 1h 0mn
Overall bit rate mode                    : Variable
Overall bit rate                         : 308 Kbps
Encoded date                             : UTC 2013-11-28 04:41:00
Tagged date                              : UTC 2013-11-28 04:41:00
gsst                                     : 0
gstd                                     : 3648063
gssd                                     : B5CC58185HH1408390296880239
gshh                                     : r2---sn-9nj-q0ne.googlevideo.com

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Baseline@L3
Format settings, CABAC                   : No
Format settings, ReFrames                : 1 frame
Format settings, GOP                     : M=1, N=60
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 1h 0mn
Bit rate                                 : 210 Kbps
Maximum bit rate                         : 2 389 Kbps
Width                                    : 640 pixels
Height                                   : 360 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 24.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.038
Stream size                              : 91.3 MiB (68%)
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 2013-11-28 04:41:19

Audio
ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : 40
Duration                                 : 1h 0mn
Bit rate mode                            : Variable
Bit rate                                 : 96.0 Kbps
Maximum bit rate                         : 102 Kbps
Channel(s)                               : 2 channels
Channel positions                        : Front: L R
Sampling rate                            : 44.1 KHz
Compression mode                         : Lossy
Stream size                              : 41.7 MiB (31%)
Title                                    : IsoMedia File Produced by Google, 5-11-2011
Encoded date                             : UTC 2013-11-28 04:41:10
Tagged date                              : UTC 2013-11-28 04:41:19


$ mediainfo /tmp/output.mp4 
General
Complete name                            : /tmp/output2.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom
File size                                : 42.4 MiB
Duration                                 : 1h 0mn
Overall bit rate mode                    : Constant
Overall bit rate                         : 97.4 Kbps
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00
Writing application                      : Lavf57.83.100

Video
ID                                       : 2
Format                                   : JPEG
Codec ID                                 : 6C
Duration                                 : 40ms
Bit rate mode                            : Constant
Bit rate                                 : 4 215 Kbps
Width                                    : 640 pixels
Height                                   : 360 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 25.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.732
Stream size                              : 20.6 KiB (0%)
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

Audio
ID                                       : 1
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : 40
Duration                                 : 1h 0mn
Bit rate mode                            : Constant
Bit rate                                 : 96.0 Kbps
Channel(s)                               : 2 channels
Channel positions                        : Front: L R
Sampling rate                            : 44.1 KHz
Compression mode                         : Lossy
Stream size                              : 41.7 MiB (99%)
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00
  • However, as one can notice, the audio was not really copied. How can I make sure, audio is really copied?
  • Also VLC Player has an issue: When starting the video, the slides (that indicates the time) does not move. If I move it to something greater than 00:00, it does move again...
  • How do I say that I want to extract a different frame than the first?
0

Convert one video frame to temporary file, then join temp file with audio:

ffmpeg -i input.mp4 -frames:v 1 -map 0:v -c:v libx265 -crf 18 -y tmp.mp4
ffmpeg -i input.mp4 -i tmp.mp4 -map 0:a -map 1 -c:a copy -c:v copy -y output.mp4

These lines create a video incompatible with the VLC player. Therefore, I propose an option with converting to MP3.

ffmpeg -i input.mp4 -f image2 -frames:v 1 -y /tmp/tmp.jpg
ffmpeg -i input.mp4 -i /tmp/tmp.jpg -map 0:a -map 1 -c:a libmp3lame -c:v copy -y /tmp/output.mp3
vlc /tmp/output.mp3
  • This would be a better answer if it included an explanation of what the commands do. Yes, it’s kind-of obvious, but this is supposed to be a knowledge base. … … … … … … … … … … … Please do not respond in comments; edit your answer to make it clearer and more complete. – Scott Nov 14 '20 at 8:18
  • This answer indeed includes very little explanation of what is going on here. Also, it'll create an MJPEG-encoded video, which may or may not be what the OP wants. – slhck Nov 14 '20 at 9:49
  • Thank you, I tried it out, but I when I played output.mp4 in VLC Player I only got the audio - no image. What might be wrong? How can I check if tmp.mp4 was created correctly? – Make42 Nov 14 '20 at 20:24
  • @Make42 ffplay and mpv plays output.mp4 correctly, but not vlc. It needs to come up with a way to make it work in vlc. ffplay tmp.mp4 works ok. – Баяр Гончикжапов Nov 15 '20 at 3:00
  • So, the extraction of the jpg worked. But the result of the second command is only audio it seems. During conversion it said that h264 is used, but mediainfo /tmp/output.mp3 just says that Format MPEG Audio. My VLC is able to play h265 encoded videos though. I tried combining your first command of your second idea with the second command of your first idea. This gave me a JPEG video (see question edit) and also changed audio, even though I said "copy". I would like that audio is not changed. – Make42 Nov 16 '20 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.