Opened 6 years ago

Closed 5 years ago

#11457 closed Bug Report - General (Duplicate)

Mythweb unable to download video (not recordings) over 64.5mb

Reported by: Thomas C <notchicken@…> Owned by: Rob Smith
Priority: minor Milestone: unknown
Component: Plugin - MythWeb Version: 0.26-fixes
Severity: medium Keywords: mythweb video download
Cc: Ticket locked: no

Description

Hi,

Mythweb is unable to download vidoes that are over 64.5mb (recordings download/stream just fine)

I first thought it was a config error but just for the heck of it I put a 2.5mb .m4v file (under 64.5mb) in the vidoes/movies folder, clicked on the link in mythweb and it downloaded and started playing successfully.

Clicking on the video links in Safari it downloads 64.5mb for every movie, which are all over 1gb, the 2.5mb .m4v file downloads and plays successfully

Clicking on the video links in firefox however, returns an error page File not found Firefox can't find the file at http://192.168.0.100/mythweb/video/stream?Id=312. The 2.5mb .m4v file in mythweb downloads and plays just fine.

Videos mounted at /media/sdb/videos. .m4v files located on sdb under sdb/videos/Movies and sdb/videos/TV folders. The 2.5mb .m4v file downloads fine being placed in sdb/videos, sdb/videos/TV and sdb/videos/Movies

All videos play as expected in mythfrontend.

Attachments (1)

stream.php (2.0 KB) - added by awaldram@… 6 years ago.
fixed video stream.php

Download all attachments as: .zip

Change History (18)

comment:1 Changed 6 years ago by Rob Smith

Anything in the apache error logs?

comment:2 Changed 6 years ago by Thomas C <notchicken@…>

I have clicked on 5 different videos and the log shows:

[Tue Mar 26 16:07:08 2013] [error] [client 192.168.0.6] PHP Fatal error:  Allowed memory size of 67108864 bytes exhausted (tried to allocate 64491521 bytes) in /usr/share/mythtv/mythweb/modules/video/stream.php on line 66, referer: http://192.168.0.100/mythweb/video
[Tue Mar 26 16:07:12 2013] [error] [client 192.168.0.6] PHP Fatal error:  Allowed memory size of 67108864 bytes exhausted (tried to allocate 64491521 bytes) in /usr/share/mythtv/mythweb/modules/video/stream.php on line 66, referer: http://192.168.0.100/mythweb/video?path=%2FMovies
[Tue Mar 26 16:07:14 2013] [error] [client 192.168.0.6] PHP Fatal error:  Allowed memory size of 67108864 bytes exhausted (tried to allocate 64491521 bytes) in /usr/share/mythtv/mythweb/modules/video/stream.php on line 66, referer: http://192.168.0.100/mythweb/video?path=%2FMovies
[Tue Mar 26 16:08:00 2013] [error] [client 192.168.0.6] PHP Fatal error:  Allowed memory size of 67108864 bytes exhausted (tried to allocate 64491521 bytes) in /usr/share/mythtv/mythweb/modules/video/stream.php on line 66, referer: http://192.168.0.100/mythweb/video?path=%2FMovies
[Tue Mar 26 16:08:29 2013] [error] [client 192.168.0.6] PHP Fatal error:  Allowed memory size of 67108864 bytes exhausted (tried to allocate 64491521 bytes) in /usr/share/mythtv/mythweb/modules/video/stream.php on line 66, referer: http://192.168.0.100/mythweb/video?path=%2FMovies

comment:3 Changed 6 years ago by Thomas C <notchicken@…>

line 66 of /usr/share/mythtv/mythweb/modules/video/stream.ph is:

 readfile("http://$Master_Host:$port/Content/GetVideo?Id=".$vid_id);

file contents:

<?php
/**
 * Stream a music file
 *
 * @license     GPL
 *
 * @package     MythWeb
 * @subpackage  Music
/**/

// Yes, a db connection
    global $db;

// Pull video ID
    $vid_id = $_GET['Id'];

