[FFmpeg-user] Encoding a stream of base64 image strings into video

Yotam Laufer y at utab.com
Tue Jul 14 10:31:11 CEST 2015


Hello All,

I’ve been searching for an answer for quite some time and hopefully you will have the answer for me. Consider that I have used ffmpeg in the past, but I am certainly still a newbie.

I have a routine that captures a stream of images, pipes them to ffmpeg and outputs a video file. This works very well and I am happy with the result. The host that captures the images returns them as a base64 string, which I then convert to a binary image (png or jpeg) and pipe to ffmpeg. This conversion takes some time slowing down my process significantly. I would like to pipe the base64 string into ffmpeg, skipping the conversion stage on my runtime to see if that optimizes the system but I am unable to get it to work.

This is the command I use now that works very well with binary images:

ffmpeg -y -framerate 60 -f image2pipe -i pipe: -i <AUDIO FILE> -pix_fmt yuv420p -vcodec libx264 -preset veryslow -profile main -qp 1 -shortest -movflags +faststart -tune animation <OUTPUTFILE>

On a single image I managed to use a base64 string the same way it is specified here: https://www.ffmpeg.org/ffmpeg-protocols.html#data <https://www.ffmpeg.org/ffmpeg-protocols.html#data> 

ffmpeg -i "data:image/gif;base64,R0lGODdhCAAIAMIEAAAAAAAA//8AAP//AP///////////////ywAAAAACAAIAAADF0gEDLojDgdGiJdJqUX02iB4E8Q9jUMkADs=" smiley.png

So my question is: how I can pipe base64 strings into stdin?

Here is the console output from ffmpeg:

ffmpeg -loglevel debug -y -framerate 60 -f image2pipe -i pipe: -i /Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA -pix_fmt yuv420p -vcodec libx264 -preset veryslow -profile main -qp 1 -shortest -movflags +faststart -tune animation /Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA.mp4

ffmpeg version 2.6.3 Copyright (c) 2000-2015 the FFmpeg developers

  built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)

  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libvorbis --enable-vda

  libavutil      54. 20.100 / 54. 20.100

  libavcodec     56. 26.100 / 56. 26.100

  libavformat    56. 25.101 / 56. 25.101

  libavdevice    56.  4.100 / 56.  4.100

  libavfilter     5. 11.102 /  5. 11.102

  libavresample   2.  1.  0 /  2.  1.  0

  libswscale      3.  1.101 /  3.  1.101

  libswresample   1.  1.100 /  1.  1.100

  libpostproc    53.  3.100 / 53.  3.100

  Splitting the commandline.

  Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.

Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.

Reading option '-framerate' ...

FFMPEG STDERR:  matched as AVOption 'framerate' with argument '60'.

Reading option '-f' ... matched as option 'f' (force format) with argument 'image2pipe'.

Reading option '-i' ... matched as input file with argument 'pipe:'.

Reading option '-i' ... matched as input file with argument '/Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA'.

Reading option '-pix_fmt' ... matched as option 'pix_fmt' (set pixel format) with argument 'yuv420p'.

Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'libx264'.

Reading option '-preset' ... matched as AVOption 'preset' with argument 'veryslow'.

Reading option '-profile' ... matched as option 'profile' (set profile) with argument 'main'.

Reading option '-qp' ... matched as AVOption 'qp' with argument '1'.

Reading option '-shortest' ... matched as option 'shortest' (finish encoding within shortest input) with argument '1'.

Reading option '-movflags' ... matched as AVOption 'movflags' with argument '+faststart'.

Reading option '-tune' ...

matched as AVOption 'tune' with argument 'animation'.

Reading option '/Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA.mp4' ... matched as output file.

Finished splitting the commandline.

Parsing a group of options: global .

Applying option loglevel (set logging level) with argument debug.

Applying option y (overwrite output files) with argument 1.

Successfully parsed a group of options.

Parsing a group of options: input file pipe:.

Applying option f (force format) with argument image2pipe.

Successfully parsed a group of options.

Opening an input file: pipe:.



[image2pipe @ 0x7f8385025000] Before avformat_find_stream_info() pos: 0 bytes read:8192 seeks:0

[image2pipe @ 0x7f8385025000] parser not found for codec none, packets or times may be invalid.

[image2pipe @ 0x7f8385025000] Could not find codec parameters for stream 0 (Video: none, none): unknown codec

Consider increasing the value for the 'analyzeduration' and 'probesize' options

[image2pipe @ 0x7f8385025000] After avformat_find_stream_info() pos: 0 bytes read:8192 seeks:0 frames:0

pipe:: could not find codec parameters

Input #0, image2pipe, from 'pipe:':

  Duration: N/A, bitrate: N/A

    Stream #0:0, 0, 1/60: Video: none, none, 60 tbr, 60 tbn, 60 tbc

    Successfully opened the file.

    Parsing a group of options: input file /Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA.

Successfully parsed a group of options.

Opening an input file: /Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA.

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8384801600] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8384801600] ISO: File Type Major Brand: isom

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8384801600] Before avformat_find_stream_info() pos: 6443352 bytes read:102719 seeks:1

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8384801600] All info found

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8384801600] After avformat_find_stream_info() pos: 780 bytes read:135487 seeks:2 frames:1

Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA':

  Metadata:

    major_brand     : isom

    minor_version   : 512

    compatible_brands: isomiso2mp41

    creation_time   : 2014-11-26 12:46:43

    encoder         : Lavf56.1.0

  Duration: 00:03:21.06, start: 0.000000, bitrate: 256 kb/s

    Stream #1:0(und), 1, 1/44100: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 253 kb/s (default)

    Metadata:

      creation_time   : 2014-11-26 12:46:43

      handler_name    : SoundHandler

      Successfully opened the file.

      Parsing a group of options: output file /Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA.mp4.

