【问题标题】:Trying to loop a playlist in folder with ffmpeg尝试使用 ffmpeg 在文件夹中循环播放列表
【发布时间】:2020-04-19 09:36:49
【问题描述】:

当尝试播放文件夹中的所有 *.mp4 文件,然后再次从第一个视频中重复播放时,我收到此错误:

start_betterme_playlist: line 35: 25659 Killed                  ffmpeg $SOURCE -filter_complex "$filter" -map "[v]" -map "[a]" -deinterlace -vcodec libx264 -pix_fmt yuv420p -preset $QUAL -r $FPS -g $(($FPS * 2)) -b:v $VBR -acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b:a 712000 -bufsize 512k -f flv "$YOUTUBE_URL/$KEY"

代码是 - 有没有人知道如何解决这个问题,我真的很想在流中连续播放这多个视频。提前致谢!

#! /bin/bash


VBR="2500k"                                    
FPS="30"                                      
QUAL="medium"                                 
YOUTUBE_URL="rtmp://live.twitch.tv/app/"  

FOLDER="videos"                                  
KEY="live_16xxxxxxxxxxx_xxxvO7C"                 

SOURCE=""
n=0
filter=""

for f in $FOLDER/*.mp4
do
  SOURCE="$SOURCE -i $f"
  filter="$filter [$n:v:0] [$n:a:0]"
  ((n++))
done

filter="$filter concat=n=$n:v=1:a=1 [v] [a]"

echo "ffmpeg $SOURCE -filter_complex '$filter'"

ffmpeg \
    $SOURCE -filter_complex "$filter" \
-map "[v]" -map "[a]" -deinterlace \
    -vcodec libx264 -pix_fmt yuv420p -preset $QUAL -r $FPS -g $(($FPS * 2)) -b:v $VBR \
    -acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b:a 712000 -bufsize 512k \
    -f flv "$YOUTUBE_URL/$KEY"

【问题讨论】:

    标签: bash loops ffmpeg


    【解决方案1】:

    您可以使用 ffmpeg 的内置播放列表功能:

    1. 为您目录中的所有 mp4 文件创建一个播放列表(您可以在视频之间使用填充视频)
    2. 使用 playlist 作为 ffmpeg 的输入(编辑 ffmpeg 命令来品尝。我创建了一个可以在本地轻松测试的多播流)

    这是一个简单的 shell 脚本:

    #!/bin/bash
    
    # create playlist from all .mp4 and play in loop
    
    playlist="playlist.txt"
    
    # create/reset playlist file
    echo "#ffmpeg playlist" > ${playlist}
    
    # this video goes in between two video files
    use_filler="true" # activate filler with "true". Use "false" or any other string to deactivate filler.
    filler="filler.mp4"
    
    # create playlist for ffmpeg from all videos in the current directory
    for f in *.mp4;do
    
    # exclude filler from playlist
    if [ "${f}" != "${filler}" ]; then
    
        echo "file '${f}'" >> ${playlist}
    
        # if activated add filler after every video file
        if [[ "${use_filler}" = "true" ]]; then  # This condition is false for anything but the literal string "true".
    
            echo "file '${filler}'" >> ${playlist}
    
        fi
    
    fi
    
    done
    
    # stream playlist immediately with ffmpeg
    ffmpeg -f concat -safe 0 -stream_loop -1 \
    -i "${playlist}" \
    -c copy \
    -f mpegts \
    "udp://239.253.253.1:1234?pkt_size=1384"
    

    使用 ffplay 播放...

    ffplay udp://239.253.253.1:1234
    

    【讨论】:

      【解决方案2】:

      您可以使用 ffmpeg 的内置播放列表功能:

      1. 为所有 mp4 文件创建一个播放列表(您可以在视频之间使用填充符)
      2. 使用 playlist 作为 ffmpeg 的输入(编辑 ffmpeg 命令来品尝。我创建了一个可以在本地轻松测试的多播流)

      这是一个简单的 shell 脚本:

      #!/bin/bash
      
      # create playlist from all .mp4 and play in loop
      
      playlist="playlist.txt"
      
      # create/reset playlist file
      echo "#ffmpeg playlist" > ${playlist}
      
      # this video goes in between two video files
      use_filler="true" # activate filler with "true". Use "false" or any other string to deactivate filler.
      filler="filler.mp4"
      
      # create playlist for ffmpeg from all videos in the current directory
      for f in *.mp4;do
      
      # exclude filler from playlist
      if [ "${f}" != "${filler}" ]; then
      
          echo "file '${f}'" >> ${playlist}
      
          # if activated add filler after every video file
          if [[ "${use_filler}" = "true" ]]; then  # This condition is false for anything but the literal string "true".
      
              echo "file '${filler}'" >> ${playlist}
      
          fi
      
      fi
      
      done
      
      # stream playlist immediately with ffmpeg
      ffmpeg -f concat -safe 0 -stream_loop -1 \
      -i "${playlist}" \
      -c copy \
      -f mpegts \
      "udp://239.253.253.1:1234?pkt_size=1384"
      

      使用 ffplay 播放...

      ffplay udp://239.253.253.1:1234
      

      ..或 VLC:

      udp://@239.253.253.1:1234
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-31
        • 1970-01-01
        • 2015-08-15
        相关资源
        最近更新 更多