Skip to content

[GOWS] - FFmpeg Thumbnail Generation Error in GOWS v1.0.26 #1746

Description

@bergpinheiro

Summary

Issue: Video thumbnail generation fails when processing video messages due to incorrect FFmpeg output format.

Severity: High - Affects all video message processing in GOWS engine

Version: GOWS v1.0.26

Environment: Docker container running on Debian 12, FFmpeg 5.1.8


Error Description

When the GOWS engine processes video messages (received or sent), it attempts to generate a 72px thumbnail using FFmpeg. The command fails with the following error:

[image2 @ 0x5564f0501e80] The specified filename 'pipe:' does not contain an image sequence pattern or a pattern is invalid.
[image2 @ 0x5564f0501e80] Use a pattern such as %03d for an image sequence or use the -update option (with -frames:v 1 if needed) to write a single image.

Root Cause

The FFmpeg command uses -f image2 format, which is designed for writing to files, not pipes. When the output is a pipe (pipe:), the image2 muxer expects a filename pattern (e.g., frame%03d.jpg) or the -update flag.

Problematic Command

ffmpeg -i pipe:0 -filter_complex [0]scale=72:-1[s0];[s0]select=gte(n\,0)[s1] -map [s1] -f image2 -vframes 1 pipe: -y

Issue: Using -f image2 with pipe: output


Complete Error Logs

2025/12/21 07:58PM 30 pid=7 hostname=27e7d92ff134 session=11_16_5551997658394 
name=WebhookSender id=402wek7mjgbw0os event.id=evt_01kd1j59kwn1dq0kckk3j06rx4 
event=message.ack url=https://chat.gowdy.com.br/webhooks/whatsapp/+5551997658394 
msg=Sending POST...

2025/12/21 07:58PM 30 pid=7 hostname=27e7d92ff134 session=11_16_5551997658394 
name=WebhookSender id=402wek7mjgbw0os event.id=evt_01kd1j59kwn1dq0kckk3j06rx4 
event=message.ack url=https://chat.gowdy.com.br/webhooks/whatsapp/+5551997658394 
msg=POST request was sent with status code: 200

2025/12/21 07:58PM 50 pid=7 hostname=27e7d92ff134 engine=gows 
msg=2025/12/21 19:58:23 compiled command: ffmpeg -i pipe:0 -filter_complex [0]scale=72:-1[s0];[s0]select=gte(n\,0)[s1] -map [s1] -f image2 -vframes 1 pipe: -y

2025/12/21 07:58PM 50 pid=7 hostname=27e7d92ff134 engine=gows 
msg=ffmpeg version 5.1.8-0+deb12u1 Copyright (c) 2000-2025 the FFmpeg developers
  built with gcc 12 (Debian 12.2.0-14+deb12u1)
  ...
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  ...

2025/12/21 07:58PM 50 pid=7 hostname=27e7d92ff134 engine=gows 
msg=Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:0':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : 4090302881254490
    encoder         : Lavf59.27.100
  Duration: 00:00:31.84, start: 0.000000, bitrate: N/A
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 360x640, 522 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.37.100 libx264
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]

2025/12/21 07:58PM 50 pid=7 hostname=27e7d92ff134 engine=gows 
msg=Stream mapping:
  Stream #0:0 (h264) -> scale:default
  select:output0 -> Stream #0:0 (mjpeg)

2025/12/21 07:58PM 50 pid=7 hostname=27e7d92ff134 engine=gows 
msg=[swscaler @ ...] deprecated pixel format used, make sure you did set range correctly

2025/12/21 07:58PM 50 pid=7 hostname=27e7d92ff134 engine=gows 
msg=Output #0, image2, to 'pipe:':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : 4090302881254490
    encoder         : Lavf59.27.100
  Stream #0:0: Video: mjpeg, yuvj420p(pc, bt709, progressive), 72x128, q=2-31, 200 kb/s, 30 fps, 30 tbn
    Metadata:
      encoder         : Lavc59.37.100 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A

2025/12/21 07:58PM 50 pid=7 hostname=27e7d92ff134 engine=gows 
msg=[image2 @ 0x5564f0501e80] The specified filename 'pipe:' does not contain an image sequence pattern or a pattern is invalid.
[image2 @ 0x5564f0501e80] Use a pattern such as %03d for an image sequence or use the -update option (with -frames:v 1 if needed) to write a single image.