Applying option pix_fmt (set pixel format) with argument yuv420p.

Applying option vcodec (force video codec ('copy' to copy stream)) with argument libx264.

Applying option profile (set profile) with argument main.

Please use -profile:a or -profile:v, -profile is ambiguous

Applying option shortest (finish encoding within shortest input) with argument 1.

Successfully parsed a group of options.

Opening an output file: /Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA.mp4.

Codec AVOption preset (Set the encoding preset (cf. x264 --fullhelp)) specified for output file #0 (/Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA.mp4) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.

Codec AVOption qp (Constant quantization parameter rate control method) specified for output file #0 (/Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA.mp4) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.

Codec AVOption tune (Tune the encoding params (cf. x264 --fullhelp)) specified for output file #0 (/Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA.mp4) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.

Codec AVOption profile () specified for output file #0 (/Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA.mp4) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.

Successfully opened the file.

detected 8 logical cores

[graph 0 input from stream 1:0 @ 0x7f8382e00860] Setting 'time_base' to value '1/44100'

[graph 0 input from stream 1:0 @ 0x7f8382e00860] Setting 'sample_rate' to value '44100'

[graph 0 input from stream 1:0 @ 0x7f8382e00860] Setting 'sample_fmt' to value 'fltp'

[graph 0 input from stream 1:0 @ 0x7f8382e00860] Setting 'channel_layout' to value '0x3'

[graph 0 input from stream 1:0 @ 0x7f8382e00860] tb:1/44100 samplefmt:fltp samplerate:44100 chlayout:0x3

[audio format for output stream 0:0 @ 0x7f8382e00f00] Setting 'sample_fmts' to value 's16'

[audio format for output stream 0:0 @ 0x7f8382e00f00] Setting 'sample_rates' to value '96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025|8000|7350'

[audio format for output stream 0:0 @ 0x7f8382e00f00] auto-inserting filter 'auto-inserted resampler 0' between the filter 'Parsed_anull_0' and the filter 'audio format for output stream 0:0'

[AVFilterGraph @ 0x7f8382c0f0e0] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed

[auto-inserted resampler 0 @ 0x7f8382e017e0] ch:2 chl:stereo fmt:fltp r:44100Hz -\u003E ch:2 chl:stereo fmt:s16 r:44100Hz

Output #0, mp4, to '/Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA.mp4':

  Metadata:

    encoder         : Lavf56.25.101

    Stream #0:0(und), 0, 1/44100: Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, s16, 128 kb/s (default)

    Metadata:

      creation_time   : 2014-11-26 12:46:43

      handler_name    : SoundHandler

      encoder         : Lavc56.26.100 libvo_aacenc

      Stream mapping:

  Stream #1:0 -\u003E #0:0 (aac (native) -\u003E aac (libvo_aacenc))



size=     434kB time=00:00:27.73 bitrate= 128.2kbits/s 
size=     833kB time=00:00:53.23 bitrate= 128.1kbits/s
size=    1240kB time=00:01:19.28 bitrate= 128.1kbits/s    
size=    1655kB time=00:01:45.86 bitrate= 128.1kbits/s    
size=    1655kB time=00:01:45.86 bitrate= 128.1kbits/s    
size=    2060kB time=00:02:11.78 bitrate= 128.1kbits/s    
size=    2462kB time=00:02:37.53 bitrate= 128.0kbits/s 
size=    2860kB time=00:03:03.00 bitrate= 128.0kbits/s 

[output stream 0:0 @ 0x7f8382e00d00] EOF on sink link output stream 0:0:default.

No more output streams to write to, finishing.

[libvo_aacenc @ 0x7f8383011800] Trying to remove 448 more samples than there are in the queue

[mp4 @ 0x7f8383010c00] Starting second pass: moving the moov atom to the beginning of the file   

AVIOContext @ 0x7f8384102060] Statistics: 3217772 bytes read, 0 seeks

size=    3177kB time=00:03:21.07 bitrate= 129.4kbits/s    

video:0kB audio:3142kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.101460%

Input file #0 (pipe:):

  Input stream #0:0 (video): 0 packets read (0 bytes); 

  Total: 0 packets (0 bytes) demuxed

  Input file #1 (/Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA):

  Input stream #1:0 (audio): 8659 packets read (6373357 bytes); 8659 frames decoded (8866816 samples); 

  Total: 8659 packets (6373357 bytes) demuxed

  Output file #0 (/Users/yotamlaufer/Work/video-renderer-processor/tmp/output/M11SvDtPBhA.mp4):

  Output stream #0:0 (audio): 8659 frames encoded (8866816 samples); 8661 packets muxed (3217728 bytes); 

  Total: 8661 packets (3217728 bytes) muxed

  8659 frames successfully decoded, 0 decoding errors

  [AVIOContext @ 0x7f8382c0ef20] Statistics: 32 seeks, 8784 writeouts

[AVIOContext @ 0x7f83841022a0] Statistics: 8192 bytes read, 0 seeks

[AVIOContext @ 0x7f83840133e0] Statistics: 6492479 bytes read, 2 seeks



Best regards,
Yotam Laufer





More information about the ffmpeg-user mailing list