板凳-------Mysql cookbook学习 (十二--------7)

发布于:2025-07-30 ⋅ 阅读:(28) ⋅ 点赞:(0)

18.0 概述 593

<html>
<head><title>Web Page Title </title></head>
<body>
<p>Web page body.</p>
</body>
</html>
方法1:保存为HTML文件后打开
将你提供的代码复制到一个文本编辑器中(如记事本、VS Code等)

将文件保存为.html扩展名的文件,例如index.html

双击该文件,它会自动在你的默认浏览器中打开


Index3.html
<html>
<head>
    <title>Web Page Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <p>Web page body.</p>
</body>
</html>


要发送JPEG图像,你可以使用HTML的<img>标签来嵌入图片。以下是示例代码:

Index4.html
<!DOCTYPE html>
<html>
<head>
    <title>显示JPEG图像</title>
</head>
<body>
    <h1>MySQL Cookbook 2nd Edition</h1>
    <!-- 本地文件路径方式(仅在你本地电脑有效) -->
    <img src="file:///C:/Users/lenovo/Desktop/desk_python/MYSQL%20COOKBOOK%202TH.jpeg" 
         alt="MySQL Cookbook 2nd Edition"
         width="500">
    
    <p>或者使用网络URL方式:</p>
    <!-- 网络URL方式(需要把图片上传到网络) -->
    <img src="https://example.com/path/to/MYSQL%20COOKBOOK%202TH.jpeg" 
         alt="MySQL Cookbook 2nd Edition">
</body>
</html>
注意事项:
本地文件路径方式(file:///)只会在你自己的电脑上有效
空格在URL中需要替换为%20
要使图片能在网络上共享,你需要:
将图片上传到网络服务器或云存储
使用图片的公开URL替换示例中的网络URL
width属性可以控制图片显示宽度(高度会自动按比例调整)
如果你需要实际发送图片文件(而不是HTML代码),需要通过电子邮件、文件共享服务或其他文件传输方式。

mysql> use cookbook
Database changed
mysql> SELECT file_data INTO DUMPFILE '/tmp/trailer_export.ogv'
    -> FROM video_storage
    -> WHERE id = 1;
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
mysql> SELECT HEX(SUBSTRING(file_data, 1, 100)) from video_storage
    -> where file_name = 'trailer.ogv';
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| HEX(SUBSTRING(file_data, 1, 100))                                                                                                                                                                        |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 4F67675300020000000000000000C47AD0060000000049963A1701406669736865616400030000000000000000000000E8030000000000000000000000000000E80300000000000000000000000000000000000000000000000000004F67675300020000 |
| 4F67675300020000000000000000C47AD0060000000049963A1701406669736865616400030000000000000000000000E8030000000000000000000000000000E80300000000000000000000000000000000000000000000000000004F67675300020000 |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.18 sec)

mysql> SHOW VARIABLES LIKE 'secure_file_priv';
+------------------+---------------------------------+
| Variable_name    | Value                           |
+------------------+---------------------------------+
| secure_file_priv | D:\software\MySql\Data\Uploads\ |
+------------------+---------------------------------+
1 row in set, 1 warning (0.02 sec)

mysql> SELECT file_data INTO DUMPFILE 'D:/software/MySql/Data/Uploads/trailer_export.ogv'
    -> FROM video_storage
    -> WHERE id = 1;
Query OK, 1 row affected (0.02 sec)

import mysql.connector
import os

conn = mysql.connector.connect(
    host="localhost",
    user="your_username",
    password="your_password",
    database="cookbook"
)

cursor = conn.cursor()
cursor.execute("SELECT file_data FROM video_storage WHERE id = 1")
data = cursor.fetchone()[0]

with open('trailer_export.ogv', 'wb') as f:
    f.write(data)

cursor.close()
conn.close()

1. 安装 FFmpeg
方法1:通过 Chocolatey(推荐给 Windows 用户)
1.	以管理员身份打开 PowerShell
2.	安装 Chocolatey(如果尚未安装):
powershell
复制
下载
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
  1. 安装 FFmpeg:
powershell
复制
下载
choco install ffmpeg

Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
                                                                                                                        尝试新的跨平台 PowerShell https://aka.ms/pscore6                                                                                                                                                                                                PS C:\windows\system32> Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Forcing web requests to allow TLS v1.2 (Required for requests to Chocolatey.org)
Getting latest version of the Chocolatey package for download.
Not using proxy.
Getting Chocolatey from https://community.chocolatey.org/api/v2/package/chocolatey/2.5.0.
Downloading https://community.chocolatey.org/api/v2/package/chocolatey/2.5.0 to C:\Users\lenovo\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip
Not using proxy.
Extracting C:\Users\lenovo\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip to C:\Users\lenovo\AppData\Local\Temp\chocolatey\chocoInstall
Installing Chocolatey on the local machine
Creating ChocolateyInstall as an environment variable (targeting 'Machine')
  Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'
WARNING: It's very likely you will need to close and reopen your shell
  before you can use choco.
