Joyber 发布的文章

本文参考自:https://www.jianshu.com/p/94a1759ceb34
官方参考文章:https://trac.ffmpeg.org/wiki/CompilationGuide/Centos

原文中有仓库不能访问,替换成了国内可用的仓库地址

ffmpeg 4.1 编译安装后,可以得到ffmpeg,ffprobe,ffplay。ffmpeg 4.0 开始删掉了ffserver。
FFmpeg 3.4 编译安装后,可以得到ffmpeg,ffprobe,ffplay,ffserver

如果你已经安装了最新版gcc,gcc-c++,cmake,make的话,请忽略安装这些程序!

yum install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel harfbuzz-devel
mkdir ~/ffmpeg_sources

升级开发工具

yum install centos-release-scl -y
yum install devtoolset-7-toolchain -y
scl enable devtoolset-7 bash

CMAKE,安装最新版本(非必须,但推荐)

cd ~/ffmpeg_sources
curl -O -L https://src.fedoraproject.org/lookaside/extras/cmake/cmake-3.13.2.tar.gz/sha512/da095d483326ed379bfc8fa54e95db3426149ab923479a757149a4aed5c90693c0244bc2c9550cf4b64385f5003ee2060fea1698d989ed13bd0198e718c40903/cmake-3.13.2.tar.gz
tar xzvf cmake-3.13.2.tar.gz
cd cmake-3.13.2
./bootstrap --prefix=/usr/local
make
make install

ln -s -f /usr/local/bin/ccmake /usr/bin/
ln -s -f /usr/local/bin/cmake /usr/bin/
ln -s -f /usr/local/bin/ctest /usr/bin/
ln -s -f /usr/local/bin/cpack /usr/bin/

文中有用到 mercurial (hg),如果你的环境python不是2.x版本,需要执行下面这步

mercurial (hg), 只支持python2.x版本,如果你的系统上安装了多个python版本,且前提条件是在命令行输入python2的时候,执行的是2.x版本的python

whereis hg 查看hg位置
vi /usr/bin/hg 进入编辑模式
把第一行代码改成如下: #!/usr/bin/python2
保存退出
# hg --version

