自适应比特率流在NGINX服务器中的nginx-vod模块中不起作用

时间:2015-10-15 11:47:04

标签: nginx streaming winginx

我已经安装了Nginx并使用nginx-vod-module为adaprive流配置了VOD。在请求master.m3u8文件时,我得到了为不同网络带宽服务的相同ts文件。

master.m3u8文件包​​含以下内容:

public class Adapter extends
    RecyclerView.Adapter<Adapter.ViewHolder> {
private LruCache<String, Bitmap> bitmapCache;
Context context;


public static class ViewHolder extends RecyclerView.ViewHolder {
    public TextView title;
    public TextView year;
    public TextView type;
    public ImageView poster;

    public ViewHolder(View itemView) {
        super(itemView);
        title = (TextView) itemView.findViewById(R.id.txt_title);
        year = (TextView) itemView.findViewById(R.id.txt_year);
        type = (TextView) itemView.findViewById(R.id.txt_rating);
        poster = (ImageView) itemView.findViewById(R.id.imageView);

    }

}

private List<Movie> mList;

public Adapter(List<Movie> mList) {
    this.mList = mList;
    int numImages = 4 * 1024 * 1024;
    this.bitmapCache = new LruCache<String, Bitmap>(numImages) {
        @Override
        protected int sizeOf(String key, Bitmap value) {
            // this is how to calculate a bitmap size in bytes.
            // (bytes-in-a-row * height)
            return value.getRowBytes() * value.getHeight();
        }
    };
}

@Override
public Adapter.ViewHolder onCreateViewHolder
        (ViewGroup parent, int viewType) {
    Context context = parent.getContext();
    LayoutInflater inflater = LayoutInflater.from(context);
    View movieView = inflater.inflate(R.layout.card_view, parent, false);
    ViewHolder viewHolder = new ViewHolder(movieView);




    return viewHolder;
}

@Override
public void onBindViewHolder
        (Adapter.ViewHolder holder, int position) {
    Movie movie = mList.get(position);
    holder.title.setText(movie.getTitle());
    holder.year.setText(movie.getYear());
    holder.type.setText(movie.getType());
    holder.poster.setVisibility(View.INVISIBLE);
    GetImageTask task = new GetImageTask(movie, holder);
    task.execute(movie.getPoster_url());

}

@Override
public int getItemCount() {
    return mList.size();
}

class GetImageTask extends AsyncTask<String, Void, Bitmap> {


    private final Movie movie;
    private final ViewHolder holder;

    public GetImageTask(Movie movie, ViewHolder holder) {
        this.movie = movie;
        this.holder = holder;
    }

    @Override
    protected Bitmap doInBackground(String... params) {
        //download:
        String address = params[0];
        Bitmap bitmap = HttpHandler.getBitmap(address, null);

        //save it in the cache for later:
        if (bitmap != null) {
            bitmapCache.put(address, bitmap);
        }
        return bitmap;
    }

    @Override
    protected void onPostExecute(Bitmap result) {

        if (movie.equals(holder.poster)) {
            holder.poster.setVisibility(View.VISIBLE);
            holder.poster.setImageBitmap(result);
        }
    }
}

Nginx配置是:

 #EXTM3U
 #EXT-X-STREAM-INF:PROGRAMID=1,BANDWIDTH=1914317,RESOLUTION=1280x544,CODECS="avc1.64001f,mp4a.40.2"
  http://localhost/content/Input.mp4/index-v1-a1.m3u8

如何使用nginx-vod-module启用自适应比特率,验证它的最佳方法是什么?

1 个答案:

答案 0 :(得分:1)

  1. 您使用不同的分辨率/比特率编码Input.mp4的多个版本。纵横比应该相同。例如:Input_high.mp4Input_low.mp4

  2. 您可以编辑主m3u8播放列表,并使用其特定的比特率和分辨率添加每个节目:

    #EXTM3U
    #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=...,RESOLUTION=...,CODECS="..."
    /content/Input_low.mp4.m3u8
    #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=...,RESOLUTION=...,CODECS="..."
    /content/Input_high.mp4.m3u8
    
  3. nginx-vod-module收到filename.mp4.m3u8请求时,它会自动为filename.mp4细分HLS并为您创建播放列表。例如:/content/Input_low.mp4.m3u8

  4. /content/Input_low.mp4