Restricting write permissions to Administrators
We are setting up the Chocolatey package repository.
The packages themselves go to 'C:\ProgramData\chocolatey\lib'
  (i.e. C:\ProgramData\chocolatey\lib\yourPackageName).
A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin'
  and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'.

Creating Chocolatey CLI folders if they do not already exist.

chocolatey.nupkg file not installed in lib.
 Attempting to locate it from bootstrapper.
PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding...
警告: Not setting tab completion: Profile file does not exist at
'C:\Users\lenovo\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'.
Chocolatey CLI (choco.exe) is now ready.
You can call choco from anywhere, command line or PowerShell by typing choco.
Run choco /? for a list of functions.
You may need to shut down and restart PowerShell and/or consoles
 first prior to using choco.
Ensuring Chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder
PS C:\windows\system32>

PS C:\windows\system32> choco install ffmpeg -y
Chocolatey v2.5.0
Installing the following packages:
ffmpeg
By installing, you accept licenses for the packages.
Downloading package from source 'https://community.chocolatey.org/api/v2/'
Progress: Downloading ffmpeg 7.1.1... 100%

ffmpeg v7.1.1 [Approved]
ffmpeg package files install completed. Performing other installation steps.
Extracting 64-bit C:\ProgramData\chocolatey\lib\ffmpeg\tools\ffmpeg-release-essentials.7z to C:\ProgramData\chocolatey\lib\ffmpeg\tools...
C:\ProgramData\chocolatey\lib\ffmpeg\tools
Removing extracted archive.
Sleeping for 2 seconds to allow anti-viruses to finish scanning...
Renaming ffmpeg directory to common name (Try 1 / 3)
Successfully renamed directory.
 ShimGen has successfully created a shim for ffmpeg.exe
 ShimGen has successfully created a shim for ffplay.exe
 ShimGen has successfully created a shim for ffprobe.exe
 The install of ffmpeg was successful.
  Deployed to 'C:\ProgramData\chocolatey\lib\ffmpeg\tools'