Mercurial Distributed SCM (version 4.0-rc)
(see https://mercurial-scm.org for more information)

Copyright (C) 2005-2016 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ffplay使用sdl作为窗体,需要先安装SDL2,如果不需要ffplay可以跳过这个步骤!

yum install libXext-devel
cd ~/ffmpeg_sources
hg clone https://hg.libsdl.org/SDL SDL
cd SDL
mkdir build
cd build
../configure
make && make install
ln -s /usr/local/lib/libSDL2.so /usr/lib64/libSDL2.so
strings /lib64/libSDL2.so | grep GLIBC_

Nasm

cd ~/ffmpeg_sources
curl -O -L https://www.nasm.us/pub/nasm/releasebuilds/2.14/nasm-2.14.tar.bz2
tar xjvf nasm-2.14.tar.bz2
cd nasm-2.14
./autogen.sh
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install

Yasm

cd ~/ffmpeg_sources
curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xzvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install

libx264

cd ~/ffmpeg_sources
#git clone --depth 1 http://git.videolan.org/git/x264
git clone --depth 1 https://gitee.com/ibaoger/x264.git
cd x264
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static
make
make install

libx265

cd ~/ffmpeg_sources
#hg clone https://bitbucket.org/multicoreware/x265
git clone --depth 1 https://gitee.com/pengwukui/x265.git
cd ~/ffmpeg_sources/x265/build/linux
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source
make
make install
cp ~/ffmpeg_build/bin/x265 ~/bin/

libfdk_aac

cd ~/ffmpeg_sources
git clone --depth 1 https://github.com/mstorsjo/fdk-aac
cd fdk-aac
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install

libmp3lame

cd ~/ffmpeg_sources
curl -O -L http://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz
tar xzvf lame-3.100.tar.gz
cd lame-3.100
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm
make
make install

libopus

cd ~/ffmpeg_sources
curl -O -L https://archive.mozilla.org/pub/opus/opus-1.3.tar.gz
tar xzvf opus-1.3.tar.gz
cd opus-1.3
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install

libogg

cd ~/ffmpeg_sources
curl -O -L http://downloads.xiph.org/releases/ogg/libogg-1.3.3.tar.gz
tar xzvf libogg-1.3.3.tar.gz
cd libogg-1.3.3
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install

libvorbis

cd ~/ffmpeg_sources
curl -O -L http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.6.tar.gz
tar xzvf libvorbis-1.3.6.tar.gz
cd libvorbis-1.3.6
./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-shared
make
make install

libvpx

cd ~/ffmpeg_sources
#git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git
git clone --depth 1 https://github.com/webmproject/libvpx
cd libvpx
./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm
make
make install

freetype2

cd ~/ffmpeg_sources
curl -O -L  https://github.com/aseprite/freetype2/archive/VER-2-6-3.tar.gz
tar xzvf VER-2-6-3.tar.gz
cd freetype2-VER-2-6-3
./autogen.sh
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
cp ~/ffmpeg_build/bin/freetype-config ~/bin/

FFmpeg

cd ~/ffmpeg_sources
#最新版本下载地址:https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
curl -O -L https://ffmpeg.org/releases/ffmpeg-4.1.tar.bz2
tar xjvf ffmpeg-4.1.tar.bz2
cd ffmpeg-4.1
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="/usr" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --extra-libs=-lpthread \
  --extra-libs=-lm \
  --bindir="/usr/bin" \
  --enable-gpl \
  --enable-libfdk_aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-nonfree

make
make install
# ffmpeg -version 查看版本

ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-36)
configuration: --prefix=/root/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --extra-libs=-lpthread --extra-libs=-lm --bindir=/root/bin --enable-gpl --enable-libfdk_aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
libavutil      56. 22.100 / 56. 22.100
libavcodec     58. 35.100 / 58. 35.100
libavformat    58. 20.100 / 58. 20.100
libavdevice    58.  5.100 / 58.  5.100
libavfilter     7. 40.101 /  7. 40.101
libswscale      5.  3.100 /  5.  3.100
libswresample   3.  3.100 /  3.  3.100
libpostproc    55.  3.100 / 55.  3.100

本文是从 https://www.cnblogs.com/jingzhishen/p/3735314.html copy过来的,仅作个人学习笔记

ffmpeg和ffserver配合使用可以实现实时的流媒体服务。

一、理解
里边主要有如下四个东西,搞清楚他们之间的关系就差不多明白了。

  1. ffmpeg
  2. ffserver
  3. ffserver.conf
  4. feed1.ffm
  5. ffmpeg,负责媒体文件的transcode工作,把你服务器上的源媒体文件转换成要发送出去的流媒体文件。
  6. ffserver,负责响应客户端的流媒体请求,把流媒体数据发送给客户端。
  7. ffserver.conf,ffserver启动时的配置文件,在这个文件中主要是对网络协议,缓存文件feed1.ffm(见下述)和要发送的流媒体文件的格式参数做具体的设定。
  8. feed1.ffm,可以看成是一个流媒体数据的缓存文件,ffmpeg把转码好的数据发送给ffserver,如果没有客户端连接请求,ffserver把数据缓存到该文件中。

二、http的建立流程

  1. 配置ffserver.conf文件(初次接触可以参考ffmpeg源码中的doc/ffserver.conf,里边有详细的注释)

如下写一个示例

Port 10535
RTSPPort 5454
BindAddress 0.0.0.0、
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 1000
CustomLog -
NoDaemon
 
#实时流数据配置(参考源码ffmpeg/test/下的ffserver.conf)
<Feed feed1.ffm>
File /tmp/feed1.ffm
FileMaxSize 1M
ACL allow 127.0.0.1
</Feed>
 
