Trying to convert a bunch of files with ffmpeg and find.
find -name "*.mkv" | while read f
do ffmpeg -i "$f" -c copy -y "${f%.*}.mp4"
done
This should work right? It results in:
+ read f
+ ffmpeg -i '/file.mkv' -c copy -y '/file.mp4'
ffmpeg version N-61155-g61ff043 Copyright (c) 2000-2014 the FFmpeg developers
built on Mar 7 2014 19:17:59 with gcc 4.8 (Debian 4.8.2-16)
/file.mkv: No such file or directory
So I naturally try sticking the missing dot in front of the variable:
find -name "*.mkv" | while read f
do ffmpeg -i ".$f" -c copy -y ".${f%.*}.mp4"
done
The result:
+ read f
+ ffmpeg -i '../file.mkv' -c copy -y '../file.mp4'
ffmpeg version N-61155-g61ff043 Copyright (c) 2000-2014 the FFmpeg developers
built on Mar 7 2014 19:17:59 with gcc 4.8 (Debian 4.8.2-16)
../file.mkv: No such file or directory
It's specifically removing the dot at the worst possible time. Any idea what's causing this and how to fix it?
PS: -print0 in find has the same problem, and none of the files have newlines etc.
Edit: As requested, the echo. The echo works as expected:
find -name "*.mkv" | while read f
do echo ffmpeg -i "$f" -c copy -y "${f%.*}.mp4"
done
+ read f
+ echo ffmpeg -i './file.mkv' -c copy -y './file.mp4'
ffmpeg -i ./file.mkv -c copy -y ./file.mp4
Edit2: With a file with a space and one without, the filename without is changed. If I rm the one with a space the one without works fine.
$ ls
+ ls
file.mkv file two.mkv
$ find -name "*.mkv" | while read f; do ffmpeg -i "$f" -c copy -y "${f%.*}.mp4"; done
+ find -name '*.mkv'
+ read f
+ ffmpeg -i './file two.mkv' -c copy -y './file two.mp4'
ffmpeg version N-61155-g61ff043 Copyright (c) 2000-2014 the FFmpeg developers
built on Mar 7 2014 19:17:59 with gcc 4.8 (Debian 4.8.2-16)
configuration: --arch=amd64 --enable-pthreads --enable-libopencv --enable-librtmp --enable-libopenjpeg --enable-libopus --enable-libspeex --enable-libtheora --enable-vaapi --enable-runtime-cpudetect --enable-libvorbis --enable-zlib --enable-swscale --enable-libcdio --enable-bzlib --enable-libdc1394 --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-libpulse --enable-vdpau --enable-libvpx --enable-gpl --enable-x11grab --enable-libx264 --enable-filters
libavutil 52. 66.101 / 52. 66.101
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.101 / 55. 33.101
libavdevice 55. 11.100 / 55. 11.100
libavfilter 4. 3.100 / 4. 3.100
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, matroska,webm, from './file two.mkv':
Metadata:
COMPATIBLE_BRANDS: isommp42
MAJOR_BRAND : mp42
MINOR_VERSION : 0
ENCODER : Lavf55.33.101
Duration: 00:08:15.54, start: 0.000000, bitrate: 194 kb/s
Stream #0:0(und): Audio: aac, 44100 Hz, stereo, fltp (default)
Metadata:
CREATION_TIME : 2014-03-07 04:33:17
LANGUAGE : und
HANDLER_NAME : IsoMedia File Produced by Google, 5-11-2011
Output #0, mp4, to './file two.mp4':
Metadata:
COMPATIBLE_BRANDS: isommp42
MAJOR_BRAND : mp42
MINOR_VERSION : 0
encoder : Lavf55.33.101
Stream #0:0(und): Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo (default)
Metadata:
CREATION_TIME : 2014-03-07 04:33:17
LANGUAGE : und
HANDLER_NAME : IsoMedia File Produced by Google, 5-11-2011
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
size= 11698kB time=00:08:15.53 bitrate= 193.4kbits/s
video:0kB audio:11614kB subtitle:0 data:0 global headers:0kB muxing overhead 0.724668%
+ read f
+ ffmpeg -i /file.mkv -c copy -y /file.mp4
ffmpeg version N-61155-g61ff043 Copyright (c) 2000-2014 the FFmpeg developers
built on Mar 7 2014 19:17:59 with gcc 4.8 (Debian 4.8.2-16)
configuration: --arch=amd64 --enable-pthreads --enable-libopencv --enable-librtmp --enable-libopenjpeg --enable-libopus --enable-libspeex --enable-libtheora --enable-vaapi --enable-runtime-cpudetect --enable-libvorbis --enable-zlib --enable-swscale --enable-libcdio --enable-bzlib --enable-libdc1394 --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-libpulse --enable-vdpau --enable-libvpx --enable-gpl --enable-x11grab --enable-libx264 --enable-filters
libavutil 52. 66.101 / 52. 66.101
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.101 / 55. 33.101
libavdevice 55. 11.100 / 55. 11.100
libavfilter 4. 3.100 / 4. 3.100
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
/file.mkv: No such file or directory
+ read f
ffmpeg, for reasons I do not know, reads from standard input. Redirect from /dev/null to avoid interfering with the read statement in the while loop.
find -name "*.mkv" | while read f
do ffmpeg -i "$f" -c copy -y "${f%.*}.mp4" < /dev/null
done
Alternatively, you could execute ffmepg on each file as it's found:
find . -type f -name "*.mkv" -exec bash -c 'ffmpeg -i "$0" -codec copy "${0%.*}.mp4"' "{}" \;
Related
I am trying to make a thumbnail image from mp4 video using FFmpeg but I am getting the error that
Output #0, image2, to 'output.jpg':
Output file #0 does not contain any stream
the command I used is
ffmpeg -i file_example_MP4_700KB.mp4 -ss 00:00:01 -vf thumbnail,scale=200:115 -qscale:v 2 -frames:v 1 -f image2 -c:v mjpeg output.jpg
and I am not sure what I am doing wrong and I stuck throw it for so long.
Any suggestions will be good
I am using Ubuntu 18.*
full logs:-
ffmpeg version n4.1.4 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
configuration: --prefix= --prefix=/usr --disable-debug --disable-doc --disable-static --enable-avisynth --enable-cuda --enable-cuvid --enable- libdrm --enable-ffplay --enable-gnutls --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopus --enable-libpulse --enable-sdl2 --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-nonfree --enable-nvenc --enable-omx --enable-openal --enable-opencl --enable-runtime-cpudetect --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-xlib
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
Input #0, mp3, from 'file_example_MP3_700KB.mp3':
Metadata:
genre : Cinematic
album : YouTube Audio Library
title : Impact Moderato
artist : Kevin MacLeod
Duration: 00:00:27.25, start: 0.034531, bitrate: 224 kb/s
Stream #0:0: Audio: mp3, 32000 Hz, stereo, fltp, 224 kb/s
Metadata:
encoder : LAME3.99r
Output #0, image2, to 'output.jpg':
Output file #0 does not contain any stream
I had the same problem with:
ffmpeg -i myfile.raw -f s16le -ac 1 -ar 48000 -acodec pcm_s16le output.mp3
The solution was to change the order to:
ffmpeg -f s16le -ac 1 -ar 48000 -acodec pcm_s16le -i input.raw output.mp3
I want to merge 3 .mov files quickly without losing any resolution. I want to be able to distinguish the 3 pieces of videos after merge.
"ffmpeg -f concat" does not lose resolution and quick without crossfade.
But, I can't distinguish 3 videos.
As far as I know ffmpeg filter can be used add crossfade, but it have to use video start/end content to do the merger, which might involve transcoding. It won't be fast compared with 'concat', which won't do transcoding, but simply copying.
Here is the content (ffmpeg -i video.mov) of one of 3 videos:
ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
built with Apple LLVM version 10.0.1 (clang-1001.0.46.3)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.3 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/openjdk-12.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/openjdk-12.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr
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
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '..../(edited)/VMEK8375.MOV':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2019-06-30T01:28:04.000000Z
com.apple.quicktime.model: iPhone
com.apple.quicktime.software: ZHIYUN
com.apple.quicktime.creationdate: 2019-06-30T09:28:04Z
Duration: 00:00:07.61, start: 0.000000, bitrate: 4386 kb/s
Stream #0:0(und): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, smpte170m/bt709/bt709), 1280x720, 4329 kb/s, 30.01 fps, 30 tbr, 600 tbn, 600 tbc (default)
Metadata:
creation_time : 2019-06-30T01:28:04.000000Z
handler_name : Core Media Video
encoder : HEVC
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 94 kb/s (default)
Metadata:
creation_time : 2019-06-30T01:28:04.000000Z
handler_name : Core Media Audio
If I don't care about crossfade with video content, just some 'nice' black screen in between (It would be nice I add some text, like date + time on the black screen) is good enough for me. Is it possible to do 'concat' and simple crossfade without video 'content'?
Filtering requires re-encoding, so fading is not an option. Instead you can make videos that go between the main content.
Create middle videos. Ensure that you match the attributes of the main videos:
ffmpeg -y -f lavfi -i color=c=black:s=1280x720:r=30 -f lavfi -i anullsrc=channel_layout=mono:sample_rate=44100 -vf "drawtext=text='your text':fontsize=24:fontcolor=white:x=(w-text_w)/2:y=(h-text_h)/2" -c:v libx265 -profile:v main -c:a aac -tag:v hvc1 -t 5 -video_track_timescale 600 black1.mov
Make input.txt:
file '1.mov'
file 'black1.mov'
file '2.mov'
file 'black2.mov'
file '3.mov'
Then use concat demuxer:
ffmpeg -f concat -i input.txt -c copy output.mov
I am trying to convert a video to images.
ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg
But every time it shows error in Windows CMD :
Invalid frame size: WxH.
The full Error code is posted below
C:\Users\HP\Desktop\New folder>ffmpeg -i "C:\Users\HP\Desktop\foo.mp4" -r 1 -s WxH -f image2 afoo-%03d.jpeg
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\HP\Desktop\foo.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.40.101
Duration: 00:00:45.05, start: 0.000000, bitrate: 1163 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 854x480 [SAR 1:1 DAR 427:240], 1032 kb/s, 25.02 fps, 25 tbr, 90k tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
Metadata:
handler_name : SoundHandler
Invalid frame size: WxH.
I tried with multiple video formats and video sizes but still not working :(
I've checked whether it is really 'x' and I typed it by hand.
This question implies about the 'x' problem and mine is different.
As Gyan mentioned, you need to specify the actual width (W) and (x) height (H).
You should also update your ancient FFMPEG version.
ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg
should be changed to (assuming you want 1280x720):
ffmpeg -i foo.avi -r 1 -s 1280x720 -f image2 foo-%03d.jpeg
You can also specify the size like this:
ffmpeg -i foo.avi -r 1 -filter:v "scale=1280:720" -f image2 foo-%03d.jpeg
If you want to Not force both a width And height and keep the aspect ratio you could use:
ffmpeg -i foo.avi -r 1 -filter:v "scale=1280:-2" -f image2 foo-%03d.jpeg
ffmpeg -i foo.avi -r 1 -filter:v "scale=-2:720" -f image2 foo-%03d.jpeg
The -2 will auto resize that dimension (W or H) to the correct size (Mod 2) to maintain the aspect ratio.
This page may be worth reading: FFMPEG Scaling
When I run this command from the shell it works perfectly.
ffmpeg -nostdin -i /data/binil/v2t_final/output/cnbctv18/2018_07_02_14_38_30/tmp/merged.avi -ss 00:00:00 -vcodec h264 -vf fps=25 -to 00:6:43 /data/binil/v2t_final/output/cnbctv18/2018_07_02_14_38_30/1/1.avi
But the same thing when I do in python it gives error:
import sys
import os
INPUT_DIR = sys.argv[1]
INPUT_VIDEO = sys.argv[2]
OUTPUT_PATH = sys.argv[3]
SOURCE = sys.argv[4]
DATE = sys.argv[5]
INPUT = INPUT_DIR+"sorted_result.txt"
COUNT=1
initial="00:00:00"
with open(INPUT,"r") as f:
for line in f.readlines():
OUT_DIR = OUTPUT_PATH+str(COUNT)
directory = os.path.abspath(OUT_DIR)
print('OUT DIR',OUT_DIR)
print('directory',directory)
try:
os.mkdir(directory)
except:
pass
cmd_1 = "ffmpeg -nostdin -i "+INPUT_VIDEO+" -ss " +initial+ " -vcodec h264 -vf fps=25 -to " +line+ " " +OUT_DIR+"/"+str(COUNT)+".avi"
os.system(cmd_1)
COUNT += 1
initial=line
I cant understand the problem:
The error is as follows:
ffmpeg version 4.0-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-libxml2 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
Trailing options were found on the commandline.
Input #0, avi, from '/data/binil/v2t_final/output/cnbctv18/2018_07_02_14_38_30/tmp/merged.avi':
Metadata:
encoder : Lavf58.12.100
Duration: 01:00:50.23, start: 0.000000, bitrate: 1334 kb/s
Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 512x288 [SAR 1:1 DAR 16:9], 1001 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp, 639 kb/s
At least one output file must be specified
sh: line 1: /data/binil/v2t_final/output/cnbctv18/2018_07_02_14_38_30/1/1.avi: Permission denied
Please help.
This is some dummy text I am writing because it looks like stack overflow does not accept less description and more code. Please don't mind these sentences. I cant believe that I am still writing this and it is still requesting me to add some more description. I am still doing it. Don't know till what extent do I have to write. I hope this much is enough.
Got the error.
The input file contains timestamps each one on a new line so it was taking the '\n' character along with the timestamp in the ffmpeg command. Hence it considered -vcodec as a new command and resulted in error.
When i run this command i get an error. If i run without the pipe, it works.
With Pipe
cat mymovie.m4v | ffmpeg -i pipe:0 -an -analyzeduration 1000000 -f image2 -vf
"select='eq(pict_type,PICT_TYPE_I)'" -vsync vfr 'public/files/thumb%04d.png'
Without Pipe (Works)
ffmpeg -i mymovie.m4v -an -analyzeduration 2147483647 -probesize 2147483647 -f image2 -vf
"select='eq(pict_type,PICT_TYPE_I)'" -vsync vfr 'public/files/thumb%04d.png'
Output
ffmpeg version 2.2 Copyright (c) 2000-2014 the FFmpeg developers
built on Apr 10 2014 17:50:46 with Apple LLVM version 5.1 (clang-503.0.38)
(based on LLVM 3.4svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.2
--enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree
--enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang
--host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame
--enable-libxvid --enable-libfreetype --enable-libtheora --enable-libvorbis
--enable-libvpx --enable-librtmp --enable-libopencore-amrnb --enable-libopencore-amrwb
--enable-libvo-aacenc --enable-libass --enable-ffplay --enable-libspeex
--enable-libschroedinger --enable-libfdk-aac --enable-libopus --enable-frei0r
--enable-libopenjpeg --extra-cflags='-
I/usr/local/Cellar/openjpeg/1.5.1_1/include/openjpeg-1.5 '
libavutil 52. 66.100 / 52. 66.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 2.100 / 4. 2.100
libavresample 1. 2. 0 / 1. 2. 0
libswscale 2. 5.102 / 2. 5.102
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
[mov,mp4,m4a,3gp,3g2,mj2 # 0x7fd87b80f000] stream 0, offset 0x2c: partial file
[mov,mp4,m4a,3gp,3g2,mj2 # 0x7fd87b80f000] Could not find codec parameters for stream 0
(Video: h264 (avc1 / 0x31637661), 1280x720, 3310 kb/s): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
pipe:0: could not find codec parameters
I have tried setting (link)
-analyzeduration100 -probesize 10000000
-analyzeduration 2147483647 -probesize 2147483647
Still didn't work.
MP4 container is not the best choice for piping. The muxer that made the MP4 file may place certain info at the end of the file. This info is required for proper demuxing, but is not immediately available if using a pipe. However, you have a few options:
Don't use a pipe
I don't know why you need to use a pipe in the first place. Just use the file as a normal input:
ffmpeg -i input.mp4 ...
Don't use MP4
If you must use a pipe then consider using some other container such as .mkv or .ts for your input.
Re-mux your MP4 then pipe
If you must use MP4 then one method is to re-arrange the moov atom so it is at the beginning of the file:
ffmpeg -i input.mp4 -c copy -movflags +faststart output.mp4