Chocolatey installed 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
PS C:\windows\system32> ffmpeg -version
ffmpeg version 7.1.1-essentials_build-www.gyan.dev Copyright (c) 2000-2025 the FFmpeg developers
built with gcc 14.2.0 (Rev1, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil      59. 39.100 / 59. 39.100
libavcodec     61. 19.101 / 61. 19.101
libavformat    61.  7.100 / 61.  7.100
libavdevice    61.  3.100 / 61.  3.100
libavfilter    10.  4.100 / 10.  4.100
libswscale      8.  3.100 /  8.  3.100
libswresample   5.  3.100 /  5.  3.100
libpostproc    58.  3.100 / 58.  3.100
PS C:\windows\system32> cd C:\Users\lenovo\Desktop\desk_python
PS C:\Users\lenovo\Desktop\desk_python> ffmpeg -i trailer_export.ogv -c:v libx264 -preset fast -crf 23 -pix_fmt yuv420p -movflags +faststart -c:a aac -b:a 128k trailer.mp4
ffmpeg version 7.1.1-essentials_build-www.gyan.dev Copyright (c) 2000-2025 the FFmpeg developers
  built with gcc 14.2.0 (Rev1, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
  libavutil      59. 39.100 / 59. 39.100
  libavcodec     61. 19.101 / 61. 19.101
  libavformat    61.  7.100 / 61.  7.100
  libavdevice    61.  3.100 / 61.  3.100
  libavfilter    10.  4.100 / 10.  4.100
  libswscale      8.  3.100 /  8.  3.100
  libswresample   5.  3.100 /  5.  3.100
  libpostproc    58.  3.100 / 58.  3.100
[ogg @ 0000026dfcbe4140] Broken file, keyframe not correctly marked.
Input #0, ogg, from 'trailer_export.ogv':
  Duration: 00:00:52.25, start: 0.000000, bitrate: 1985 kb/s
  Stream #0:0: Data: none
  Stream #0:1: Video: theora, yuv420p(bt470bg/bt470bg/bt709), 854x480, 24 tbr, 24 tbn
      Metadata:
        TITLE           : Sintel Trailer
        ARTIST          : Durian Open Movie Team
        COPYRIGHT       : (c) copyright Blender Foundation | durian.blender.org
        LICENSE         : Creative Commons Attribution 3.0 license
        ENCODER         : ffmpeg2theora-0.24
  Stream #0:2: Data: none
  Stream #0:3: Audio: vorbis, 48000 Hz, stereo, fltp, 80 kb/s
      Metadata:
        ENCODER         : ffmpeg2theora-0.24
Stream mapping:
  Stream #0:1 -> #0:0 (theora (native) -> h264 (libx264))
  Stream #0:3 -> #0:1 (vorbis (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0000026dfce50c40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0000026dfce50c40] profile High, level 3.0, 4:2:0, 8-bit
[libx264 @ 0000026dfce50c40] 264 - core 164 r3204 373697b - H.264/MPEG-4 AVC codec - Copyleft 2003-2025 - http://www.videolan.org/x264.html - options: cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=6 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookahead=30 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'trailer.mp4':
  Metadata:
    encoder         : Lavf61.7.100
  Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt470bg/bt470bg/bt709, progressive), 854x480, q=2-31, 24 fps, 12288 tbn
      Metadata:
        TITLE           : Sintel Trailer
        ARTIST          : Durian Open Movie Team
        COPYRIGHT       : (c) copyright Blender Foundation | durian.blender.org
        LICENSE         : Creative Commons Attribution 3.0 license
        encoder         : Lavc61.19.101 libx264
      Side data:
        cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
  Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
      Metadata:
        encoder         : Lavc61.19.101 aac
[ogg @ 0000026dfcbe4140] Broken file, keyframe not correctly marked.
[ogg @ 0000026dfcbe4140] Broken file, keyframe not correctly marked.= 694.3kbits/s speed= 2.1x
    Last message repeated 1 times
[ogg @ 0000026dfcbe4140] Broken file, keyframe not correctly marked.= 550.1kbits/s speed=2.23x
    Last message repeated 1 times
[ogg @ 0000026dfcbe4140] Broken file, keyframe not correctly marked.= 611.4kbits/s speed= 2.6x
[ogg @ 0000026dfcbe4140] Broken file, keyframe not correctly marked.= 498.4kbits/s speed=2.81x
[ogg @ 0000026dfcbe4140] Broken file, keyframe not correctly marked.= 606.4kbits/s speed=3.12x
[ogg @ 0000026dfcbe4140] Broken file, keyframe not correctly marked.= 697.9kbits/s speed=3.38x
[ogg @ 0000026dfcbe4140] Broken file, keyframe not correctly marked.= 813.0kbits/s speed=3.45x
[ogg @ 0000026dfcbe4140] Broken file, keyframe not correctly marked.= 826.0kbits/s speed=3.48x
[ogg @ 0000026dfcbe4140] Broken file, keyframe not correctly marked.= 832.8kbits/s speed=3.51x
    Last message repeated 1 times
[ogg @ 0000026dfcbe4140] Broken file, keyframe not correctly marked.= 817.2kbits/s speed=3.63x
    Last message repeated 5 times
[mp4 @ 0000026dfcbec040] Starting second pass: moving the moov atom to the beginning of the file
[out#0/mp4 @ 0000026dfce51c40] video:3845KiB audio:819KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 0.733970%
frame= 1111 fps= 88 q=-1.0 Lsize=    4699KiB time=00:00:50.54 bitrate= 761.7kbits/s speed=4.02x
[libx264 @ 0000026dfce50c40] frame I:21    Avg QP:14.98  size:  8669
[libx264 @ 0000026dfce50c40] frame P:460   Avg QP:21.09  size:  4711
[libx264 @ 0000026dfce50c40] frame B:630   Avg QP:21.81  size:  2520
[libx264 @ 0000026dfce50c40] consecutive B-frames: 21.0%  7.6%  8.1% 63.4%
[libx264 @ 0000026dfce50c40] mb I  I16..4: 43.6% 52.3%  4.1%
[libx264 @ 0000026dfce50c40] mb P  I16..4:  8.3% 16.5%  0.9%  P16..4: 19.9%  5.6%  2.4%  0.0%  0.0%    skip:46.4%
[libx264 @ 0000026dfce50c40] mb B  I16..4:  3.8% 11.3%  0.3%  B16..8: 14.4%  4.0%  0.3%  direct:11.3%  skip:54.5%  L0:47.0% L1:41.0% BI:12.0%
[libx264 @ 0000026dfce50c40] 8x8 transform intra:66.8% inter:78.3%
[libx264 @ 0000026dfce50c40] coded y,uvDC,uvAC intra: 34.7% 40.0% 5.8% inter: 8.9% 15.3% 0.3%
[libx264 @ 0000026dfce50c40] i16 v,h,dc,p: 29% 42% 12% 16%
[libx264 @ 0000026dfce50c40] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 30% 32%  2%  2%  2%  2%  2%  3%
[libx264 @ 0000026dfce50c40] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 29% 18%  6%  7%  6%  7%  5%  5%
[libx264 @ 0000026dfce50c40] i8c dc,h,v,p: 55% 27% 15%  3%
[libx264 @ 0000026dfce50c40] Weighted P-Frames: Y:31.5% UV:20.2%
[libx264 @ 0000026dfce50c40] ref P L0: 83.5% 16.5%
[libx264 @ 0000026dfce50c40] ref B L0: 90.5%  9.5%
[libx264 @ 0000026dfce50c40] ref B L1: 97.5%  2.5%
[libx264 @ 0000026dfce50c40] kb/s:604.25
[aac @ 0000026dfcea89c0] Qavg: 840.834

运行并测试
启动 Flask 应用:

powershell
python app.py
浏览器访问:

text
http://127.0.0.1:5000

网站公告

今日签到

点亮在社区的每一天
去签到