<Stream test.avi>
Feed feed1.ffm
Format avi
#
BitExact
DctFastint
IdctSimple
VideoFrameRate 10
VideoSize 352x288
VideoBitRate 100
VideoGopSize 30
NoAudio
 
PreRoll 10
StartSendOnKey
MaxTime 100
 
</Stream>
 
#已经存在的文件而非实时流
 
<Stream test.flv>
File "/project/apps/ffserver/test.flv"
Format flv
</Stream>

2、如何实现播放
(1)实时流用http传输
如果传输硬盘上的文件,则:
ffserver -f myfile/ffmpeg0.8.9/ffserver.conf & ffmpeg -i inputfile(输入文件) http://localhost:10535/feed1.ffm
如何传输摄像头捕获的实时流,则:
ffserver -f myfile/ffmpeg0.8.9/ffserver.conf & ffmpeg -f video4linux2 -framerate 30 -i /dev/video0 http://127.0.0.1:8090/feed1.ffm

启动ffserver和ffmpeg。ffserver先于ffmpeg启动,它在启动的时候需要加参数-f指定其配置文件。ffserver启动后,feed1.ffm就会被创建,这时如果你打开feed1.ffm看看,会发现feed1.ffm开始的部分已经写入了内 容,你可以找到关键字ffm以及向客户端传送流的配置信息,在feed1.ffm做缓冲用的时候,这些信息是不会被覆盖掉的,就把它们理解为 feed1.ffm文件的头吧。

ffserver启动后,ffmpeg启动,它启动时加的一个关键参数就是“http://ip:10535/feed1.ffm”,其中ip是运行 ffserver主机的ip,如果ffmpeg和ffserver都在同一系统中运行的话,用localhost也行。ffmpeg启动后会与 ffserver建立一个连接(短暂的连接),通过这第一次的连接,ffmpeg从ffserver那里获取了向客户端输出流的配置,并把这些配置作为自 己编码输出的配置,然后ffmpeg断开了这次连接,再次与ffserver建立连接(长久的连接),利用这个连接ffmpeg会把编码后的数据发送给 ffserver。

如果你观察ffserver端的输出就会发现这段时间会出现两次HTTP的200,这就是两次连接的过程。

ffmpeg从摄像头获取数据后,按照输出流的编码方式编码,然后发送给ffserver,ffserver收到ffmpeg的数据后,如果网络上 没有播放的请求,就把数据写入feed1.ffm中缓存,写入时把数据加上些头信息然后分块,每块4096B(每块也有结构),当feed1.ffm的大 小到了ffserver.conf中规定的大小后,就会从文件开始(跳过头)写入,覆盖旧的数据。直到网络上有播放的请求,ffserver从 feed1.ffm中读取数据,发送给客户端。

(2)本地文件用http传输
ffserver -f /etc/ffserver.conf
用命令启动ffserver,然后用ffplay http://ip:port/test.flv,或者在vlc中输入以上网址也可实现播放。

(3)本地文件用rtsp传输
ffserver -f /etc/ffserver.conf
用命令启动ffserver,然后用ffplay rtsp://ip:port/rtsp.mpg,或者在vlc中输入以上网址也可实现播放。
备注:在做测试的时候,用rtsp不能传输flv文件。

相关错误:
http://localhost:8090/test.asf: Invalid data found when processing input
Error occurs when I transcode a file into asf format
http://ffmpeg.gusari.org/viewtopic.php?f=11&t=590

You can't stream avi file format, it's not designed to be streamed, rather to be used as a file/storage format. Streaming formats are: flv, mpegts, asf, rtmp/rtp/rtsp... So, try changing Format avi to Format mpegts and see if that works. But, the most convenient way of using ffmpeg/ffserver is to create a config file for ffserver and then run ffmpeg, telling it to feed the ffserver, which will do the actual encoding and streaming.

 

 

 

 

ffmpeg与ffserver的协同工作
http://blog.csdn.net/shendan00/article/details/18839837

工作流程如下:

1、 启动ffserver,配置参数

