Video upload fails #430

Closed
opened 2026-10-04 23:58:03 +02:00 by adam · 7 comments
Owner

Uploading a video clip to Piwigo 2.8.0 results in the following error:

**REQUEST**:
POST http://piwigo28.int/ws.php?method=pwg.images.add&format=json HTTP/1.1
Accept: */*
Cookie: pwg_id=8arvv47c2tha51v2n20cvpj2t4
Content-Type: application/x-www-form-urlencoded
Content-Length: 261
User-Agent: Adobe Photoshop Lightroom
Host: piwigo28.int
Pragma: no-cache

categories=2&file_sum=a73c256036477811d94521561c2d36ce&comment=&author=&tag_ids=1&pwg_token=56c47f9a677e25f99bfcf19fde4f8201&name=&original_sum=a73c256036477811d94521561c2d36ce&date_creation=2014-09-01%2022%3A49%3A37&level=0&resize=0&original_filename=-9035.mp4

**RESPONSE**:

HTTP/1.1 200 OK
Date: Sun, 03 Apr 2016 19:50:07 GMT
Server: Apache/2.2.22 (Win32) mod_ssl/2.2.22 OpenSSL/0.9.8t PHP/5.3.29
X-Powered-By: PHP/5.3.29
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 584
Content-Type: text/plain; charset=utf-8

<pre><br />
<b>Warning</b>:  [mysql error 1366] Incorrect integer value: '' for column 'width' at row 1

INSERT INTO piwigo_images
  (file,name,date_available,path,filesize,width,height,md5sum,added_by,rotation,level)
  VALUES('-9035.mp4','-9035','2016-04-03 15:50:07','./upload/2016/04/03/20160403155007-a73c2560.mp4','2962','','','a73c256036477811d94521561c2d36ce','1','0','0') in <b>D:\WWW_HOME\piwigo28.com\include\dblayer\functions_mysqli.inc.php</b> on line <b>832</b><br />
</pre>{"stat":"ok","result":{"image_id":0,"url":"http:\/\/piwigo28.int\/picture.php?\/0\/category\/2"}}
Uploading a video clip to Piwigo 2.8.0 results in the following error: ``` **REQUEST**: POST http://piwigo28.int/ws.php?method=pwg.images.add&format=json HTTP/1.1 Accept: */* Cookie: pwg_id=8arvv47c2tha51v2n20cvpj2t4 Content-Type: application/x-www-form-urlencoded Content-Length: 261 User-Agent: Adobe Photoshop Lightroom Host: piwigo28.int Pragma: no-cache categories=2&file_sum=a73c256036477811d94521561c2d36ce&comment=&author=&tag_ids=1&pwg_token=56c47f9a677e25f99bfcf19fde4f8201&name=&original_sum=a73c256036477811d94521561c2d36ce&date_creation=2014-09-01%2022%3A49%3A37&level=0&resize=0&original_filename=-9035.mp4 **RESPONSE**: HTTP/1.1 200 OK Date: Sun, 03 Apr 2016 19:50:07 GMT Server: Apache/2.2.22 (Win32) mod_ssl/2.2.22 OpenSSL/0.9.8t PHP/5.3.29 X-Powered-By: PHP/5.3.29 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-Length: 584 Content-Type: text/plain; charset=utf-8 <pre><br /> <b>Warning</b>: [mysql error 1366] Incorrect integer value: '' for column 'width' at row 1 INSERT INTO piwigo_images (file,name,date_available,path,filesize,width,height,md5sum,added_by,rotation,level) VALUES('-9035.mp4','-9035','2016-04-03 15:50:07','./upload/2016/04/03/20160403155007-a73c2560.mp4','2962','','','a73c256036477811d94521561c2d36ce','1','0','0') in <b>D:\WWW_HOME\piwigo28.com\include\dblayer\functions_mysqli.inc.php</b> on line <b>832</b><br /> </pre>{"stat":"ok","result":{"image_id":0,"url":"http:\/\/piwigo28.int\/picture.php?\/0\/category\/2"}} ``` <!-- github-sync-id:145534518 -->
adam closed this issue 2026-10-04 23:58:04 +02:00
Author
Owner

I was unable to reproduce this issue on piwigo.com, however it happens consistently on my local machine, so I went to debug the code and found the issue. It starts with pwg_image_infos() returning null values for width and height when the uploaded file is a video clip.
Second, single_insert() converts null values to empty strings. This causes the insert to fail because the database expects integer values or nulls.

I believe the following change in single_insert() is in order:

      if ($value === '')
      {
        $query .= 'NULL';
      }

replace with

      if ($value === '' || is_null($value))
      {
        $query .= 'NULL';
      }

That way null values will remain NULLs.

And finally, a couple of words about using ffmpeg. You are constructing the full path as

$ffmpeg = $conf['ffmpeg_dir'].'ffmpeg';

which will cause if the configuration parameter doesn't contain a trailing slash.
I would like to suggest a more flexible approach:

  $exe = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')? 'ffmpeg.exe' : 'ffmpeg';
  $ffmpeg = realpath(join('/', array($conf['ffmpeg_dir'], $exe)));
  if (!$ffmpeg) {
    return null;
  }

That way the path can be specified with or without the trailing slash. This also gives you the opportunity to log a message if the executable is not there. Currently exec() fails silently if the path is incorrect, and there is no way to determine what caused the failure (or even know that ffmpeg didn't run).

I was unable to reproduce this issue on piwigo.com, however it happens consistently on my local machine, so I went to debug the code and found the issue. It starts with pwg_image_infos() returning null values for width and height when the uploaded file is a video clip. Second, single_insert() converts null values to empty strings. This causes the insert to fail because the database expects integer values or nulls. I believe the following change in single_insert() is in order: ``` if ($value === '') { $query .= 'NULL'; } ``` replace with ``` if ($value === '' || is_null($value)) { $query .= 'NULL'; } ``` That way null values will remain NULLs. And finally, a couple of words about using ffmpeg. You are constructing the full path as ``` $ffmpeg = $conf['ffmpeg_dir'].'ffmpeg'; ``` which will cause if the configuration parameter doesn't contain a trailing slash. I would like to suggest a more flexible approach: ``` $exe = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')? 'ffmpeg.exe' : 'ffmpeg'; $ffmpeg = realpath(join('/', array($conf['ffmpeg_dir'], $exe))); if (!$ffmpeg) { return null; } ``` That way the path can be specified with or without the trailing slash. This also gives you the opportunity to log a message if the executable is not there. Currently exec() fails silently if the path is incorrect, and there is no way to determine what caused the failure (or even know that ffmpeg didn't run). <!-- github-comment-id:215848417 -->
Author
Owner

