Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
You can use HandBrakeCLI to encode a video and it will automatically crop the black borders, works well unless something on screen gets in the way, see the attached image.
The CBS-Justice tag spoils this
So you can use ffmpeg to detect the black borders and to give you the crop parameters
I'll be making the start point of the cropdetect, and the input video file an argument to the script, but what I would like is a critique on the script, could it be improved or is there an entirely different way of cropping out black borders?
Instead of relying on a fragile detection algorithm, I'd simply take a screenshot of the video (assuming that the black borders remain unchanged throughout the video), calculate the pixel dimensions I need to crop, and crop it with ffmpeg.
You can use HandBrakeCLI to encode a video and it will automatically crop the black borders, works well unless something on screen gets in the way, see the attached image.
The CBS-Justice tag spoils this
So you can use ffmpeg to detect the black borders and to give you the crop parameters
I'll be making the start point of the cropdetect, and the input video file an argument to the script, but what I would like is a critique on the script, could it be improved or is there an entirely different way of cropping out black borders?
The latest version of devedeng will do this for you. It uses ffmpeg as a back end and handles it seamlessly.
I have a couple of questions.
What is the output of:
Code:
ffprobe CBS_Justice-10282020-0348.mts
If that transport stream is an mpeg2, and you are making a .mp4 out of it, ffmpeg will reencode it. Is that what you want? Every time you reencode you loose quality. You did not specify -c:a copy -c:v copy
This will reencode the video. Look at what ffmpeg's defaults are.
Code:
ffmpeg -i file.ts -vf crop=700:400:0:2 out.mp4
I would specify the parameters for the reencode. I would find the crop manually, Auto crop will remove part of the video probably, I've never found that to work as good.
Do you want to crop without reencoding or resizing?
Instead of relying on a fragile detection algorithm, I'd simply take a screenshot of the video (assuming that the black borders remain unchanged throughout the video), calculate the pixel dimensions I need to crop, and crop it with ffmpeg.
That's what I've done in the past, bit tedious if you have 20+ videos to crop tho', and I'm a believer of getting the 'puter to do the work.
Things that an go wrong:
1 You detect the wrong bit of video
2 The crop=nn:nn:nn:nn isn't the 14th column
3 There are multiple crop= sequences in the data output file
4 Many things I havn't thought of
BTW I do assume the black borders remain the same throughout the video
I have a couple of questions.
What is the output of:
Code:
ffprobe CBS_Justice-10282020-0348.mts
Code:
$ ffprobe CBS_Justice-10282020-0348.mts
ffprobe version 4.2.4-1ubuntu0.1 Copyright (c) 2007-2020 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
WARNING: library configuration mismatch
avcodec configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libaribb24 --enable-liblensfun --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
[mpeg2video @ 0x55bbb31e2940] Invalid frame dimensions 0x0.
Last message repeated 1 times
[mpegts @ 0x55bbb3177240] PES packet size mismatch
Input #0, mpegts, from 'CBS_Justice-10282020-0348.mts':
Duration: 00:54:00.75, start: 45829.134400, bitrate: 2536 kb/s
Program 25792
Program 25920
Program 26176
Program 26240
Program 26304
Program 26368
Program 26560
Program 26624
Program 26752
Program 27040
Program 27200
Program 27424
Program 27456
Program 27584
Program 27616
Program 27680
Program 27712
Program 27744
Stream #0:0[0xb7d]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 544x576 [SAR 32:17 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0xb7e](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 128 kb/s
Program 27776
Program 27872
Program 27904
Program 27968
Program 28000
Program 28096
Program 28160
Program 28224
Program 28256
Program 28288
If that transport stream is an mpeg2, and you are making a .mp4 out of it, ffmpeg will reencode it. Is that what you want? Every time you reencode you loose quality. You did not specify -c:a copy -c:v copy
This will reencode the video. Look at what ffmpeg's defaults are.
Code:
ffmpeg -i file.ts -vf crop=700:400:0:2 out.mp4
I would specify the parameters for the reencode. I would find the crop manually, Auto crop will remove part of the video probably, I've never found that to work as good.
Do you want to crop without reencoding or resizing?
You're dead right I should have used -acodec copy, I just rushed the last bit - my evening meal was waiting for me and the missus would have been upset if I was late - know what I mean?
I have a couple of questions.
What is the output of:
Code:
ffprobe CBS_Justice-10282020-0348.mts
If that transport stream is an mpeg2, and you are making a .mp4 out of it, ffmpeg will reencode it. Is that what you want? Every time you reencode you loose quality. You did not specify -c:a copy -c:v copy
Input file is mts and I want mp4 files out so yes I do re-encode these files, and yes I may lose (not loose) a bit of quality, but that's acceptable.
And you cannot use copy when re-encoding - here's the error message
Code:
Filtergraph 'crop=400:576:72:0' was defined for video output stream 0:0 but codec copy was selected.
Filtering and streamcopy cannot be used together.
Filtering requires the input video to be fully decoded into raw video, then the raw video is processed by the filter(s), then it is encoded.
It does take time but I run this through a driver script that will process about 20 or 30 videos - takes a little while which is why I do it this way.
Setting up the driver script only takes 5 mins or so then the 'puter does all the work - neat innit!
No you can't, but you can crop without reencoding. If you have a .mp4 file that is x264 for example. You can make that a transport stream, crop it, and put it back into a .mp4 container without doing any reencoding. You seem to already know that. Good deal.
1) Detect the crop values however you prefer to.
2) Dynamically construct AviSynth script that utilizes Crop() and splicing.
3) Encode the singular, output-ready script with FFmpeg.
No extraneous encodes and after-the-fact concatting.
1) Detect the crop values however you prefer to.
2) Dynamically construct AviSynth script that utilizes Crop() and splicing.
3) Encode the singular, output-ready script with FFmpeg.
No extraneous encodes and after-the-fact concatting.
Cheers, could you expand your comments please, not entirely sure what you mean
No you can't, but you can crop without reencoding. If you have a .mp4 file that is x264 for example. You can make that a transport stream, crop it, and put it back into a .mp4 container without doing any reencoding. You seem to already know that. Good deal.
The input is an mts file and I want to re-encode it to mp4 so I'm not copying.
I could just re-encoe the entie video, then rop and copy the resulting mp4 file, it may be quicker, but I don't think there will be much in it, worth trying tho,
You did not answer post #4. I think that you have not started at the start. The first thing to do it find out what audio/video is in that transport stream. Then you will know what your options are with ffmpeg, and how to reencode it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.