ffserver先于ffmpeg启动,它在启动的时候需要加参数-f指定其配置文件,配置文件里包含端口信息、缓冲文件配置、传送流配置(如编码方式,帧率,采样率……)。

2、 启动ffmpeg,输入流

启动ffmpeg,向缓冲文件输入数据流,数据流可以来自摄像头,也可以来自本来就存在的文件。

feed1.ffm是一个缓冲文件,fserver启动后,feed1.ffm就会自动被创建,feed1.ffm开始的部分已经写入向客户端传送流的配置信息,在feed1.ffm做缓冲用的时候,这些信息是不会被覆盖掉。

ffmpeg启动的一个关键参数就是“http://ip:port/feed1.ffm”,其中ip是运行ffserver主机的ip,如果 ffmpeg和ffserver都在同一系统中运行的话,用localhost或者127.0.0.1也行。ffmpeg启动后会与ffserver建立 一个连接(短暂的连接),通过这第一次的连接,ffmpeg从ffserver那里获取了向客户端输出流的配置,并把这些配置作为自己编码输出的配置,然后ffmpeg断开了这次连接,再次与ffserver建立连接(长久的连接),利用这个连接ffmpeg会把编码后的数据发送给ffserver。如果你观察ffserver端的输出就会发现这段时间会出现两次HTTP的200,这就是两次连接的过程。

3、连接过程

ffmpeg从摄像头获取数据后,按照输出流的编码方式编码,然后发送给ffserver,ffserver收到ffmpeg的数据后,如果网络上 没有播放的请求,就把数据写入feed1.ffm中缓存,写入时把数据加上些头信息然后分块,每块4096B(每块也有结构),当feed1.ffm的大 小到了ffserver.conf中规定的大小后,就会从文件开始(跳过头)写入,覆盖旧的数据。直到网络上有播放的请求,ffserver从feed1.ffm中读取数据,发送给客户端。

带有缓冲的数据流图如下
ffserver用法小结 - yjlyp - 龙

我的配置(注意:asf文件播放不了)

Port 8090
RTSPPort 8091
BindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 1000
CustomLog -

<Feed feed1.ffm>
#File /tmp/feed1.ffm
File "/home/yingc/gcyin/test/thirdparty/output/ffmpeg/bin/feed1.ffm"
FileMaxSize 20000000K
ACL allow 127.0.0.1
</Feed>

#<Stream test.ts>
#Feed feed1.ffm
#Format mpegts
#
#AudioCodec libmp3lame
#AudioBitRate 128
#AudioChannels 2
#AudioSampleRate 44100
#AVOptionAudio flags +global_header
#
#VideoBitRate 800
#VideoFrameRate 25
#VideoSize 640x480
#VideoCodec libx264
#AVOptionVideo flags +global_header
#</Stream>
#
#<Stream test.asf>
#Feed feed1.ffm
#Format asf
#
#AudioCodec aac
#AudioBitRate 128
#AudioChannels 2
#AudioSampleRate 44100
#AVOptionAudio flags +global_header
#
#VideoBitRate 800
#VideoFrameRate 25
#VideoSize 640x480
#VideoCodec libx264
#AVOptionVideo flags +global_header
#</Stream>


<Stream test.ts>
Feed feed1.ffm
Format mpegts
</Stream>
<Stream test.avi>
Feed feed1.ffm
Format avi
</Stream>
<Stream test.flv>
Feed feed1.ffm
Format flv
</Stream>
<Stream test.mp4>
Format rtp
File "/home/yingc/gcyin/test/thirdparty/output/ffmpeg/bin/h.mp4"
</Stream>
<Stream test.asf>
Feed feed1.ffm
Format asf
</Stream>

<Stream stat.html>
Format status

# Only allow local people to get the status
ACL allow localhost
ACL allow 192.168.110.0 192.168.110.255
</Stream>

# Redirect index.html to the appropriate site
<Redirect index.html>
URL http://www.ffmpeg.org/
</Redirect>

 
 
