nilaoda / BBDown

Bilibili Downloader. 一个命令行式哔哩哔哩下载器.
MIT License
9.9k stars 1.28k forks source link

ffmpeg小白请教一下 #534

Open qllokirin opened 1 year ago

qllokirin commented 1 year ago

1. 你使用的BBDown版本是什么?(指明是Release版本还是Actions版本)

Release

2. 你在什么系统使用本软件?(Win/Linux/Mac)

Win

首先非常感谢大佬的软件,很好用 然后我会下载一些视频的音频,但是要裁剪掉一部分(如果可以 后续bbdown能加入这个功能吗[即指定起始和终止时间]) 但是我在使用ffmpeg裁剪音频的时候遇到了一个问题—封面不会被保留,我尝试搜索找一些指令来完成,但是还是不太行 我尝试过这些指令,但是都无法保留下封面

ffmpeg -i input.m4a -ss 00:01:00 -to 00:02:30 -map_metadata 0 -codec copy output.m4a
ffmpeg -i input.m4a -ss 00:01:00 -to 00:02:30 -codec copy output.m4a 

image

但当我的指令中没有裁剪时,这两个指令都能保留住封面 即

ffmpeg -i input.m4a  -map_metadata 0 -codec copy output.m4a
ffmpeg -i input.m4a  -codec copy output.m4a 

image

感谢解答

nilaoda commented 1 year ago

-map 0 -map_metadata 0

qllokirin commented 1 year ago

-map 0 -map_metadata 0

感谢你的回答 请问是这样吗

 ffmpeg -i input.m4a -ss 00:01:00 -to 00:02:30 -map 0 -map_metadata 0 output.m4a

但是报错了,我稍微搜索了一下看起来都是Linux的解决办法https://www.jianshu.com/p/d5c5dae3ac9c 我的ffmpeg是下载的https://www.gyan.dev/ffmpeg/builds/

  Duration: 00:04:33.18, start: 0.000000, bitrate: 180 kb/s
  Stream #0:0[0x1](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 176 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x3](chi): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
    Metadata:
      handler_name    : SubtitleHandler
  Stream #0:2[0x0]: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 1161x726 [SAR 1:1 DAR 387:242], 90k tbr, 90k tbn (attached pic)
[sost#0:1 @ 0000016fe3820780] Automatic encoder selection failed Default encoder for format ipod (codec none) is probably disabled. Please choose an encoder manually.
[sost#0:1 @ 0000016fe3820780] Error selecting an encoder
nilaoda commented 1 year ago
ffmpeg -i input.m4a -ss 00:01:00 -to 00:02:30 -map 0 -map_metadata 0 -f mp4 output.m4a
qllokirin commented 1 year ago
ffmpeg -i input.m4a -ss 00:01:00 -to 00:02:30 -map 0 -map_metadata 0 -f mp4 output.m4a

感谢你的回答 不过似乎还是出现了问题

[sost#0:1 @ 000001fd1592b3c0] Automatic encoder selection failed Default encoder for format mp4 (codec none) is probably disabled. Please choose an encoder manually.
[sost#0:1 @ 000001fd1592b3c0] Error selecting an encoder

当把参数换为mp3时,也是一样的,error也会变成mp3 查询一下之后似乎是说没有mp3编码器,但是我输入ffmpeg -codecs之后看到了

 DEA..S mlp                  MLP (Meridian Lossless Packing)
 D.AIL. mp1                  MP1 (MPEG audio layer 1) (decoders: mp1 mp1float )
 DEAIL. mp2                  MP2 (MPEG audio layer 2) (decoders: mp2 mp2float ) (encoders: mp2 mp2fixed libtwolame )
 DEAIL. mp3                  MP3 (MPEG audio layer 3) (decoders: mp3float mp3 ) (encoders: libmp3lame libshine mp3_mf )
 D.AIL. mp3adu               ADU (Application Data Unit) MP3 (MPEG audio layer 3) (decoders: mp3adufloat mp3adu )
 D.AIL. mp3on4               MP3onMP4 (decoders: mp3on4float mp3on4 )
 D.AI.S mp4als               MPEG-4 Audio Lossless Coding (ALS) (decoders: als )

mp3的编码器应该是存在的但是无法使用,很诡异 网上教程很多是自己编译mp3lame然后让ffmpeg找到

参考:https://blog.csdn.net/han_ying_ying/article/details/80206026 https://o-u-u.com/?p=1900 https://blog.csdn.net/weixin_44736603/article/details/121537824 https://stackoverflow.com/questions/44058544/pydub-export-error-choose-encoder-manually

nilaoda commented 1 year ago

-c:v copy -c:a mp3

qllokirin commented 1 year ago

-c:v copy -c:a mp3

感谢你的回答,不过似乎还是没有解决 因为不知道指令的具体含义,所以我尝试了

 ffmpeg -i input.m4a -ss 00:01:00 -to 00:02:30 -map 0 -map_metadata 0 -c:v copy -c:a mp3 output.mp3

无法生成 提示

  Duration: 00:04:33.18, start: 0.000000, bitrate: 180 kb/s
  Stream #0:0[0x1](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 176 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x3](chi): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
    Metadata:
      handler_name    : SubtitleHandler
  Stream #0:2[0x0]: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 1161x726 [SAR 1:1 DAR 387:242], 90k tbr, 90k tbn (attached pic)
[sost#0:1 @ 00000178698411c0] Automatic encoder selection failed Default encoder for format mp3 (codec none) is probably disabled. Please choose an encoder manually.
[sost#0:1 @ 00000178698411c0] Error selecting an encoder

ffmpeg -i input.m4a -ss 00:01:00 -to 00:02:30 -map 0  -c:v copy -c:a mp3 output.mp3

无法生成 提示

  Duration: 00:04:33.18, start: 0.000000, bitrate: 180 kb/s
  Stream #0:0[0x1](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 176 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x3](chi): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
    Metadata:
      handler_name    : SubtitleHandler
  Stream #0:2[0x0]: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 1161x726 [SAR 1:1 DAR 387:242], 90k tbr, 90k tbn (attached pic)
[sost#0:1 @ 0000020bff3c1340] Automatic encoder selection failed Default encoder for format mp3 (codec none) is probably disabled. Please choose an encoder manually.
[sost#0:1 @ 0000020bff3c1340] Error selecting an encoder

 ffmpeg -i input.m4a -ss 00:01:00 -to 00:02:30   -c:v copy -c:a mp3 output.mp3

可以生成 ,但是还是没有封面 输出如下

ffmpeg -i input.m4a -ss 00:01:00 -to 00:02:30   -c:v copy -c:a mp3 output.mp3
ffmpeg version 2023-02-16-git-aeceefa622-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.0 (Rev10, 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-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      58.  1.100 / 58.  1.100
  libavcodec     60.  2.100 / 60.  2.100
  libavformat    60.  2.100 / 60.  2.100
  libavdevice    60.  0.100 / 60.  0.100
  libavfilter     9.  2.100 /  9.  2.100
  libswscale      7.  0.100 /  7.  0.100
  libswresample   4.  9.100 /  4.  9.100
  libpostproc    57.  0.100 / 57.  0.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000027cb750e4c0] stream 0, timescale not set
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.m4a':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    title           : xxxx
    artist          : xx
    encoder         : Lavf59.17.103
    description     : xx
  Duration: 00:04:33.18, start: 0.000000, bitrate: 180 kb/s
  Stream #0:0[0x1](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 176 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x3](chi): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
    Metadata:
      handler_name    : SubtitleHandler
  Stream #0:2[0x0]: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 1161x726 [SAR 1:1 DAR 387:242], 90k tbr, 90k tbn (attached pic)
File 'output.mp3' already exists. Overwrite? [y/N] y
Stream mapping:
  Stream #0:2 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (aac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'output.mp3':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    TIT2            : xx
    TPE1            : xxx
    description     : xxx
    TSSE            : Lavf60.2.100
  Stream #0:0: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 1161x726 [SAR 1:1 DAR 387:242], q=2-31, 90k tbr, 90k tbn (attached pic)
  Stream #0:1(und): Audio: mp3, 44100 Hz, stereo, fltp (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc60.2.100 libmp3lame
[mp3 @ 0000027cb752e880] No packets were sent for some of the attached pictures.s speed=73.5x
frame=    0 fps=0.0 q=-1.0 Lsize=    1408kB time=00:01:29.99 bitrate= 128.2kbits/s speed=70.2x
video:0kB audio:1407kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.084334%
ChenQiang-AISS commented 1 year ago

可能是metadata格式的问题。试试看 -map_metadata 0 -id3v2_version 3

qllokirin commented 1 year ago

可能是metadata格式的问题。试试看 -map_metadata 0 -id3v2_version 3

感谢回复 我试了下报错了

 Desktop  ffmpeg -i input.m4a -ss 00:01:00 -to 00:02:30 -map_metadata 0 -id3v2_version 3 output.m4a
ffmpeg version 2023-02-16-git-aeceefa622-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.0 (Rev10, 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-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      58.  1.100 / 58.  1.100
  libavcodec     60.  2.100 / 60.  2.100
  libavformat    60.  2.100 / 60.  2.100
  libavdevice    60.  0.100 / 60.  0.100
  libavfilter     9.  2.100 /  9.  2.100
  libswscale      7.  0.100 /  7.  0.100
  libswresample   4.  9.100 /  4.  9.100
  libpostproc    57.  0.100 / 57.  0.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001f7c5949900] stream 0, timescale not set
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.m4a':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    title           : xxxxxxxxxxxxxxxx
  Duration: 00:03:26.76, start: 0.000000, bitrate: 327 kb/s
  Stream #0:0[0x1](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x3](chi): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
    Metadata:
      handler_name    : SubtitleHandler
  Stream #0:2[0x0]: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 2033x1271 [SAR 1:1 DAR 2033:1271], 90k tbr, 90k tbn (attached pic)
Stream mapping:
  Stream #0:2 -> #0:0 (mjpeg (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[vost#0:0/libx264 @ 000001f7c5950b40] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or setting vsync/fps_mode to vfr
[libx264 @ 000001f7c5950e80] width not divisible by 2 (2033x1271)
[vost#0:0/libx264 @ 000001f7c5950b40] Error initializing output stream: Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
[aac @ 000001f7c599d400] Qavg: 512.117
[aac @ 000001f7c599d400] 2 frames left in the queue on closing
Conversion failed!

Press [q] to stop, [?] for help那我什么都没按,自动结束了

ChenQiang-AISS commented 1 year ago

@qllokirin 自己试了试,搞明白了 那个看起来像是封面的东西是只有1帧的视频流。 在你提供的输出里也可以看到

Stream #0:2[0x0]: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 2033x1271 [SAR 1:1 DAR 2033:1271], 90k tbr, 90k tbn (attached pic)
Stream mapping:

那么问题就变成了“为什么第1帧消失了?” 这个我也不知道,你可以去StackOverflow之类的问答网站上问问。 (不过如果从最开始切的话第1帧倒是可以被保留)