-2

Am trying to create a video clip using .jpg images and ffmpeg, am creating .jpg images as below:

  $str=$_REQUEST['data_array'];//gets the base64 encoded image data;  
  $count =$_REQUEST['count'];//gets number of images i've to create;
  $edited_str=substr($str,23,strlen($str)-1);// 
  $edited_str=base64_decode($edited_str);  
  $f=fopen("Images/temp".$count.".jpg","w");//am creating temp.jpg file
  fwrite($f,$edited_str);//placing my decoded data into file
  fclose($f); 

are the images am creating above different from normal .jpg images?

user1070642
  • 273
  • 1
  • 5
  • 15
  • 2
    You mean, you are stitching multiple JPG files together and expecting them to animate? I doubt that'll work. Can you use ImageMagick? – Pekka Dec 07 '11 at 12:11
  • 2
    @Pekka - You doubt? It won't ;-) – Flukey Dec 07 '11 at 12:12
  • 2
    @Flukey bizarrely, this is [possible with MP3 files.](http://stackoverflow.com/questions/3992311/merge-two-mp3-php/3992378#3992378) Hence my expression of only doubt (instead of an unequivocal "are you crazy?") :) – Pekka Dec 07 '11 at 12:13
  • don't use `$_REQUEST`... – matino Dec 07 '11 at 12:21
  • ha am creating a video using ffmpeg and php,now the problem is if i use .jpg images those are not created from this script then am able to crate video but if i use images from the above php code then it's not working – user1070642 Dec 07 '11 at 12:27
  • How $_REQUEST can solve my problem – user1070642 Dec 07 '11 at 12:32
  • Offtopic: `I Am`, not `Am`. If you prefer shorthands, it's `I'm`. – N.B. Dec 07 '11 at 12:43
  • Not using $_REQUEST is a different problem. If you are sending the information via get, it most likely will get cut off (due to size) and should be sent via POST (among other issues). Did you try not cutting off the front of the base64 coding to make sure that wasn't it? .. Granted REQUEST is POST and GET (and cookie), but you shouldn't allow both in this case (or most cases)to prevent something unwanted. – craniumonempty Dec 07 '11 at 12:45
  • Since you are only removing added data, the base64 encoding should be the same. Test the data before you send, then test again after you send to make sure you are getting the correct data. You don't have to read every line, just the size, front and back. Make sure it's encoded the same as php_encode would do it. Is it coming from another server? Oh, also, how big are the files. One person had a problem with decode and large files (>7MB) try $decodedstring=base64_decode(chunk_split($encodedstring)); – craniumonempty Dec 07 '11 at 13:07
  • Check my last edit in the post on converting spaces to pluses, because that might actually be the problem given that we don't know how the data is being sent. – craniumonempty Dec 07 '11 at 13:32
  • it's coming from the same server ,also i've checked that data size it is same and my image would be max of 20kb only – user1070642 Dec 07 '11 at 14:36
  • Did you test it with a smaller image? If you did can you post the code and what the base64 looks like for the test image, so we can help more? Kind of in the dark about where to go if there isn't more information... also, did you check to see if it was adding " " instead of "+"? – craniumonempty Dec 12 '11 at 14:43

1 Answers1

0

This line:

$edited_str=substr($str,23,strlen($str)-1);

makes it different. If this is the full base64 sting of the file, then this cuts it up and corrupts it. Maybe you are adding some stuff on the front.

If you are just removing stuff from the front that was added, then it should be the same as the original file that was encoded with base64.

If you want to get the information this way from another page, I suggest using $_POST as opposed to $_REQUEST for a number of reasons.

EDIT: I wouldn't say video manipulation in php is impossible. I think there is even a toolkit... here's one:

http://phpvideotoolkit.sourceforge.net/

which states:

It can perform video format conversion, extract video frames into separate image files, and assemble a video stream from a set of separate video images.

Haven't tested it, but plan to try it out one day.

EDIT2: On the php site, there were some issues that you could try, but to help more, there needs to be more information. Check with a file directly to make sure it's being sent and decrypted properly.

I haven't got to test any of these yet.

One piece of advice was for large files use:

$decodedstring=base64_decode(chunk_split($encodedstring));

Another was if you use javascript canvas.toDataURL() then you need to convert spaces back to pluses:

$encodedData = str_replace(' ','+',$encodedData);
$decocedData = base64_decode($encodedData);

http://php.net/manual/en/function.base64-decode.php

craniumonempty
  • 3,525
  • 2
  • 20
  • 18
  • am removing 'data:image/jpeg;base64,' using the line above to decode it otherwise it wont create an image what's my question is are those images from above php code different from normal images? – user1070642 Dec 07 '11 at 13:00
  • When data is encoded/decoded base64, it should be the same (well, I've never had a problem with it, including jpeg's). The problem is probably something else. Also, like N.B. said, it's either "I am" or "I'm" in English. "am" can be confusing. – craniumonempty Dec 07 '11 at 14:15