@vvinogradsky can you elaborate a bit on your fix ? I have the same problem, but changing the test in single_insert() does not change anything. I don't really know how to debug and I don't want to clobber my db with invalid data when testing :)

@vvinogradsky can you elaborate a bit on your fix ? I have the same problem, but changing the test in `single_insert()` does not change anything. I don't really know how to debug and I don't want to clobber my db with invalid data when testing :) <!-- github-comment-id:216460890 -->
Author
Owner

I've updated to piwigo 2.8.1 and still have the same error. Even applying the little fix above (in include/dblayer/functions_mysql.inc.php) does not change anything.

I've updated to piwigo 2.8.1 and still have the same error. Even applying the little fix above (in include/dblayer/functions_mysql.inc.php) does not change anything. <!-- github-comment-id:217088005 -->
Author
Owner

Ok, I've found why the fix was not working: I must be using mysqli, not mysql, so the file to edit is include/dblayer/functions_mysql.inc.php.

Ok, I've found why the fix was not working: I must be using mysqli, not mysql, so the file to edit is include/dblayer/functions_mysql.inc.php. <!-- github-comment-id:217230494 -->
Author
Owner

Awesome! I am glad you found the solution. Too bad there is no official fix for this.

Awesome! I am glad you found the solution. Too bad there is no official fix for this. <!-- github-comment-id:217267055 -->
Author
Owner

I've made a PR for quicker merge in piwigo :)

I've made a PR for quicker merge in piwigo :) <!-- github-comment-id:217348327 -->
Author
Owner

Huge +1 for getting this fix into Piwigo, and video upload support into @vvinogradsky 's lightroom publisher plugin.

Huge +1 for getting this fix into Piwigo, and video upload support into @vvinogradsky 's lightroom publisher plugin. <!-- github-comment-id:230589222 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#430