./ffmpeg -i "http://122.228.84.235/d44bff3d000002EE-1400405760-3078718192/data4/vhotlx.video.qq.com/flv/173/5/p0014s3d4pb.p201.1.mp4?vkey=06C6236D18A183017BF4076DC2CCD118E4A6DCC28BAB7ECA53A48918D7D3732A6379C03F1EC5CB6FE7C901CA66638EFDB3E01647C335E225hostname=122.228.84.235" http://localhost:8090/feed1.ffm
 
 
 
./ffmpeg -i h.mp4 http://localhost:8090/feed1.ffm
 
 
 
./ffplay  http://localhost:8090/test.flv
 
./ffplay  rtsp://localhost:8091/test.flv

检查是否有notepad,要用的话就算成自己的进程名,如果进程宕了就过会自动重启(会在当前目录下生成一个start.bat)

@echo off

set _task=notepad.exe
set _svr=c:/windows/notepad.exe
set _des=start.bat

:checkstart
for /f "tokens=5" %%n in ('qprocess.exe ^| find "%_task%" ') do (
if %%n==%_task% (goto checkag) else goto startsvr
)

:startsvr
echo %time%
echo ********程序开始启动********
echo 程序重新启动于 %time% ,请检查系统日志 >> restart_service.txt
echo start %_svr% > %_des%
echo exit >> %_des%
start %_des%
set/p=.<nul
for /L %%i in (1 1 10) do set /p a=.<nul&ping.exe /n 2 127.0.0.1>nul
echo .
echo Wscript.Sleep WScript.Arguments(0) >%tmp%/delay.vbs
cscript //b //nologo %tmp%/delay.vbs 10000
del %_des% /Q
echo ********程序启动完成********
goto checkstart


:checkag
echo %time% 程序运行正常,10秒后继续检查..
echo Wscript.Sleep WScript.Arguments(0) >%tmp%/delay.vbs
cscript //b //nologo %tmp%/delay.vbs 10000
goto checkstart

======

这个脚本提供两种方式守护,一种是通过进程名,但对于进程名都是java.exe的java程序不适用,另一种是通过netstat查找应用程序所监听的端口是否正在被监听。这两种方式可以在脚本中通过两个冒号注释来选择切换。下面是设置成通过端口来守护的,当端口没被监听则打开一个zip文件,所以运行后会发现没过5秒会重复打开这个zip文件,除非这个zip文件打开后会自动监听8080端口,那当然是不可能的!脚本涉及的命令就不解释了搜一下就知道了。

@echo off

::检测时间间隔,单位:秒
set _interval=5

::需要守护的进程名称
set _processName=WinRAR

::需要守护的进程启动命令
set _processCmd=C:\ideavim-0.32.zip

::需要守护的进程预估启动完毕所需时间,单位:秒
set _processTimeout=10

::需要守护的进程所监听的端口
set _port=8080

::进程用户名,一般是Administrator
set _username=Administrator 

:LOOP
set /a isAlive=false

::通过进程名称检测
::tasklist /FI "username eq %_username%" | find /C "%_processName%" > temp.txt
::set /p num= < temp.txt
::del /F temp.txt

::通过进程的端口是否正在被监听检测
netstat -an | find /C "0.0.0.0:%_port%" > temp.txt
set /p num= < temp.txt
del /F temp.txt

if "%num%" == "0" (
start %_processCmd% | echo 启动 %_processName% 于 %time%
choice /D y /t %_processTimeout% > nul
)

if "%num%" NEQ "0" echo 已启动

::ping -n %_interval% 127.1>nul
choice /D y /t %_interval% >nul

goto LOOP

该脚本运行后会出现一个dos窗口,若觉得碍眼可以用记事本将下面保存为扩展名为.vbs的文件。其中guard.bat是上面批处理保存的文件名。两个文件放在同一目录下双击vbs文件后,守护进程就在后台运行了,单这样得通过资源管理器结束cmd进程才能停止守护进程。

set ws=WScript.CreateObject("WScript.Shell")
ws.Run "guard.bat",0

=============

根据上面的内容自己修改一个放到项目上使用:

1)可以根据参数,执行指定的程序

2)可以保存详细的执行日志

版本一:

@echo off
title processWatch
cls
set d=%date:~0,10%
set d=%d: =0%
echo %d%
set logFile=.\processWatch_%d:-=%.txt
echo 现在时间:%date%%time% 
echo ********程序开始启动******** >> %logFile%

set runAppPath=%1
set runAppPath="C:\Users\Administrator\Desktop\新建文件夹\Cares.AutoUpdate.exe"
set runAppFolder=''
if '%runAppPath%'=='' (goto end)

set _processName=''
set _processNameExt=''
::检测时间间隔,单位:秒
set _interval=10

for %%a in (%runAppPath%) do (
set _processName=%%~na
set _processNameExt=%%~nxa
set runAppFolder=%%~dpa
)
goto checkstart

rem 以下是测试代码
echo %_processName%
echo %_processNameExt%
echo %runAppFolder%
echo %runAppPath%
echo ====================================================
goto end


:checkstart
set d=%date:~0,10%
set d=%d: =0%
set logFile=.\processWatch_%d:-=%.txt
for /f "tokens=1" %%n in ('tasklist.exe ^| find /I "%_processNameExt%" ') do ( 
if '%%n'=='%_processNameExt%' (echo 检查进程【%_processNameExt%】正在运行 >> %logFile% && goto checkend) )
echo 检查进程【%_processNameExt%】未在运行 >> %logFile%

:startApp
echo, && echo ********开始启动程序********
echo ********开始启动程序******** >> %logFile%
echo [%date:~0,10%%time:~0,8%] 未检测到【%_processNameExt%】的进程,将重新启动程序 >> %logFile%
echo [%date:~0,10%%time:~0,8%] 重新启动程序:%runAppPath%
echo [%date:~0,10%%time:~0,8%] 重新启动程序:%runAppPath% >> %logFile%
echo 开始执行 start "" %runAppPath% >> %logFile%
pushd %runAppFolder%
start "" %runAppPath%
popd
echo ********启动程序完成******** && echo,
echo ********启动程序完成******** >> %logFile%
echo, >> %logFile%


:checkend
echo [%date:~0,10%%time:~0,8%] 程序【%_processNameExt%】运行正常,%_interval%秒后继续检查......
choice /t %_interval% /d y /n >nul
goto checkstart

:end
echo end.

对于一个jupyter编辑器使用的新手,更换浏览器或者Logout后,需要输入密码进行登陆时

按照网上的教程怎么设置都不行,那么自己整理了一个适用于初学者的操作。

1.windows下,打开命令行,重新生成一个jupyter配置文件:

jupyter notebook --generate-config     

2.修个配置文件,找到这个新生成的文件:Windows: C:UsersUSERNAME.jupyterjupyter_notebook_config.py

搜索 NotebookApp.allow_password_change,改为:NotebookApp.allow_password_change=False ,记得去掉注释的#

3.回到windows命令行,运行jupyter notebook password

C:\Windows\System32>jupyter notebook password
Enter password:             #键入密码,不显示的
Verify password:            #再次重复键入密码

[NotebookPasswordApp] Wrote hashed password to C:Users用户.jupyterjupyter_notebook_config.json #密码生成的一串sha1,写入到了这个文件,等下要把这串sha1,复制到第一个生成的配置文件中
4.还差一步密码才可以生效使用,在第一个jupyter_notebook_config.py配置文件中找到“c.NotebookApp.password“,等于,刚生成的那个密码sha1,效果如下:去掉前面的”#“

c.NotebookApp.password = u'sha1:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

5.保险起见,把jupyter重启,之后,无论是更换浏览器还是Logout登陆,新密码都可以正常使用了。

≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

第3步也可以换成:ipython执行

C:\Windows\System32>ipython
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'