2025/12/21 07:58PM 50 pid=7 hostname=27e7d92ff134 engine=gows 
msg=frame=    1 fps=0.0 q=2.7 size=N/A time=00:00:00.03 bitrate=N/A speed=2.77x    

2025/12/21 07:58PM 50 pid=7 hostname=27e7d92ff134 engine=gows 
msg=frame=    1 fps=0.0 q=2.7 Lsize=N/A time=00:00:00.03 bitrate=N/A speed=0.765x

Analysis

What Works

✅ FFmpeg is correctly installed (version 5.1.8)
✅ Video input is successfully read from pipe (H.264, 360x640, 31.84s)
✅ Audio stream is detected (AAC, stereo, 44.1kHz)
✅ Filter complex correctly scales video to 72x128
✅ Frame is successfully extracted and encoded to MJPEG

What Fails

❌ The image2 muxer rejects writing to a pipe without a filename pattern

Impact

  • Video thumbnails are not generated
  • WhatsApp messages may be incomplete (thumbnails are part of the protocol)
  • Webhook notifications may fail or send incomplete data
  • User experience is degraded (no video preview)

Proposed Solutions

Solution 1: Use image2pipe Format (Recommended)

Change the command from:

ffmpeg -i pipe:0 -filter_complex [0]scale=72:-1[s0];[s0]select=gte(n\,0)[s1] -map [s1] -f image2 -vframes 1 pipe: -y

To:

ffmpeg -i pipe:0 -filter_complex [0]scale=72:-1[s0];[s0]select=gte(n\,0)[s1] -map [s1] -vframes 1 -f image2pipe pipe: -y

Key changes:

  • Remove -f image2
  • Add -f image2pipe before the output
  • Reorder: -vframes 1 -f image2pipe pipe:

Why this works:
image2pipe is specifically designed for piping single images, unlike image2 which expects file sequences.


Solution 2: Add -update Flag

Change the command to:

ffmpeg -i pipe:0 -filter_complex [0]scale=72:-1[s0];[s0]select=gte(n\,0)[s1] -map [s1] -f image2 -update 1 -vframes 1 pipe: -y

Key change:

  • Add -update 1 flag

Why this works:
The -update 1 flag tells image2 to write a single image without requiring a pattern.


Solution 3: Use MJPEG Format Directly

Change the command to:

ffmpeg -i pipe:0 -filter_complex [0]scale=72:-1[s0];[s0]select=gte(n\,0)[s1] -map [s1] -vframes 1 -c:v mjpeg -f mjpeg pipe: -y

Key changes:

  • Explicitly specify codec: -c:v mjpeg
  • Use MJPEG format: -f mjpeg

Why this works:
MJPEG format naturally supports single-frame output to pipes.


Recommendation

Use Solution 1 (-f image2pipe) as it:

  • Is the most semantically correct for the use case
  • Has minimal changes to the existing command
  • Is well-documented and widely supported
  • Is the standard approach for piping images in FFmpeg

Code Location

The FFmpeg command is generated in the GOWS Go source code (repository: devlikeapro/gows, version v1.0.26).

The command is likely in code related to:

  • Thumbnail generation
  • Video message processing
  • Media preprocessing for WhatsApp protocol

Search for:

"scale=72:-1"
"-f image2"
"pipe:"

Testing

After applying the fix, verify with:

# Test command directly
echo "test_video.mp4" | ffmpeg -i pipe:0 -filter_complex [0]scale=72:-1[s0];[s0]select=gte(n\,0)[s1] -map [s1] -vframes 1 -f image2pipe pipe: -y > thumbnail.jpg

# Should create a valid 72px wide JPEG
file thumbnail.jpg  # Should show: JPEG image data

Additional Notes

Video Details from Error Log

  • Format: MP4 (H.264 video + AAC audio)
  • Resolution: 360x640 (portrait/vertical)
  • Duration: 31.84 seconds
  • Video Bitrate: 522 kb/s
  • Audio: Stereo, 44.1kHz, 128 kb/s
  • FPS: 30

Thumbnail Specification

  • Width: 72 pixels (fixed)
  • Height: Calculated automatically (maintains aspect ratio)
  • Resulting size: 72x128 pixels
  • Format: JPEG (MJPEG codec)
  • Purpose: WhatsApp message thumbnail/preview

patron:PRO

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions