gpt4 book ai didi

arrays - 如何正确地将 bash 数组扩展为参数

转载 作者:行者123 更新时间:2023-12-04 22:47:39 24 4
gpt4 key购买 nike

我正在编写 Bash 上的脚本。
目标是通过命令将 36 个参数传递给 ffmpeg。
这里的步骤:

  • 我验证了命令。这个工作正常:
    ffmpeg -i  "$f" -y -acodec aac -ab 128k  -vcodec copy  -f mp4 -movflags use_metadata_tags   -metadata MtsExifToolVersionNumber="12.30"  -metadata MtsFileName="00017.MTS"  -metadata MtsDirectory="."  -metadata MtsFileSize="59 MiB"  -metadata MtsFileModificationDate/Time="2020"  -metadata MtsFileAccessDate/Time="2021"  -metadata MtsFileInodeChangeDate/Time="2022"  -metadata MtsFilePermissions="-rwxr-xr-x"  -metadata MtsFileType="M2TS"  -metadata MtsFileTypeExtension="mts"  -metadata MtsMIMEType="video/m2ts"  -metadata MtsVideoStreamType="H.264 (AVC) Video"  -metadata MtsAudioBitrate="256 kbps"  -metadata MtsSurroundMode="Not indicated"  -metadata MtsAudioChannels="2"  -metadata MtsAudioStreamType="PGS Audio"  -metadata MtsImageWidth="1920"  -metadata MtsImageHeight="1080"  -metadata MtsDate/TimeOriginal="2020"  -metadata MtsApertureSetting="Auto"  -metadata MtsGain="0 dB"  -metadata MtsExposureProgram="Program AE"  -metadata MtsWhiteBalance="Auto"  -metadata MtsFocus="Auto (0.155)"  -metadata MtsImageStabilization="On (0x3f)"  -metadata MtsExposureTime="1/60"  -metadata MtsFNumber="3.4"  -metadata MtsMake="Sony"  -metadata MtsCameraModelName="HDR-CX405"  -metadata MtsWarning="[minor] The ExtractEmbedded option may find more tags in the video data"  -metadata MtsAudioSampleRate="48000"  -metadata MtsDuration="18.71 s"  -metadata MtsAperture="3.4"  -metadata MtsImageSize="1920x1080"  -metadata MtsMegapixels="2.1"  -metadata MtsShutterSpeed="1/60"  -metadata Offset="$Offset" -metadata creation_time="$DATE" "./$output/convert_exif_ok/$MP4_NAME"

  • 现在..我创建了一个 bash 数组,并尝试直接在命令上扩展它:
      ffmpeg -i  "$f" -y -acodec aac -ab 128k  -vcodec copy  -f mp4 -movflags use_metadata_tags  $(echo "${exif_2[@]}"  )   -metadata Offset="$Offset" -metadata creation_time="$DATE" "./$output/convert_exif_ok/$MP4_NAME"
    而且..这不起作用..
    似乎它需要一个参数这么长时间而不是 36 个不同的参数..
    这是输出:
        ffmpeg version 5.0.1 Copyright (c) 2000-2022 the FFmpeg developers
    built with Apple clang version 12.0.0 (clang-1200.0.32.29)
    configuration: --prefix=/usr/local/Cellar/ffmpeg/5.0.1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
    libavutil 57. 17.100 / 57. 17.100
    libavcodec 59. 18.100 / 59. 18.100
    libavformat 59. 16.100 / 59. 16.100
    libavdevice 59. 4.100 / 59. 4.100
    libavfilter 8. 24.100 / 8. 24.100
    libswscale 6. 4.100 / 6. 4.100
    libswresample 4. 3.100 / 4. 3.100
    libpostproc 56. 3.100 / 56. 3.100
    Input #0, mpegts, from '00017.MTS':
    Duration: 00:00:18.72, start: 1.020000, bitrate: 26466 kb/s
    Program 1
    Stream #0:0[0x1011]: Video: h264 (High) (HDPR / 0x52504448), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn
    Stream #0:1[0x1100]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 256 kb/s
    Stream #0:2[0x1200]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090), 1920x1080
    -metadata MtsExifToolVersionNumber="12.30" -metadata MtsFileName="00017.MTS" -metadata MtsDirectory="." -metadata MtsFileSize="59 MiB" -metadata MtsFileModificationDate/Time="2020" -metadata MtsFileAccessDate/Time="2021" -metadata MtsFileInodeChangeDate/Time="2022" -metadata MtsFilePermissions="-rwxr-xr-x" -metadata MtsFileType="M2TS" -metadata MtsFileTypeExtension="mts" -metadata MtsMIMEType="video/m2ts" -metadata MtsVideoStreamType="H.264 (AVC) Video" -metadata MtsAudioBitrate="256 kbps" -metadata MtsSurroundMode="Not indicated" -metadata MtsAudioChannels="2" -metadata MtsAudioStreamType="PGS Audio" -metadata MtsImageWidth="1920" -metadata MtsImageHeight="1080" -metadata MtsDate/TimeOriginal="2020" -metadata MtsApertureSetting="Auto" -metadata MtsGain="0 dB" -metadata MtsExposureProgram="Program AE" -metadata MtsWhiteBalance="Auto" -metadata MtsFocus="Auto (0.155)" -metadata MtsImageStabilization="On (0x3f)" -metadata MtsExposureTime="1/60" -metadata MtsFNumber="3.4" -metadata MtsMake="Sony" -metadata MtsCameraModelName="HDR-CX405" -metadata MtsWarning="[minor] The ExtractEmbedded option may find more tags in the video data" -metadata MtsAudioSampleRate="48000" -metadata MtsDuration="18.71 s" -metadata MtsAperture="3.4" -metadata MtsImageSize="1920x1080" -metadata MtsMegapixels="2.1" -metadata MtsShutterSpeed="1/60": File name too long
    好吧..我确定我在将数组内容传递给参数的方式上做错了..
    有什么帮助吗?
    谢谢

    最佳答案

    如果你有

    $ typeset -p exif_2 
    declare -a exif_2='([0]=" -metadata MtsExifToolVersionNumber=\"12.30\"" ...
    创建数组时引号过多。 -metadataMtsExifToolVersionNumber="12.30"需要是数组中的单独元素。
    试试这个(请注意,数组定义中允许使用任意空格,包括换行符)
    exif_2=(
    -movflags use_metadata_tags
    -metadata MtsExifToolVersionNumber="12.30"
    -metadata MtsFileName="00017.MTS"
    -metadata MtsDirectory="."
    -metadata MtsFileSize="59 MiB"
    -metadata MtsFileModificationDate/Time="2020"
    -metadata MtsFileAccessDate/Time="2021"
    -metadata MtsFileInodeChangeDate/Time="2022"
    -metadata MtsFilePermissions="-rwxr-xr-x"
    -metadata MtsFileType="M2TS"
    -metadata MtsFileTypeExtension="mts"
    -metadata MtsMIMEType="video/m2ts"
    -metadata MtsVideoStreamType="H.264 (AVC) Video"
    -metadata MtsAudioBitrate="256 kbps"
    -metadata MtsSurroundMode="Not indicated"
    -metadata MtsAudioChannels="2"
    -metadata MtsAudioStreamType="PGS Audio"
    -metadata MtsImageWidth="1920"
    -metadata MtsImageHeight="1080"
    -metadata MtsDate/TimeOriginal="2020"
    -metadata MtsApertureSetting="Auto"
    -metadata MtsGain="0 dB"
    -metadata MtsExposureProgram="Program AE"
    -metadata MtsWhiteBalance="Auto"
    -metadata MtsFocus="Auto (0.155)"
    -metadata MtsImageStabilization="On (0x3f)"
    -metadata MtsExposureTime="1/60"
    -metadata MtsFNumber="3.4"
    -metadata MtsMake="Sony"
    -metadata MtsCameraModelName="HDR-CX405"
    -metadata MtsWarning="[minor] The ExtractEmbedded option may find more tags in the video data"
    -metadata MtsAudioSampleRate="48000"
    -metadata MtsDuration="18.71 s"
    -metadata MtsAperture="3.4"
    -metadata MtsImageSize="1920x1080"
    -metadata MtsMegapixels="2.1"
    -metadata MtsShutterSpeed="1/60"
    )

    ffmpeg_opts=(
    -i "$f"
    -y
    -acodec aac
    -ab 128k
    -vcodec copy
    -f mp4
    "${exif_2[@]}"
    -metadata Offset="$Offset"
    -metadata creation_time="$DATE"
    )

    ffmpeg "${ffmpeg_opts[@]}" "./$output/convert_exif_ok/$MP4_NAME"

    关于arrays - 如何正确地将 bash 数组扩展为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71849338/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com