Wednesday, August 20, 2014

Video is not streaming in Safari and Iphone

This may happen due to

RequestHeader unset Range
Header unset Accept-Ranges



>>Why do we need above configuration?
We do this to fix "Range header DoS vulnerability Apache HTTPD 1.3/2.x" issue. For details please check @ http://people.apache.org/~dirkx/CVE-2011-3192.txt



>>Does iPhone/iPad Safari require 'Accept-Ranges' header for video?
Yes. It requires these headers.Please find the apple documentation for the same.
"
https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariWebContent/CreatingVideoforSafarioniPhone/CreatingVideoforSafarioniPhone.html#//apple_ref/doc/uid/TP40006514-SW6
"



>>Any other solution?
Actually we can use another fix as suggested @ http://people.apache.org/~dirkx/CVE-2011-3192.txt . It is as below.

"
SetEnvIf Range (,.*?){5,} bad-range=1
RequestHeader unset Range env=bad-range
"

Here we are rejecting request when more than 5 ranges. But we can put very high value too.Please check these lines in same document.

"
The number 5 is arbitrary. Several 10's should not be an issue and may be
required for sites which for example serve PDFs to very high end eReaders
or use things such complex http based video streaming.
"

We will enable "Accept-Ranges" at .htaccess file for .mp4 videos only as below.

"

Header set Accept-Ranges bytes

"

other ffmpeg help link-
https://sites.google.com/site/linuxencoding/x264-ffmpeg-mapping
http://www.itbroadcastanddigitalcinema.com/ffmpeg_howto.html



Issue 1: Audio was not playing
Cause: Sample rate of the audio file did not match with the sample rate of the video.
Fix:
Check videos sample rate-- ffmpeg -i video.mp4
Use the flag -ar to specify Sample rate of audio.


Issue 2: Video was not streaming.
~~~~~: Video should be "Progressive" in nature. Video should provides its meta info at the beginning so that it playback as soon as possible.
Fix:
Use the following command:

qt-faststart output.mp4 output1.mp4

----------------------------

Final commands:
1) ffmpeg -i video.mp4 -i test.mp3 -vcodec copy -acodec aac -strict experimental -shortest output.mp4
2) qt-faststart output.mp4 output1.mp4

Wednesday, May 14, 2014

How to enable old closing position in Vim

Please add below lines in Vimrc


if has("autocmd")
   au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
         \| exe "normal! g'\"" | endif
endif

Saturday, March 29, 2014

virtualBox ERROR - Kernel driver not installed (rc = -1908)

1.This command will display modules of virtualbox
#cat /etc/sysconfig/modules/VirtualBox.modules
2.Now  i want fix this problem using ‘systemd-modules-load.service’.insert this in “virtualbox.conf”
## vi /usr/lib/modules-load.d/virtualbox.conf
#Loading VirtualBox modules
vboxdrv
vboxnetflt
vboxnetadp
and restart service
# systemctl restart systemd-modules-load.service # systemctl status systemd-modules-load.service
finally reboot and it will work fine. without any error!!!

Saturday, February 15, 2014

Stack Implementation using Linked List

#include<iostream>
#include<string>
using namespace std;

//class for each node of stack
class Node{
    private:
        Node* nextNode;
        string data;
    public:
        friend class Stack;
};

//Stack Class
class Stack {
    private:
        Node* top;

    public:
        Stack() {
            top = NULL;
        }
        int push(string data);
        string pop();
        int traverse();
};

//push operation - insertion at top
int Stack::push(string data) {
    Node* temptr = new Node();
    temptr->data = data;
    //if not adding first node
    if(top != NULL) {
        temptr->nextNode = top;
    } else {
        temptr->nextNode = NULL;
    }
    top = temptr;
    return 0;
}

//pop operation -- deletion from top
string Stack::pop() {
    string data = top->data;
    Node* temptr = top;
    top = top->nextNode;
    delete(temptr);
    return data;
}

//traverse the stack elements
int Stack::traverse() {
    Node* temptr = top;
    while(temptr != NULL){
        cout<< temptr->data <<endl;
        temptr = temptr->nextNode;
    }
    return 0;
}

int main() {
    Stack* so = new Stack();
    so->push("abc");
    so->push("def");
    so->push("ghi");
    cout<<"Display Stack::\t"<<endl;
    so->traverse();
    cout<<"Popped Item::\t"<<so->pop()<<endl;
    cout<<"Display Stack::\t"<<endl;
    so->traverse();
}

Monday, January 13, 2014

Send HTML mail with embedded Image using Javamail API

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class Testmail
{
   public static void main(String [] args)
   {
   
      // Recipient's email ID needs to be mentioned.
      String to = "golupant@gmail.com";
      //String to = "hemantvsn@gmail.com";
      //String to = "dileep.multimedia@gmail.com";

      // Sender's email ID
      String from = "test@gmail.com";

      // sending email from localhost
      String host = "localhost";

      // Get system properties
      Properties properties = System.getProperties();

      // Setup mail server   "smtp.gmail.com"
      properties.setProperty("server1.vo.com", host);

      // Get the default Session object.
      Session session = Session.getDefaultInstance(properties);

      try{
         // Create a default MimeMessage object.
         MimeMessage message = new MimeMessage(session);


//Create multipart message
MimeMultipart multipart = new MimeMultipart("related");


         // Set From: header field of the header.
         message.setFrom(new InternetAddress(from));

         // Set To: header field of the header.
         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));

         // Set Subject: header field
         message.setSubject("This is my Subject");


         //add text part
BodyPart bodyPart = new MimeBodyPart();
         String htmlText = "<html><body><img src='cid:myimageid' /><p>this is my html body</p></body></html>";
bodyPart.setContent(htmlText, "text/html");
multipart.addBodyPart(bodyPart);

//add image part
MimeBodyPart imagePart = new MimeBodyPart();
imagePart.setDataHandler(new DataHandler(new FileDataSource("/home/gauravp/mail/NSAwarnsofpowergridshutdown.jpg")));
imagePart.addHeader("Content-ID","<myimageid>");
multipart.addBodyPart(imagePart);

message.setContent(multipart);
       
         // Send message
         Transport.send(message);

         System.out.println("Sent message successfully....");
      }catch (Exception e) {
         e.printStackTrace();
      }
   }
}