// Get filename
    list($fname) = $db->query_row('SELECT filename
                                     FROM videometadata
                                    WHERE intid = ?', $vid_id);

// Mime type
    switch (substr($fname, strrpos($fname, '.'))) {
        case 'mpg':
        case 'mpeg':
            $mime = 'video/mpeg';
            break;
        case 'mp4':
            $mime = 'video/mp4';
            break;
        case 'ogg':
        case 'ogm':
        case 'ogv':
            $mime = 'video/ogg';
            break;
        case 'qt':
            $mime = 'video/quicktime';
            break;
        case 'webm':
            $mime = 'video/webm';
            break;
        case 'mkv':
            $mime = 'video/x-matroska';
            break;
        case 'wmv':
            $mime = 'video/x-ms-wmv';
            break;
        case 'flv':
            $mime = 'video/x-flv';
            break;
        default:
            $mime = 'applicatoin/octet-stream';
    }
    header('Content-Type: '.$mime);

// Send the filename
    header('Content-Disposition: filename="'.$fname.'"');

// Send data via the backend
    $Master_Host = setting('MasterServerIP');
    $port = _or(get_backend_setting('BackendStatusPort', $Master_Host),
                get_backend_setting('BackendStatusPort'));
    if (stripos($Master_Host,':') !== false) {
        $Master_Host = '['.$Master_Host.']';
    }
    readfile("http://$Master_Host:$port/Content/GetVideo?Id=".$vid_id);

// Nothing else to do
    exit;

I've tried adding:

       case 'm4v':
            $mime = 'video/x-m4v';

to the file but made no difference.

comment:4 Changed 6 years ago by sphery

Looks like you need to disable output_buffering (which defaults to off in PHP, but may have been turned on by your distro) in your PHP configuration. Please ask for help on mythtv-users mailing list if you have questions about how to do so. If this fixes the issue, please report back, here, and we will close the ticket.

comment:5 Changed 6 years ago by sphery

Status: newinfoneeded_new

comment:6 Changed 6 years ago by Thomas C <notchicken@…>

locate php.ini
shows

/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini

I changed
output_buffering = 4096
to
output_buffering = Off
in both of the files then rebooted

still cannot download the videos

comment:7 Changed 6 years ago by phillip.stanton@…

This is the problem code in /usr/share/mythtv/mythweb/modules/video/stream.php it does not chunk the data like the recordings stream does.

Send data via the backend

$Master_Host = setting('MasterServerIP'); $port = _or(get_backend_setting('BackendStatusPort?', $Master_Host),

get_backend_setting('BackendStatusPort?'));

if (stripos($Master_Host,':') !== false) {

$Master_Host = '.$Master_Host.?';

} readfile("http://$Master_Host:$port/Content/GetVideo?Id=".$vid_id);

comment:8 Changed 6 years ago by sphery

http://php.net/manual/en/function.readfile.php

"readfile() will not present any memory issues, even when sending large files, on its own. If you encounter an out of memory error ensure that output buffering is off with ob_get_level()."

Keep looking for something that /is/ enabling output_buffering (and make sure you've properly restarted everything).

comment:9 Changed 6 years ago by joe.yasi@…

I'm also running into this problem on Ubuntu 13.04. Output_buffering is turned off. ob_get_level() returns 0 and phpinfo() shows output_buffering no value. What is going on here?

comment:10 Changed 6 years ago by joe.yasi@…

Ah, there is a ob_start(); in the mythweb init.php file that is causing this. If I flush the output buffer before the readfile, this works:

while (ob_get_level()) {

ob_end_flush();

}

comment:11 Changed 6 years ago by paulh

Status: infoneeded_newnew

Changed 6 years ago by awaldram@…

Attachment: stream.php added

fixed video stream.php

comment:12 Changed 6 years ago by awaldram@…

See attachment

correct file type parsing add avi header type video/x-msvideo correct spelling of application clean object buffer

comment:13 Changed 6 years ago by Thomas C <notchicken@…>

Thank you thank you thank you awaldram :-D I've updated the stream.php file, rebooted and its all working as expected :-)

comment:14 Changed 6 years ago by Karl Egly

Component: MythTV - GeneralPlugin - MythWeb
Owner: set to Rob Smith

comment:15 Changed 5 years ago by slavo.fabian@…

It does not function for me.

I have upgraded mythbuntu 0.25 - there is no stream.php but I can see video in web browser

to 0.26 or 0.27 - new function stream.php but video in web browser do not function.

I changed to your new script, but it did not help me.

0.25 has good video output but bad imdb support 0.26 or 0.27 have better imdb support but no video output.

in all version of mythbuntu you will have to repair some scripts or database to use imdb :-(

I hope 0.28 will be better.

comment:16 Changed 5 years ago by Frank Phillips <fphillips81@…>

OP has version 0.26-fixes. This was fixed in mythweb 0.27, same solution as what he proposes. slavo.fabian should ask on mythtv-users or forum for help, not this bug.

Dupe of #11310

comment:17 Changed 5 years ago by Rob Smith

Resolution: Duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.